package user import ( "nixcn-cms/internal/exception" "nixcn-cms/service" "nixcn-cms/utils" "github.com/gin-gonic/gin" "github.com/google/uuid" ) func (self *UserHandler) Update(c *gin.Context) { userIdOrig, ok := c.Get("user_id") if !ok { errorCode := new(exception.Builder). SetStatus(exception.StatusUser). SetService(exception.ServiceUser). SetEndpoint(exception.EndpointUserServiceUpdate). SetType(exception.TypeCommon). SetOriginal(exception.CommonErrorMissingUserId). Throw(c). String() utils.HttpResponse(c, 403, errorCode) return } userId, err := uuid.Parse(userIdOrig.(string)) if err != nil { errorCode := new(exception.Builder). SetStatus(exception.StatusServer). SetService(exception.ServiceUser). SetEndpoint(exception.EndpointUserServiceUpdate). SetType(exception.TypeCommon). SetOriginal(exception.CommonErrorUuidParseFailed). Throw(c). String() utils.HttpResponse(c, 500, errorCode) return } userInfoPayload := &service.UserInfoPayload{ Context: c, UserId: userId, } err = c.ShouldBindJSON(&userInfoPayload.Data) if err != nil { errorCode := new(exception.Builder). SetStatus(exception.StatusUser). SetService(exception.ServiceUser). SetEndpoint(exception.EndpointUserServiceUpdate). SetType(exception.TypeCommon). SetOriginal(exception.CommonErrorInvalidInput). SetError(err). Throw(c). String() utils.HttpResponse(c, 400, errorCode) return } result := self.svc.UpdateUserInfo(userInfoPayload) 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) }