Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix database query #11

Merged
merged 2 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/data/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/data/pg/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/service/handlers/update_event_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func UpdateEventType(w http.ResponseWriter, r *http.Request) {
}

EventTypes(r).Push(typeModel)
ape.Render(w, newEventTypeResponse(*res))
ape.Render(w, newEventTypeResponse(res[0]))
violog marked this conversation as resolved.
Show resolved Hide resolved
}

func newEventTypeResponse(evType models.EventType) resources.EventTypeResponse {
Expand Down
Loading