Update API documentation to reflect customer authorization changes

- Changed tags from "Customers-Mobile" to "Customers-Authorization" in Swagger documentation for customer logout and profile retrieval endpoints.
- Updated the Company entity to replace CustomerID with OwnerCustomerID to better represent ownership.
- Removed obsolete customer assignment methods and related forms from the company domain, streamlining the codebase.
- Adjusted customer forms to include CompanyID instead of CompanyName for better consistency in customer management.
- Enhanced Swagger documentation to accurately reflect the new structure and authorization details for customer-related endpoints.
This commit is contained in:
n.nakhostin
2025-08-11 16:24:28 +03:30
parent 1e998b365e
commit 566fa07574
12 changed files with 41 additions and 270 deletions
-82
View File
@@ -38,8 +38,6 @@ func (h *Handler) RegisterRoutes(e *echo.Echo) {
adminV1.GET("/search", h.SearchCompanies)
adminV1.PATCH("/:id/status", h.UpdateCompanyStatus)
adminV1.PATCH("/:id/verification", h.UpdateCompanyVerification)
adminV1.POST("/:id/assign-customer", h.AssignCustomer)
adminV1.POST("/:id/unassign-customer", h.UnassignCustomer)
adminV1.PUT("/:id/tags", h.UpdateCompanyTags)
adminV1.POST("/:id/tags/add", h.AddTags)
adminV1.POST("/:id/tags/remove", h.RemoveTags)
@@ -370,86 +368,6 @@ func (h *Handler) UpdateCompanyVerification(c echo.Context) error {
}, "Company verification updated successfully")
}
// AssignCustomer assigns a customer to a company (Web Panel)
// @Summary Assign customer to company
// @Description Assign a customer to a company for login credentials
// @Tags Companies-Admin
// @Accept json
// @Produce json
// @Param id path string true "Company ID"
// @Param assignment body AssignCustomerForm true "Customer assignment information"
// @Success 200 {object} response.APIResponse "Customer assigned successfully"
// @Failure 400 {object} response.APIResponse "Bad request - Invalid input data"
// @Failure 404 {object} response.APIResponse "Not found - Company not found"
// @Failure 409 {object} response.APIResponse "Conflict - Customer already assigned"
// @Failure 422 {object} response.APIResponse "Validation error - Invalid request data"
// @Failure 500 {object} response.APIResponse "Internal server error"
// @Security BearerAuth
// @Router /admin/v1/companies/{id}/assign-customer [post]
func (h *Handler) AssignCustomer(c echo.Context) error {
id := c.Param("id")
form, err := response.Parse[AssignCustomerForm](c)
if err != nil {
return response.ValidationError(c, "Invalid request data", err.Error())
}
// Get user ID from JWT token context
assignedBy, err := user.GetUserIDFromContext(c)
if err != nil {
return response.Unauthorized(c, "User not authenticated")
}
err = h.service.AssignCustomer(c.Request().Context(), id, form, &assignedBy)
if err != nil {
if err.Error() == "company not found" {
return response.NotFound(c, "Company not found")
}
if err.Error() == "customer is already assigned to another company" {
return response.Conflict(c, err.Error())
}
return response.InternalServerError(c, "Failed to assign customer")
}
return response.Success(c, map[string]interface{}{
"message": "Customer assigned successfully",
}, "Customer assigned successfully")
}
// UnassignCustomer unassigns a customer from a company (Web Panel)
// @Summary Unassign customer from company
// @Description Remove customer assignment from a company
// @Tags Companies-Admin
// @Accept json
// @Produce json
// @Param id path string true "Company ID"
// @Success 200 {object} response.APIResponse "Customer unassigned successfully"
// @Failure 400 {object} response.APIResponse "Bad request - Invalid company ID"
// @Failure 404 {object} response.APIResponse "Not found - Company not found"
// @Failure 500 {object} response.APIResponse "Internal server error"
// @Security BearerAuth
// @Router /admin/v1/companies/{id}/unassign-customer [post]
func (h *Handler) UnassignCustomer(c echo.Context) error {
id := c.Param("id")
// Get user ID from JWT token context
unassignedBy, err := user.GetUserIDFromContext(c)
if err != nil {
return response.Unauthorized(c, "User not authenticated")
}
err = h.service.UnassignCustomer(c.Request().Context(), id, &unassignedBy)
if err != nil {
if err.Error() == "company not found" {
return response.NotFound(c, "Company not found")
}
return response.InternalServerError(c, "Failed to unassign customer")
}
return response.Success(c, map[string]interface{}{
"message": "Customer unassigned successfully",
}, "Customer unassigned successfully")
}
// UpdateCompanyTags updates company tags (Web Panel)
// @Summary Update company tags
// @Description Update company tags (CPV, categories, keywords, specializations, certifications)