All checks were successful
Server Check Build (NixCN CMS) TeamCity build finished
Signed-off-by: Asai Neko <sugar@sne.moe>
99 lines
3.0 KiB
Go
99 lines
3.0 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"
|
|
)
|
|
|
|
// Schedule handles setting start/end times for an approved agenda item.
|
|
//
|
|
// @Summary Schedule Agenda
|
|
// @Description Manager sets start_time and end_time on an approved agenda item. Available even after publish.
|
|
// @Tags Agenda
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security Bearer
|
|
// @Param body body service_agenda.AgendaScheduleData true "Schedule Data"
|
|
// @Success 200 {object} utils.RespStatus{data=nil}
|
|
// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input / Not Approved"
|
|
// @Failure 404 {object} utils.RespStatus{data=nil} "Agenda Not Found"
|
|
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error"
|
|
// @Router /agenda/schedule [patch]
|
|
func (self *AgendaHandler) Schedule(c *gin.Context) {
|
|
ctx, span := tracer.StartSpan(
|
|
c.Request.Context(),
|
|
"api_agenda",
|
|
"schedule",
|
|
)
|
|
defer span.End()
|
|
|
|
ctx = exception.ContextWithEndpoint(ctx, exception.EndpointAgendaSchedule)
|
|
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
|
|
}
|
|
|
|
data := new(service_agenda.AgendaScheduleData)
|
|
if err := c.ShouldBindJSON(data); 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
|
|
}
|
|
|
|
if data.AgendaId == uuid.Nil {
|
|
errorCode := exception.New(
|
|
exception.WithStatus(exception.StatusUser),
|
|
exception.WithType(exception.TypeCommon),
|
|
exception.WithOriginal(exception.CommonErrorInvalidInput),
|
|
exception.WithError(errors.New("agenda_id is required")),
|
|
).Throw(ctx).String()
|
|
utils.HttpResponse(c, 400, errorCode)
|
|
return
|
|
}
|
|
|
|
result := self.svc.Schedule(&service_agenda.AgendaSchedulePayload{
|
|
Context: ctx,
|
|
UserId: userId,
|
|
Data: data,
|
|
})
|
|
|
|
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())
|
|
}
|