Add Assign Companies Feature for Customers
- Introduced a new endpoint to assign companies to a customer, enhancing the customer management capabilities.
- Implemented the AssignCompanies handler in the customer service layer, including validation and structured responses.
- Updated the routes to include the new PATCH /admin/v1/customers/{id}/companies endpoint, improving administrative functionalities.
- Enhanced API documentation with Swagger comments for the new endpoint, ensuring clarity for API consumers.
This commit is contained in:
@@ -265,6 +265,37 @@ func (h *Handler) AssignRole(c echo.Context) error {
|
||||
return response.Success(c, result, "Role assigned successfully")
|
||||
}
|
||||
|
||||
// AssignCompanies assigns companies to a customer
|
||||
// @Summary Assign companies to a customer
|
||||
// @Description Assign companies to a customer
|
||||
// @Tags Admin-Customers
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param id path string true "Customer ID"
|
||||
// @Param companies body AssignCompaniesForm true "Companies to assign"
|
||||
// @Success 200 {object} response.APIResponse "Companies assigned successfully"
|
||||
// @Failure 400 {object} response.APIResponse "Bad request - Invalid input data"
|
||||
// @Failure 422 {object} response.APIResponse "Validation error - Invalid request data"
|
||||
// @Failure 500 {object} response.APIResponse "Internal server error"
|
||||
// @Security BearerAuth
|
||||
// @Router /admin/v1/customers/{id}/companies [patch]
|
||||
func (h *Handler) AssignCompanies(c echo.Context) error {
|
||||
id := c.Param("id")
|
||||
form, err := response.Parse[AssignCompaniesForm](c)
|
||||
if err != nil {
|
||||
return response.ValidationError(c, "Invalid request data", err.Error())
|
||||
}
|
||||
|
||||
err = h.service.AssignCompanies(c.Request().Context(), id, form.Companies)
|
||||
if err != nil {
|
||||
return response.InternalServerError(c, "Failed to assign companies to customer")
|
||||
}
|
||||
|
||||
return response.Success(c, map[string]interface{}{
|
||||
"message": "Companies assigned successfully",
|
||||
}, "Companies assigned successfully")
|
||||
}
|
||||
|
||||
// **************************************************
|
||||
// * PROFILE HANDLERS *
|
||||
// **************************************************
|
||||
|
||||
Reference in New Issue
Block a user