improved toggle publish company category feedback
This commit is contained in:
@@ -184,11 +184,10 @@ func (h *Handler) Search(c echo.Context) error {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Category ID"
|
||||
// @Success 200 {object} response.APIResponse "Category publish status updated successfully"
|
||||
// @Failure 400 {object} response.APIResponse "Bad request - Invalid input data"
|
||||
// @Failure 404 {object} response.APIResponse "Not found - Category not found"
|
||||
// @Failure 422 {object} response.APIResponse "Validation error - Invalid request data"
|
||||
// @Failure 500 {object} response.APIResponse "Internal server error"
|
||||
// @Success 200 {object} response.APIResponse{data=map[string]bool} "Company category published/unpublished successfully"
|
||||
// @Failure 400 {object} response.APIResponse "Bad request - Invalid category ID"
|
||||
// @Failure 404 {object} response.APIResponse "Not found - Company category not found"
|
||||
// @Failure 500 {object} response.APIResponse "Internal server error - Failed to update published status"
|
||||
// @Security BearerAuth
|
||||
// @Router /admin/v1/company-categories/{id}/publish [patch]
|
||||
func (h *Handler) TogglePublish(c echo.Context) error {
|
||||
@@ -197,17 +196,25 @@ func (h *Handler) TogglePublish(c echo.Context) error {
|
||||
published, err := h.service.TogglePublish(c.Request().Context(), id)
|
||||
if err != nil {
|
||||
if err.Error() == "category not found" {
|
||||
return response.NotFound(c, "Category not found")
|
||||
return response.NotFound(c, "Company category not found")
|
||||
}
|
||||
return response.InternalServerError(c, "Failed to toggle category publish status")
|
||||
h.logger.Error("Failed to update Company category published status", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
"category_id": id,
|
||||
})
|
||||
return response.InternalServerError(c, "Failed to update Company category published status. Please try again or contact support if the problem persists.")
|
||||
}
|
||||
|
||||
message := "Company category unpublished successfully"
|
||||
if published {
|
||||
message = "Company category published successfully"
|
||||
}
|
||||
|
||||
return response.Success(
|
||||
c,
|
||||
map[string]interface{}{
|
||||
"message": "Category publish status updated successfully",
|
||||
"published": published,
|
||||
},
|
||||
"Category publish status updated successfully",
|
||||
message,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user