Files
cms-server/api/event/guide.go
Asai Neko 2c312a545a
All checks were successful
Server Check Build (NixCN CMS) TeamCity build finished
Adapt error code definitions for exception builder refactor
Signed-off-by: Asai Neko <sugar@sne.moe>
2026-03-22 00:13:34 +08:00

93 lines
2.8 KiB
Go

package event
import (
"errors"
"nixcn-cms/internal/exception"
"nixcn-cms/service/service_event"
"nixcn-cms/tracer"
"nixcn-cms/utils"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
// Specific guide about a specific event.
//
// @Summary Get Event Guide
// @Description Fetching attendance guide of an event using its UUID.
// @Tags Event
// @Accept json
// @Produce json
// @Security Bearer
// @Param event_id query string true "Event UUID"
// @Success 200 {object} utils.RespStatus{data=service_event.AttendanceGuideResponse} "Successful retrieval"
// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input"
// @Failure 401 {object} utils.RespStatus{data=nil} "Missing User ID / Unauthorized"
// @Failure 404 {object} utils.RespStatus{data=nil} "Event Not Found"
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error"
// @Router /event/guide [get]
func (self *EventHandler) Guide(c *gin.Context) {
ctx, span := tracer.StartSpan(
c.Request.Context(),
"api_event",
"guide",
)
defer span.End()
ctx = exception.ContextWithEndpoint(ctx, exception.EndpointEventAttendanceGuide)
ctx = exception.ContextWithService(ctx, exception.ServiceEndpoint)
userIdOrig, ok := c.Get("user_id")
if !ok {
errorCode := exception.New(
exception.WithStatus(exception.StatusUser),
exception.WithType(exception.TypeCommon),
exception.WithOriginal(exception.CommonErrorMissingUserId),
exception.WithError(errors.New("Missing UserId")),
).Throw(ctx).String()
utils.HttpResponse(c, 403, errorCode)
return
}
userId, err := uuid.Parse(userIdOrig.(string))
if err != nil {
errorCode := exception.New(
exception.WithStatus(exception.StatusServer),
exception.WithType(exception.TypeCommon),
exception.WithOriginal(exception.CommonErrorUuidParseFailed),
exception.WithError(err),
).Throw(ctx).String()
utils.HttpResponse(c, 500, errorCode)
return
}
eventIdOrig := c.Query("event_id")
eventId, err := uuid.Parse(eventIdOrig)
if err != nil {
errorCode := exception.New(
exception.WithStatus(exception.StatusServer),
exception.WithType(exception.TypeCommon),
exception.WithOriginal(exception.CommonErrorUuidParseFailed),
exception.WithError(err),
).Throw(ctx).String()
utils.HttpResponse(c, 500, errorCode)
return
}
result := self.svc.GetAttendanceGuide(&service_event.AttendanceGuidePayload{
Context: ctx,
UserId: userId,
Data: &service_event.AttendanceGuideData{
EventId: eventId,
},
})
if result.Common.Exception.Original != exception.CommonSuccess {
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String())
return
}
utils.HttpResponse(c, 200, result.Common.Exception.String(), result.Data)
}