Skip to content

Commit

Permalink
Load Hot Topics from database (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
katyasoup authored Sep 16, 2024
1 parent d7c029f commit 44fda86
Show file tree
Hide file tree
Showing 9 changed files with 251 additions and 49 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.23.0

require (
github.com/a-h/templ v0.2.771
github.com/google/uuid v1.6.0
github.com/jackc/pgx/v5 v5.6.0
github.com/joho/godotenv v1.5.1
github.com/justinas/alice v1.2.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
Expand Down
40 changes: 40 additions & 0 deletions internal/app/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"log/slog"
"net/http"
"strconv"

"github.com/skylight-hq/phinvads-go/internal/database/models"
"github.com/skylight-hq/phinvads-go/internal/database/models/xo"
Expand Down Expand Up @@ -415,6 +416,45 @@ func (app *Application) getValueSetConceptsByCodeSystemOID(w http.ResponseWriter
json.NewEncoder(w).Encode(valueSetConcepts)
}

func (app *Application) getAllHotTopics(w http.ResponseWriter, r *http.Request) {
rp := app.repository

hotTopics, err := rp.GetAllHotTopics(r.Context())

if err != nil {
var (
method = r.Method
uri = r.URL.RequestURI()
)
if errors.Is(err, sql.ErrNoRows) {
errorString := "Error: No Hot Topics found"
dbErr := &customErrors.DatabaseError{
Err: err,
Msg: errorString,
Method: "home: Get Hot Topics",
}
dbErr.NoRows(w, r, err, app.logger)
} else {
customErrors.ServerError(w, r, err, app.logger)
}

app.logger.Error(err.Error(), slog.String("method", method), slog.String("uri", uri))
return
}

for _, t := range *hotTopics {
// skip sending system config to the frontend
if t.HotTopicName == "SYSTEM CONFIG" {
continue
}
// format the sequence id to align with the uswds js controls
divId := fmt.Sprintf("m-a%s", strconv.Itoa(t.Seq))

component := components.HotTopic(t.HotTopicName, t.HotTopicDescription, divId, t.HotTopicID.String())
component.Render(r.Context(), w)
}
}

func (app *Application) home(w http.ResponseWriter, r *http.Request) {
component := components.Home()
component.Render(r.Context(), w)
Expand Down
1 change: 1 addition & 0 deletions internal/app/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func (app *Application) routes() http.Handler {
mux.HandleFunc("GET /api/value-set-concepts/code-system/{codeSystemOid}", app.getValueSetConceptsByCodeSystemOID)

mux.HandleFunc("GET /toggle-banner/{action}", app.handleBannerToggle)
mux.HandleFunc("GET /load-hot-topics", app.getAllHotTopics)

standard := alice.New(app.recoverPanic, app.logRequest, commonHeaders)

Expand Down
27 changes: 27 additions & 0 deletions internal/database/models/hottopic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package models

import (
"context"

"github.com/skylight-hq/phinvads-go/internal/database/models/xo"
)

// All retrieves all rows from 'public.hot_topic'
func GetAllHotTopics(ctx context.Context, db xo.DB) (*[]xo.HotTopic, error) {
const sqlstr = `SELECT * FROM public.hot_topic`
hotTopics := []xo.HotTopic{}
rows, err := db.QueryContext(ctx, sqlstr)
if err != nil {
return nil, err
}

for rows.Next() {
ht := xo.HotTopic{}
err := rows.Scan(&ht.HotTopicID, &ht.HotTopicName, &ht.HotTopicDescription, &ht.Seq, &ht.EffectiveDate, &ht.ExpiryDate, &ht.DeploymentDate, &ht.CreatedDate, &ht.UpdatedDate)
if err != nil {
return nil, err
}
hotTopics = append(hotTopics, ht)
}
return &hotTopics, nil
}
9 changes: 9 additions & 0 deletions internal/database/models/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,12 @@ func (r *Repository) GetValueSetVersionByVscVsvId(ctx context.Context, vsc *xo.V
func (r *Repository) GetValueSetVersionByVvsvVsvId(ctx context.Context, vvsv *xo.ViewValueSetVersion) (*xo.ValueSetVersion, error) {
return vvsv.ValueSetVersion(ctx, r.database)
}

// =============================== //
// ==== Other resource methods === //
// =============================== //

func (r *Repository) GetAllHotTopics(ctx context.Context) (*[]xo.HotTopic, error) {
return models.GetAllHotTopics(ctx, r.database)

}
155 changes: 155 additions & 0 deletions internal/database/models/xo/hottopic.xo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 6 additions & 49 deletions internal/ui/components/home.templ
Original file line number Diff line number Diff line change
Expand Up @@ -41,55 +41,12 @@ templ Home() {
</div>
</div>
<h2>Hot Topics</h2>
<div class="usa-accordion usa-accordion--multiselectable" data-allow-multiple>
<button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="m-a1">PHIN VADS Feedback</button>
<div id="m-a1" class="usa-accordion__content usa-prose">
<p>Lorem ipsum...</p>
</div>
<button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="m-a2">New CDCREC Code System Status Upate</button>
<div id="m-a2" class="usa-accordion__content usa-prose">
<p>Lorem ipsum...</p>
</div>
<button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="m-a3">CDC Race Category and Ethnicity Group</button>
<div id="m-a3" class="usa-accordion__content usa-prose">
<p>Lorem ipsum...</p>
</div>
<button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="m-a4">COVID-19 Information Management Response (VADS)</button>
<div id="m-a4" class="usa-accordion__content usa-prose">
<p>Lorem ipsum...</p>
</div>
<button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="m-a5">1.1 General COVID-19 Information Management Response</button>
<div id="m-a5" class="usa-accordion__content usa-prose">
<p>Lorem ipsum...</p>
</div>
<button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="m-a6">1.2 Representing Health Care Data for Emergency Medical Services</button>
<div id="m-a6" class="usa-accordion__content usa-prose">
<p>Lorem ipsum...</p>
</div>
<button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="m-a7">1.3 Patient's Clinical Encounter</button>
<div id="m-a7" class="usa-accordion__content usa-prose">
<p>Lorem ipsum...</p>
</div>
<button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="m-a8">1.4 COVID-19 Public Health Reporting</button>
<div id="m-a8" class="usa-accordion__content usa-prose">
<p>Lorem ipsum...</p>
</div>
<button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="m-a9">1.5 Labratory Data Exchange and Labratory Surveillance</button>
<div id="m-a9" class="usa-accordion__content usa-prose">
<p>Lorem ipsum...</p>
</div>
<button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="m-a10">1.6 Geospatial Data Set and Tools</button>
<div id="m-a10" class="usa-accordion__content usa-prose">
<p>Lorem ipsum...</p>
</div>
<button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="m-a11">1.7 COVID-19 Immunization</button>
<div id="m-a11" class="usa-accordion__content usa-prose">
<p>Lorem ipsum...</p>
</div>
<button type="button" class="usa-accordion__button" aria-expanded="false" aria-controls="m-a12">1.8 Community Resilience and Social Determinants of Health (SDOH)</button>
<div id="m-a12" class="usa-accordion__content usa-prose">
<p>Lorem ipsum...</p>
</div>
<div
hx-trigger="load"
hx-get="/load-hot-topics"
class="usa-accordion usa-accordion--multiselectable"
data-allow-multiple
>
</div>
<div class="grid-row">
<br><section><br><br><br><br></section></br>
Expand Down
10 changes: 10 additions & 0 deletions internal/ui/components/hot-topic.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package components

templ HotTopic(topic_name string, topic_description, sequence, topic_id string ) {
<button id={topic_id} type="button" class="usa-accordion__button" aria-expanded="false" aria-controls={sequence}>
{topic_name}
</button>
<div id={sequence} class="usa-accordion__content usa-prose" hidden>
<p>{topic_description}</p>
</div>
}

0 comments on commit 44fda86

Please sign in to comment.