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

Method Update

api/pkg/handlers/discord_handler.go:162–188  ·  view source on GitHub ↗

Update an entities.Discord @Summary Update a discord integration @Description Update a discord integration for the currently authenticated user @Security ApiKeyAuth @Tags DiscordIntegration @Accept json @Produce json @Param discordID path string true "ID of the

(c fiber.Ctx)

Source from the content-addressed store, hash-verified

160// @Failure 500 {object} responses.InternalServerError
161// @Router /discord-integrations/{discordID} [put]
162func (h *DiscordHandler) Update(c fiber.Ctx) error {
163 ctx, span, ctxLogger := h.tracer.StartFromFiberCtxWithLogger(c, h.logger)
164 defer span.End()
165
166 var request requests.DiscordUpdate
167 if err := c.Bind().Body(&request); err != nil {
168 msg := fmt.Sprintf("cannot marshall params [%s] into [%T]", c.Body(), request)
169 ctxLogger.Warn(stacktrace.Propagate(err, msg))
170 return h.responseBadRequest(c, err)
171 }
172
173 request.DiscordID = c.Params("discordID")
174 if errors := h.validator.ValidateUpdate(ctx, request.Sanitize()); len(errors) != 0 {
175 msg := fmt.Sprintf("validation errors [%s], while updating user [%+#v]", spew.Sdump(errors), request)
176 ctxLogger.Warn(stacktrace.NewError(msg))
177 return h.responseUnprocessableEntity(c, errors, "validation errors while updating discord integration")
178 }
179
180 user, err := h.service.Update(ctx, request.ToUpdateParams(h.userFromContext(c)))
181 if err != nil {
182 msg := fmt.Sprintf("cannot update discord integration with params [%+#v]", request)
183 ctxLogger.Error(stacktrace.Propagate(err, msg))
184 return h.responseInternalServerError(c)
185 }
186
187 return h.responseOK(c, "discord integration updated successfully", user)
188}
189
190// Store an entities.Discord
191// @Summary Store discord integration

Callers

nothing calls this directly

Calls 12

SanitizeMethod · 0.95
ToUpdateParamsMethod · 0.95
responseBadRequestMethod · 0.80
userFromContextMethod · 0.80
responseOKMethod · 0.80
WarnMethod · 0.65
UpdateMethod · 0.65
ErrorMethod · 0.65
ValidateUpdateMethod · 0.45

Tested by

no test coverage detected