114 lines
3.8 KiB
Go
114 lines
3.8 KiB
Go
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} service_event.CheckinResult
|
|
// @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} service_event.CheckinSubmitResult
|
|
// @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} service_event.CheckinQueryResult
|
|
// @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)
|
|
}
|