All checks were successful
Server Check Build (NixCN CMS) TeamCity build finished
Signed-off-by: Asai Neko <sugar@sne.moe>
75 lines
2.2 KiB
Go
75 lines
2.2 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"
|
|
)
|
|
|
|
// Delete removes an event by event_id.
|
|
//
|
|
// @Summary Delete an Event
|
|
// @Description Permanently deletes an event. Requires Lv40+.
|
|
// @Tags Event
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security Bearer
|
|
// @Param request body service_event.EventDeleteData true "Event to delete"
|
|
// @Success 200 {object} utils.RespStatus{data=nil} "Successfully deleted"
|
|
// @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input"
|
|
// @Failure 401 {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 /event/delete [delete]
|
|
func (self *EventHandler) Delete(c *gin.Context) {
|
|
ctx, span := tracer.StartSpan(
|
|
c.Request.Context(),
|
|
"api_event",
|
|
"delete",
|
|
)
|
|
defer span.End()
|
|
|
|
ctx = exception.ContextWithEndpoint(ctx, exception.EndpointEventDelete)
|
|
ctx = exception.ContextWithService(ctx, exception.ServiceEndpoint)
|
|
|
|
_, 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
|
|
}
|
|
|
|
var deleteData service_event.EventDeleteData
|
|
if err := c.ShouldBindJSON(&deleteData); 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
|
|
}
|
|
|
|
result := self.svc.Delete(&service_event.EventDeletePayload{
|
|
Context: ctx,
|
|
Data: &deleteData,
|
|
})
|
|
|
|
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())
|
|
}
|