Files
cms-server/api/agenda/my_list.go
Asai Neko c540235c6d
All checks were successful
Server Check Build (NixCN CMS) TeamCity build finished
Full restruct data layer without alibaba style SetXxx to Functional
Options

Signed-off-by: Asai Neko <sugar@sne.moe>
2026-03-26 16:32:51 +08:00

106 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"
)
// MyList retrieves the current user's own agenda submissions for an event.
//
// @Summary My Agenda List
// @Description Returns the calling user's agenda submissions for the specified event. User must be a joined attendee (Lv10+).
// @Tags Agenda
// @Accept json
// @Produce json
// @Security Bearer
// @Param event_id query string true "Event ID"
// @Success 200 {object} utils.RespStatus{data=[]data.Agenda}
// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input"
// @Failure 403 {object} utils.RespStatus{data=nil} "Not an Attendee"
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error"
// @Router /agenda/my-list [get]
func (self *AgendaHandler) MyList(c *gin.Context) {
ctx, span := tracer.StartSpan(
c.Request.Context(),
"api_agenda",
"my_list",
)
defer span.End()
ctx = exception.ContextWithEndpoint(ctx, exception.EndpointAgendaMyList)
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 MyListQuery struct {
EventId string `form:"event_id"`
}
var query MyListQuery
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.MyList(&service_agenda.AgendaMyListPayload{
Context: ctx,
UserId: userId,
Data: &service_agenda.AgendaMyListData{
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)
}