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:
@@ -46,6 +46,7 @@ type Service interface {
|
||||
|
||||
// Role assignment operations
|
||||
AssignRole(ctx context.Context, customerID string, form *AssignRoleForm) (*AssignRoleResponse, error)
|
||||
AssignCompanies(ctx context.Context, customerID string, Companies []string) error
|
||||
}
|
||||
|
||||
// customerService implements the Service interface
|
||||
@@ -360,6 +361,7 @@ func (s *customerService) AssignCompanies(ctx context.Context, customerID string
|
||||
}
|
||||
|
||||
// Update customer's company IDs
|
||||
customer.Companies = make([]string, 0)
|
||||
customer.Companies = append(customer.Companies, validCompanies...)
|
||||
customer.UpdatedAt = time.Now().Unix()
|
||||
|
||||
@@ -380,7 +382,7 @@ func (s *customerService) AssignCompanies(ctx context.Context, customerID string
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveCompaniesFromCustomer removes companies from a customer
|
||||
// RemoveCompanies removes companies from a customer
|
||||
func (s *customerService) RemoveCompanies(ctx context.Context, customerID string, Companies []string) error {
|
||||
// Get customer to check if exists
|
||||
customer, err := s.repository.GetByID(ctx, customerID)
|
||||
@@ -409,7 +411,7 @@ func (s *customerService) RemoveCompanies(ctx context.Context, customerID string
|
||||
|
||||
err = s.repository.Update(ctx, customer)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to update customer after removing company assignments", map[string]interface{}{
|
||||
s.logger.Error("Failed to update customer after removing companies", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
"customer_id": customerID,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user