MCPcopy Index your code
hub / github.com/NdoleStudio/httpsms / Update

Method Update

api/pkg/handlers/user_handler.go:95–122  ·  view source on GitHub ↗

Update an entities.User @Summary Update a user @Description Updates the details of the currently authenticated user @Security ApiKeyAuth @Tags Users @Accept json @Produce json @Param payload body requests.UserUpdate true "Payload of user details to update"

(c fiber.Ctx)

Source from the content-addressed store, hash-verified

93// @Failure 500 {object} responses.InternalServerError
94// @Router /users/me [put]
95func (h *UserHandler) Update(c fiber.Ctx) error {
96 ctx, span := h.tracer.StartFromFiberCtx(c)
97 defer span.End()
98
99 ctxLogger := h.tracer.CtxLogger(h.logger, span)
100
101 var request requests.UserUpdate
102 if err := c.Bind().Body(&request); err != nil {
103 msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.OriginalURL(), request)
104 ctxLogger.Warn(stacktrace.Propagate(err, msg))
105 return h.responseBadRequest(c, err)
106 }
107
108 if errors := h.validator.ValidateUpdate(ctx, request.Sanitize()); len(errors) != 0 {
109 msg := fmt.Sprintf("validation errors [%s], while updating user [%+#v]", spew.Sdump(errors), request)
110 ctxLogger.Warn(stacktrace.NewError(msg))
111 return h.responseUnprocessableEntity(c, errors, "validation errors while updating user")
112 }
113
114 user, err := h.service.Update(ctx, c.OriginalURL(), h.userFromContext(c), request.ToUpdateParams())
115 if err != nil {
116 msg := fmt.Sprintf("cannot update user with params [%+#v]", request)
117 ctxLogger.Error(stacktrace.Propagate(err, msg))
118 return h.responseInternalServerError(c)
119 }
120
121 return h.responseOK(c, "user updated successfully", user)
122}
123
124// Delete an entities.User
125// @Summary Delete a user

Callers

nothing calls this directly

Calls 13

SanitizeMethod · 0.95
ToUpdateParamsMethod · 0.95
responseBadRequestMethod · 0.80
userFromContextMethod · 0.80
responseOKMethod · 0.80
StartFromFiberCtxMethod · 0.65
CtxLoggerMethod · 0.65
WarnMethod · 0.65
UpdateMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected