package event import ( "errors" "nixcn-cms/internal/exception" "nixcn-cms/service/service_event" "nixcn-cms/tracer" "nixcn-cms/utils" "github.com/gin-gonic/gin" ) // Update modifies editable fields of an event owned by the requesting user. // // @Summary Update an Event // @Description Allows the event owner (Manager) to update name, subtitle, description, start_time, end_time, thumbnail, and is_agenda_published. Lv40+ users (admins) bypass the owner restriction and may update any event. Changes to type or enable_kyc are rejected. is_agenda_published is write-once: it can only be set to true (requires at least one agenda submission) and cannot be reverted. // @Tags Event // @Accept json // @Produce json // @Security Bearer // @Param request body service_event.EventUpdateData true "Fields to update (all optional except event_id)" // @Success 200 {object} utils.RespStatus{data=nil} "Successfully updated" // @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input / Immutable Field / Agenda Pre-flight Failed" // @Failure 401 {object} utils.RespStatus{data=nil} "Unauthorized" // @Failure 403 {object} utils.RespStatus{data=nil} "Not Event Owner" // @Failure 404 {object} utils.RespStatus{data=nil} "Event Not Found" // @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error" // @Router /event/update [patch] func (self *EventHandler) Update(c *gin.Context) { ctx, span := tracer.StartSpan( c.Request.Context(), "api_event", "update", ) defer span.End() ctx = exception.ContextWithEndpoint(ctx, exception.EndpointEventUpdate) 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 } permissionLevelOrig, ok := c.Get("permission_level") if !ok { errorCode := exception.New( exception.WithStatus(exception.StatusUser), exception.WithType(exception.TypeCommon), exception.WithOriginal(exception.CommonErrorPermissionDenied), exception.WithError(errors.New("Missing PermissionLevel")), ).Throw(ctx).String() utils.HttpResponse(c, 403, errorCode) return } var updateData service_event.EventUpdateData if err := c.ShouldBindJSON(&updateData); 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 } updateData.UserId = userIdOrig.(string) updateData.PermissionLevel = permissionLevelOrig.(uint) result := self.svc.Update(&service_event.EventUpdatePayload{ Context: ctx, Data: &updateData, }) 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()) }