Remove obsolete customer endpoint and update related documentation
- Deleted the `/admin/v1/customers/{id}/with-companies` endpoint from the API documentation and Swagger files to streamline the API structure.
- Updated the router to remove the corresponding route registration for the deprecated endpoint.
- Enhanced the company repository and service to support batch retrieval of companies by IDs, improving efficiency in data handling.
- Adjusted customer service methods to utilize the new batch retrieval functionality for loading companies associated with customers.
- Improved logging practices to provide better traceability for company retrieval operations.
This commit is contained in:
@@ -1280,24 +1280,35 @@ func (s *customerService) getDefaultTimezone(timezone *string) string {
|
||||
|
||||
// loadCompaniesForCustomer loads company summaries for a customer
|
||||
func (s *customerService) loadCompaniesForCustomer(ctx context.Context, customer *Customer) ([]*CompanySummary, error) {
|
||||
var companies []*CompanySummary
|
||||
if len(customer.CompanyIDs) == 0 {
|
||||
return []*CompanySummary{}, nil
|
||||
}
|
||||
|
||||
// Load companies from CompanyIDs
|
||||
for _, companyID := range customer.CompanyIDs {
|
||||
company, err := s.companyService.GetCompanyByID(ctx, companyID)
|
||||
if err != nil {
|
||||
s.logger.Warn("Failed to load company for customer", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
"customer_id": customer.ID,
|
||||
"company_id": companyID,
|
||||
})
|
||||
continue // Skip companies that can't be loaded
|
||||
}
|
||||
companies = append(companies, &CompanySummary{
|
||||
// Load companies in batch using the new GetCompaniesByIDs method
|
||||
companies, err := s.companyService.GetCompaniesByIDs(ctx, customer.CompanyIDs)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to load companies for customer", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
"customer_id": customer.ID,
|
||||
"company_ids": customer.CompanyIDs,
|
||||
})
|
||||
return []*CompanySummary{}, err
|
||||
}
|
||||
|
||||
// Convert to CompanySummary format
|
||||
var companySummaries []*CompanySummary
|
||||
for _, company := range companies {
|
||||
companySummaries = append(companySummaries, &CompanySummary{
|
||||
ID: company.ID.Hex(),
|
||||
Name: company.Name,
|
||||
})
|
||||
}
|
||||
|
||||
return companies, nil
|
||||
s.logger.Info("Companies loaded for customer", map[string]interface{}{
|
||||
"customer_id": customer.ID,
|
||||
"requested_count": len(customer.CompanyIDs),
|
||||
"loaded_count": len(companySummaries),
|
||||
})
|
||||
|
||||
return companySummaries, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user