package event import ( "nixcn-cms/internal/exception" "nixcn-cms/service/service_event" "nixcn-cms/utils" "github.com/gin-gonic/gin" "github.com/google/uuid" ) // Checkin generates a check-in code for a specific event. // // @Summary Generate Check-in Code // @Description Creates a temporary check-in code for the authenticated user and event. // @Tags Event // @Accept json // @Produce json // @Param event_id query string true "Event UUID" // @Success 200 {object} utils.RespStatus{data=service_event.CheckinResponse} "Successfully generated code" // @Failure 401 {object} utils.RespStatus{data=nil} "Missing User ID / Unauthorized" // @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input" // @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error" // @Security ApiKeyAuth // @Router /event/checkin [get] func (self *EventHandler) Checkin(c *gin.Context) { userIdOrig, _ := c.Get("user_id") userId, _ := uuid.Parse(userIdOrig.(string)) eventIdOrig := c.Query("event_id") eventId, err := uuid.Parse(eventIdOrig) if err != nil { errorCode := new(exception.Builder). SetStatus(exception.StatusUser). SetService(exception.ServiceEvent). SetEndpoint(exception.EndpointEventServiceCheckin). SetType(exception.TypeCommon). SetOriginal(exception.CommonErrorInvalidInput). SetError(err). Throw(c).String() utils.HttpResponse(c, 400, errorCode) return } result := self.svc.Checkin(&service_event.CheckinPayload{ Context: c, UserId: userId, Data: &service_event.CheckinData{EventId: eventId}, }) utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String(), result.Data) } // CheckinSubmit validates a check-in code to complete attendance. // // @Summary Submit Check-in Code // @Description Submits the generated code to mark the user as attended. // @Tags Event // @Accept json // @Produce json // @Param payload body service_event.CheckinSubmitData true "Checkin Code Data" // @Success 200 {object} utils.RespStatus{data=nil} "Attendance marked successfully" // @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Code or Input" // @Security ApiKeyAuth // @Router /event/checkin/submit [post] func (self *EventHandler) CheckinSubmit(c *gin.Context) { var data service_event.CheckinSubmitData if err := c.ShouldBindJSON(&data); err != nil { errorCode := new(exception.Builder). SetStatus(exception.StatusUser). SetService(exception.ServiceEvent). SetEndpoint(exception.EndpointEventServiceCheckinSubmit). SetType(exception.TypeCommon). SetOriginal(exception.CommonErrorInvalidInput). SetError(err). Throw(c).String() utils.HttpResponse(c, 400, errorCode) return } result := self.svc.CheckinSubmit(&service_event.CheckinSubmitPayload{ Context: c, Data: &data, }) utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String()) } // CheckinQuery retrieves the check-in status of a user for an event. // // @Summary Query Check-in Status // @Description Returns the timestamp of when the user checked in, or null if not yet checked in. // @Tags Event // @Accept json // @Produce json // @Param event_id query string true "Event UUID" // @Success 200 {object} utils.RespStatus{data=service_event.CheckinQueryResponse} "Current attendance status" // @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input" // @Failure 404 {object} utils.RespStatus{data=nil} "Record Not Found" // @Security ApiKeyAuth // @Router /event/checkin/query [get] func (self *EventHandler) CheckinQuery(c *gin.Context) { userIdOrig, _ := c.Get("user_id") userId, _ := uuid.Parse(userIdOrig.(string)) eventIdOrig := c.Query("event_id") eventId, err := uuid.Parse(eventIdOrig) if err != nil { errorCode := new(exception.Builder). SetStatus(exception.StatusUser). SetService(exception.ServiceEvent). SetEndpoint(exception.EndpointEventServiceCheckinQuery). SetType(exception.TypeCommon). SetOriginal(exception.CommonErrorInvalidInput). SetError(err). Throw(c).String() utils.HttpResponse(c, 400, errorCode) return } result := self.svc.CheckinQuery(&service_event.CheckinQueryPayload{ Context: c, UserId: userId, Data: &service_event.CheckinQueryData{EventId: eventId}, }) utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String(), result.Data) }