Skip to content

Commit

Permalink
Remove QR-code from event response. Fix adding events for user after …
Browse files Browse the repository at this point in the history
…create new event type.
  • Loading branch information
Zaptoss committed Jul 8, 2024
1 parent ddf5f60 commit 838fe48
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 0 additions & 1 deletion internal/data/evtypes/models/event_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func (e EventType) Resource() resources.EventStaticMeta {
ActionUrl: e.ActionURL,
Logo: e.Logo,
Flag: e.Flag(),
QrCodeValue: e.QRCodeValue,
}
}

Expand Down
27 changes: 27 additions & 0 deletions internal/service/handlers/create_event_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"net/http"

"github.com/rarimo/geo-auth-svc/pkg/auth"
"github.com/rarimo/geo-points-svc/internal/data"
"github.com/rarimo/geo-points-svc/internal/data/evtypes"
"github.com/rarimo/geo-points-svc/internal/data/evtypes/models"
"github.com/rarimo/geo-points-svc/internal/service/requests"
"gitlab.com/distributed_lab/ape"
Expand Down Expand Up @@ -44,5 +46,30 @@ func CreateEventType(w http.ResponseWriter, r *http.Request) {
}
EventTypes(r).Push(typeModel)

if evtypes.FilterNotOpenable(typeModel) {
w.WriteHeader(http.StatusNoContent)
return
}

balances, err := BalancesQ(r).FilterDisabled().Select()
if err != nil {
Log(r).WithError(err).Error("Failed to select balances")
ape.RenderErr(w, problems.InternalError())
return
}

eventsToInsert := make([]data.Event, 0, len(balances))
for _, b := range balances {
eventsToInsert = append(eventsToInsert, data.Event{
Nullifier: b.Nullifier,
Status: data.EventOpen,
Type: typeModel.Name,
})
}
if err = EventsQ(r).Insert(eventsToInsert...); err != nil {
Log(r).WithError(err).Error("Failed to insert qr-code events")
ape.RenderErr(w, problems.InternalError())
return
}
w.WriteHeader(http.StatusNoContent)
}

0 comments on commit 838fe48

Please sign in to comment.