From 87cbd6d35e3f5adfcd39dad33e2102e18339b17b Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 29 Dec 2024 15:33:53 -0500 Subject: [PATCH] Don't use DB type --- pkg/incidents/incstore/store.go | 12 +++++++++--- pkg/rest/incidents.go | 5 ++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/incidents/incstore/store.go b/pkg/incidents/incstore/store.go index 6772e12..8264815 100644 --- a/pkg/incidents/incstore/store.go +++ b/pkg/incidents/incstore/store.go @@ -34,7 +34,7 @@ type Store interface { UpdateNotes(ctx context.Context, incidentID uuid.UUID, callID uuid.UUID, notes []byte) error // Incidents gets incidents matching parameters and pagination. - Incidents(ctx context.Context, p IncidentsParams) (incs []database.Incident, totalCount int, err error) + Incidents(ctx context.Context, p IncidentsParams) (incs []incidents.Incident, totalCount int, err error) // Incident gets a single incident. Incident(ctx context.Context, id uuid.UUID) (*incidents.Incident, error) @@ -113,7 +113,7 @@ func (s *store) AddRemoveIncidentCalls(ctx context.Context, incidentID uuid.UUID }, pgx.TxOptions{}) } -func (s *store) Incidents(ctx context.Context, p IncidentsParams) (rows []database.Incident, totalCount int, err error) { +func (s *store) Incidents(ctx context.Context, p IncidentsParams) (incs []incidents.Incident, totalCount int, err error) { db := database.FromCtx(ctx) offset, perPage := p.Pagination.OffsetPerPage(100) @@ -126,6 +126,7 @@ func (s *store) Incidents(ctx context.Context, p IncidentsParams) (rows []databa } var count int64 + var rows []database.Incident txErr := db.InTx(ctx, func(db database.Store) error { var err error count, err = db.ListIncidentsCount(ctx, dbParam.Start, dbParam.End) @@ -144,7 +145,12 @@ func (s *store) Incidents(ctx context.Context, p IncidentsParams) (rows []databa return nil, 0, txErr } - return rows, int(count), err + incs = make([]incidents.Incident, 0, len(rows)) + for _, v := range rows { + incs = append(incs, fromDBIncident(v.ID, v)) + } + + return incs, int(count), err } func fromDBIncident(id uuid.UUID, d database.Incident) incidents.Incident { diff --git a/pkg/rest/incidents.go b/pkg/rest/incidents.go index 9e72a73..f07f655 100644 --- a/pkg/rest/incidents.go +++ b/pkg/rest/incidents.go @@ -10,7 +10,6 @@ import ( "dynatron.me/x/stillbox/internal/common" "dynatron.me/x/stillbox/internal/forms" "dynatron.me/x/stillbox/internal/jsontypes" - "dynatron.me/x/stillbox/pkg/database" "dynatron.me/x/stillbox/pkg/incidents" "dynatron.me/x/stillbox/pkg/incidents/incstore" "dynatron.me/x/stillbox/pkg/talkgroups/tgstore" @@ -56,8 +55,8 @@ func (ia *incidentsAPI) listIncidents(w http.ResponseWriter, r *http.Request) { } res := struct { - Incidents []database.Incident `json:"incidents"` - Count int `json:"count"` + Incidents []incidents.Incident `json:"incidents"` + Count int `json:"count"` }{} res.Incidents, res.Count, err = incs.Incidents(ctx, p)