Skip to content

Commit f00052e

Browse files
update rfid (#300)
1 parent d67f556 commit f00052e

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

apps/api/internal/api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func (api *API) setupRoutes(mw *mw.Middleware) {
8787

8888
r.Get("/events/{eventId}/redeemables", api.Handlers.Redeemables.GetRedeemables)
8989
r.Post("/redeemables/{redeemableId}/users/{userId}", api.Handlers.Redeemables.RedeemRedeemable)
90+
r.Post("/events/{eventId}/users/{userId}/update-rfid", api.Handlers.Event.UpdateUserRFID)
9091
})
9192

9293
// Health check

apps/api/internal/api/handlers/events.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,3 +903,57 @@ func (h *EventHandler) GetCheckedInStatusByIds(w http.ResponseWriter, r *http.Re
903903
"checked_in_status": strconv.FormatBool(result),
904904
})
905905
}
906+
907+
type UpdateRFID struct {
908+
RFID string `json:"rfid"`
909+
}
910+
911+
// UpdateUserRFID
912+
//
913+
// @Summary Updates a user's RFID tag
914+
// @Description Associates a new RFID string with a specific user for the given event. This overwrites any existing RFID association.
915+
// @Tags Event
916+
// @Accept json
917+
// @Produce json
918+
// @Param eventId path string true "Event ID" Format(uuid)
919+
// @Param userId path string true "User ID" Format(uuid)
920+
// @Param body body UpdateRFID true "New RFID data"
921+
// @Success 204 "No Content - RFID updated successfully"
922+
// @Failure 400 {object} response.ErrorResponse "Invalid request body or UUID format"
923+
// @Failure 404 {object} response.ErrorResponse "User or Event not found"
924+
// @Failure 500 {object} response.ErrorResponse "Internal server error"
925+
// @Router /events/{eventId}/users/{userId}/update-rfid [post]
926+
func (h *EventHandler) UpdateUserRFID(w http.ResponseWriter, r *http.Request) {
927+
eventId, err := web.PathParamToUUID(r, "eventId")
928+
if err != nil {
929+
res.SendError(w, http.StatusBadRequest, res.NewError("missing_event_id", "The event ID is missing from the URL!"))
930+
return
931+
}
932+
933+
userId, err := web.PathParamToUUID(r, "userId")
934+
if err != nil {
935+
res.SendError(w, http.StatusBadRequest, res.NewError("missing_user_id", "The user ID is missing from the URL!"))
936+
return
937+
}
938+
939+
var payload UpdateRFID
940+
err = json.NewDecoder(r.Body).Decode(&payload)
941+
if err != nil {
942+
res.SendError(w, http.StatusBadRequest, res.NewError("body_malformed", "Invalid body"))
943+
return
944+
}
945+
defer r.Body.Close()
946+
947+
if payload.RFID == "" {
948+
res.SendError(w, http.StatusBadRequest, res.NewError("body_malformed", "Invalid body"))
949+
return
950+
}
951+
952+
err = h.eventService.UpdateEventRoleByIds(r.Context(), userId, eventId, nil, nil, &payload.RFID)
953+
if err != nil {
954+
res.SendError(w, http.StatusNotFound, res.NewError("error", "Something went wrong internally."))
955+
return
956+
}
957+
958+
w.WriteHeader(http.StatusNoContent)
959+
}

0 commit comments

Comments
 (0)