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)
| 193 | // @Failure 500 {object} responses.InternalServerError |
| 194 | // @Router /phones/fcm-token [put] |
| 195 | func (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 | } |
nothing calls this directly
no test coverage detected