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

Method UpsertFCMToken

api/pkg/handlers/phone_handler.go:195–222  ·  view source on GitHub ↗

UpsertFCMToken upserts the FCM token of a phone @Summary Upserts the FCM token of a phone @Description Updates the FCM token of a phone. If the phone with this number does not exist, a new one will be created. Think of this method like an 'upsert' @Security ApiKeyAuth @Tags Phones @Ac

(c fiber.Ctx)

Source from the content-addressed store, hash-verified

193// @Failure 500 {object} responses.InternalServerError
194// @Router /phones/fcm-token [put]
195func (h *PhoneHandler) UpsertFCMToken(c fiber.Ctx) error {
196 ctx, span := h.tracer.StartFromFiberCtx(c)
197 defer span.End()
198
199 ctxLogger := h.tracer.CtxLogger(h.logger, span)
200
201 var request requests.PhoneFCMToken
202 if err := c.Bind().Body(&request); err != nil {
203 msg := fmt.Sprintf("cannot marshall params [%s] into %T", c.OriginalURL(), request)
204 ctxLogger.Warn(stacktrace.Propagate(err, msg))
205 return h.responseBadRequest(c, err)
206 }
207
208 if errors := h.validator.ValidateFCMToken(ctx, request.Sanitize()); len(errors) != 0 {
209 msg := fmt.Sprintf("validation errors [%s], while updating phones [%+#v]", spew.Sdump(errors), request)
210 ctxLogger.Warn(stacktrace.NewError(msg))
211 return h.responseUnprocessableEntity(c, errors, "validation errors while updating phones")
212 }
213
214 phone, err := h.service.UpsertFCMToken(ctx, request.ToPhoneFCMTokenParams(h.userFromContext(c), c.OriginalURL()))
215 if err != nil {
216 msg := fmt.Sprintf("cannot delete phones with params [%+#v]", request)
217 ctxLogger.Error(stacktrace.Propagate(err, msg))
218 return h.responseInternalServerError(c)
219 }
220
221 return h.responseOK(c, "FCM token updated successfully", phone)
222}

Callers

nothing calls this directly

Calls 12

SanitizeMethod · 0.95
ToPhoneFCMTokenParamsMethod · 0.95
responseBadRequestMethod · 0.80
ValidateFCMTokenMethod · 0.80
userFromContextMethod · 0.80
responseOKMethod · 0.80
StartFromFiberCtxMethod · 0.65
CtxLoggerMethod · 0.65
WarnMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected