Implement Company Search and Update API Documentation

- Introduced a new search functionality for companies, allowing advanced filtering capabilities including tags, business criteria, and location.
- Updated the API documentation to reflect changes in the search endpoint, enhancing clarity for API consumers.
- Refactored existing company-related API endpoints for consistency, including renaming and restructuring routes.
- Enhanced response structures to return company entities directly, simplifying the response handling in API endpoints.
- Removed unused query parameters and handlers, streamlining the company management functionality.
This commit is contained in:
n.nakhostin
2025-09-08 11:23:15 +03:30
parent 777bbfd714
commit ee830f8c1b
16 changed files with 589 additions and 5338 deletions
+1 -1
View File
@@ -41,7 +41,7 @@ type SearchCustomersForm struct {
// CustomerListResponse represents the response for listing customers
type CustomerListResponse struct {
Customers []*CustomerResponse `json:"customers"`
Meta *response.Meta `json:"meta"`
Meta *response.Meta `json:"-"`
}
type LoginForm struct {
+1 -1
View File
@@ -192,7 +192,7 @@ func (h *Handler) Search(c echo.Context) error {
return response.InternalServerError(c, "Failed to list customers")
}
return response.Success(c, result, "Customers retrieved successfully")
return response.SuccessWithMeta(c, result, result.Meta, "Customers retrieved successfully")
}
// UpdateCustomerStatus updates customer status (Web Panel)
+5 -5
View File
@@ -62,7 +62,7 @@ func (s *customerService) Register(ctx context.Context, form *CreateCustomerForm
var companyIDs []string
if len(form.CompanyIDs) > 0 {
for _, companyID := range form.CompanyIDs {
_, err := s.companyService.GetCompanyByID(ctx, companyID)
_, err := s.companyService.GetByID(ctx, companyID)
if err != nil {
s.logger.Error("Invalid company ID provided", map[string]interface{}{
"error": err.Error(),
@@ -210,7 +210,7 @@ func (s *customerService) Update(ctx context.Context, id string, form *UpdateCus
// Verify that all company IDs exist
var validCompanyIDs []string
for _, companyID := range form.CompanyIDs {
_, err := s.companyService.GetCompanyByID(ctx, companyID)
_, err := s.companyService.GetByID(ctx, companyID)
if err != nil {
s.logger.Error("Invalid company ID provided in update", map[string]interface{}{
"error": err.Error(),
@@ -317,7 +317,7 @@ func (s *customerService) AssignCompanies(ctx context.Context, customerID string
// Verify companies exist and update customer's company IDs
var validCompanyIDs []string
for _, companyID := range companyIDs {
_, err = s.companyService.GetCompanyByID(ctx, companyID)
_, err = s.companyService.GetByID(ctx, companyID)
if err != nil {
s.logger.Error("Company not found during assignment", map[string]interface{}{
"error": err.Error(),
@@ -695,7 +695,7 @@ func (s *customerService) loadCompaniesForCustomer(ctx context.Context, customer
}
// Load companies in batch using the new GetCompaniesByIDs method
companies, err := s.companyService.GetCompaniesByIDs(ctx, customer.CompanyIDs)
companies, err := s.companyService.GetByIDs(ctx, customer.CompanyIDs)
if err != nil {
s.logger.Error("Failed to load companies for customer", map[string]interface{}{
"error": err.Error(),
@@ -709,7 +709,7 @@ func (s *customerService) loadCompaniesForCustomer(ctx context.Context, customer
var companySummaries []*CompanySummary
for _, company := range companies {
companySummaries = append(companySummaries, &CompanySummary{
ID: company.ID.Hex(),
ID: company.ID,
Name: company.Name,
})
}