Delete a phone @Summary Delete Phone @Description Delete a phone that has been sored in the database @Security ApiKeyAuth @Tags Phones @Accept json @Produce json @Param phoneID path string true "ID of the phone" default(32343a19-da5e-4b1b-a767-3298a73703ca) @Su
(c fiber.Ctx)
| 153 | // @Failure 500 {object} responses.InternalServerError |
| 154 | // @Router /phones/{phoneID} [delete] |
| 155 | func (h *PhoneHandler) Delete(c fiber.Ctx) error { |
| 156 | ctx, span := h.tracer.StartFromFiberCtx(c) |
| 157 | defer span.End() |
| 158 | |
| 159 | ctxLogger := h.tracer.CtxLogger(h.logger, span) |
| 160 | |
| 161 | request := requests.PhoneDelete{PhoneID: c.Params("phoneID")} |
| 162 | if errors := h.validator.ValidateDelete(ctx, request); len(errors) != 0 { |
| 163 | msg := fmt.Sprintf("validation errors [%s], while deleting phone [%+#v]", spew.Sdump(errors), request) |
| 164 | ctxLogger.Warn(stacktrace.NewError(msg)) |
| 165 | return h.responseUnprocessableEntity(c, errors, "validation errors while deleting phone") |
| 166 | } |
| 167 | |
| 168 | err := h.service.Delete(ctx, c.OriginalURL(), h.userIDFomContext(c), request.PhoneIDUuid()) |
| 169 | if stacktrace.GetCode(err) == repositories.ErrCodeNotFound { |
| 170 | return h.responseNotFound(c, fmt.Sprintf("cannot find phone with ID [%s]", request.PhoneID)) |
| 171 | } |
| 172 | if err != nil { |
| 173 | msg := fmt.Sprintf("cannot delete phones with params [%+#v]", request) |
| 174 | ctxLogger.Error(stacktrace.Propagate(err, msg)) |
| 175 | return h.responseInternalServerError(c) |
| 176 | } |
| 177 | |
| 178 | return h.responseOK(c, "phone deleted successfully", nil) |
| 179 | } |
| 180 | |
| 181 | // UpsertFCMToken upserts the FCM token of a phone |
| 182 | // @Summary Upserts the FCM token of a phone |
nothing calls this directly
no test coverage detected