Files
cms-server/api/agenda/list.go
Asai Neko 75be02aed7
All checks were successful
Server Check Build (NixCN CMS) TeamCity build finished
Fix agenda list swagger doc error
Signed-off-by: Asai Neko <sugar@sne.moe>
2026-03-27 20:46:33 +08:00

107 lines
3.1 KiB
Go

package agenda
import (
"errors"
"nixcn-cms/internal/exception"
"nixcn-cms/service/service_agenda"
"nixcn-cms/tracer"
"nixcn-cms/utils"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
)
// List retrieves all agenda items for an event. Manager only.
//
// @Summary List All Agendas
// @Description Returns all agendas for the specified event, regardless of status. Manager only.
// @Tags Agenda
// @Accept json
// @Produce json
// @Security Bearer
// @Param event_id query string true "Event ID"
// @Success 200 {object} utils.RespStatus{data=[]service_agenda.AgendaListItem}
// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input"
// @Failure 403 {object} utils.RespStatus{data=nil} "Unauthorized"
// @Failure 404 {object} utils.RespStatus{data=nil} "Event Not Found"
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error"
// @Router /agenda/list [get]
func (self *AgendaHandler) List(c *gin.Context) {
ctx, span := tracer.StartSpan(
c.Request.Context(),
"api_agenda",
"list",
)
defer span.End()
ctx = exception.ContextWithEndpoint(ctx, exception.EndpointAgendaList)
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
}
type ListQuery struct {
EventId string `form:"event_id"`
}
var query ListQuery
if err := c.ShouldBindQuery(&query); err != nil {
errorCode := exception.New(
exception.WithStatus(exception.StatusUser),
exception.WithType(exception.TypeCommon),
exception.WithOriginal(exception.CommonErrorInvalidInput),
exception.WithError(err),
).Throw(ctx).String()
utils.HttpResponse(c, 400, errorCode)
return
}
eventId, err := uuid.Parse(query.EventId)
if err != nil {
errorCode := exception.New(
exception.WithStatus(exception.StatusUser),
exception.WithType(exception.TypeCommon),
exception.WithOriginal(exception.CommonErrorInvalidInput),
exception.WithError(errors.New("invalid event_id")),
).Throw(ctx).String()
utils.HttpResponse(c, 400, errorCode)
return
}
result := self.svc.List(&service_agenda.AgendaListPayload{
Context: ctx,
UserId: userId,
Data: &service_agenda.AgendaListData{
EventId: eventId,
},
})
if result.Common.Exception.Original != exception.CommonSuccess {
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String())
return
}
utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String(), result.Data)
}