All checks were successful
Server Check Build (NixCN CMS) TeamCity build finished
Options Signed-off-by: Asai Neko <sugar@sne.moe>
81 lines
2.5 KiB
Go
81 lines
2.5 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"
|
|
)
|
|
|
|
// ScheduleGet returns the published, scheduled agenda for an event.
|
|
//
|
|
// @Summary Get Agenda Schedule
|
|
// @Description Returns all approved and scheduled agenda items, sorted by start_time ascending. Returns 403 if the agenda has not been published.
|
|
// @Tags Agenda
|
|
// @Produce json
|
|
// @Security Bearer
|
|
// @Param event_id query string true "Event ID"
|
|
// @Success 200 {object} utils.RespStatus{data=[]data.AgendaDoc}
|
|
// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input"
|
|
// @Failure 403 {object} utils.RespStatus{data=nil} "Agenda Not Published"
|
|
// @Failure 404 {object} utils.RespStatus{data=nil} "Event Not Found"
|
|
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error"
|
|
// @Router /agenda/schedule [get]
|
|
func (self *AgendaHandler) ScheduleGet(c *gin.Context) {
|
|
ctx, span := tracer.StartSpan(
|
|
c.Request.Context(),
|
|
"api_agenda",
|
|
"schedule_get",
|
|
)
|
|
defer span.End()
|
|
|
|
ctx = exception.ContextWithEndpoint(ctx, exception.EndpointAgendaScheduleGet)
|
|
ctx = exception.ContextWithService(ctx, exception.ServiceEndpoint)
|
|
|
|
type ScheduleQuery struct {
|
|
EventId string `form:"event_id"`
|
|
}
|
|
|
|
var query ScheduleQuery
|
|
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.ScheduleGet(&service_agenda.AgendaScheduleGetPayload{
|
|
Context: ctx,
|
|
Data: &service_agenda.AgendaScheduleGetData{
|
|
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)
|
|
}
|