diff --git a/internal/data/event_types.go b/internal/data/event_types.go index 777baa0..d48e40f 100644 --- a/internal/data/event_types.go +++ b/internal/data/event_types.go @@ -7,7 +7,7 @@ import ( type EventTypesQ interface { New() EventTypesQ Insert(...models.EventType) error - Update(fields map[string]any) (*models.EventType, error) + Update(fields map[string]any) ([]models.EventType, error) Transaction(func() error) error Select() ([]models.EventType, error) diff --git a/internal/data/pg/event_types.go b/internal/data/pg/event_types.go index 4dc434d..862f768 100644 --- a/internal/data/pg/event_types.go +++ b/internal/data/pg/event_types.go @@ -78,10 +78,10 @@ func (q *eventTypes) Insert(eventTypes ...models.EventType) error { return nil } -func (q *eventTypes) Update(fields map[string]any) (res *models.EventType, err error) { +func (q *eventTypes) Update(fields map[string]any) (res []models.EventType, err error) { stmt := q.updater.SetMap(fields).Suffix("RETURNING *") - if err = q.db.Get(&res, stmt); err != nil { + if err = q.db.Select(&res, stmt); err != nil { return nil, fmt.Errorf("update event type with map %+v: %w", fields, err) } diff --git a/internal/service/handlers/update_event_type.go b/internal/service/handlers/update_event_type.go index 2e15498..664bd2d 100644 --- a/internal/service/handlers/update_event_type.go +++ b/internal/service/handlers/update_event_type.go @@ -46,8 +46,14 @@ func UpdateEventType(w http.ResponseWriter, r *http.Request) { return } + if len(res) == 0 { + Log(r).Error("Count of updated event_types = 0") + ape.RenderErr(w, problems.InternalError()) + return + } + EventTypes(r).Push(typeModel) - ape.Render(w, newEventTypeResponse(*res)) + ape.Render(w, newEventTypeResponse(res[0])) } func newEventTypeResponse(evType models.EventType) resources.EventTypeResponse {