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:
@@ -25,11 +25,6 @@ type Service interface {
|
||||
UpdateCompanyStatus(ctx context.Context, id string, form *UpdateCompanyStatusForm, updatedBy *string) error
|
||||
UpdateCompanyVerification(ctx context.Context, id string, form *UpdateCompanyVerificationForm, updatedBy *string) error
|
||||
|
||||
// Customer assignment
|
||||
AssignCustomer(ctx context.Context, id string, form *AssignCustomerForm, assignedBy *string) error
|
||||
UnassignCustomer(ctx context.Context, id string, unassignedBy *string) error
|
||||
GetCompanyByCustomerID(ctx context.Context, customerID string) (*Company, error)
|
||||
|
||||
// Tag management
|
||||
UpdateCompanyTags(ctx context.Context, id string, form *UpdateCompanyTagsForm, updatedBy *string) error
|
||||
AddTags(ctx context.Context, id string, form *AddTagsForm, updatedBy *string) error
|
||||
@@ -101,7 +96,6 @@ func (s *companyService) CreateCompany(ctx context.Context, form *CreateCompanyF
|
||||
Phone: form.Phone,
|
||||
Email: form.Email,
|
||||
Tags: s.convertCompanyTagsForm(form.Tags),
|
||||
CustomerID: form.CustomerID,
|
||||
IsVerified: false,
|
||||
IsCompliant: false,
|
||||
Language: s.getDefaultLanguage(form.Language),
|
||||
@@ -238,10 +232,6 @@ func (s *companyService) UpdateCompany(ctx context.Context, id string, form *Upd
|
||||
company.Tags = s.convertCompanyTagsForm(form.Tags)
|
||||
}
|
||||
|
||||
if form.CustomerID != nil {
|
||||
company.CustomerID = form.CustomerID
|
||||
}
|
||||
|
||||
if form.Language != nil {
|
||||
company.Language = *form.Language
|
||||
}
|
||||
@@ -479,66 +469,6 @@ func (s *companyService) UpdateCompanyVerification(ctx context.Context, id strin
|
||||
return nil
|
||||
}
|
||||
|
||||
// AssignCustomer assigns a customer to a company
|
||||
func (s *companyService) AssignCustomer(ctx context.Context, id string, form *AssignCustomerForm, assignedBy *string) error {
|
||||
// Get company to check if exists
|
||||
_, err := s.repository.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
return errors.New("company not found")
|
||||
}
|
||||
|
||||
// Check if customer is already assigned to another company
|
||||
existingCompany, _ := s.repository.GetByCustomerID(ctx, form.CustomerID)
|
||||
if existingCompany != nil {
|
||||
return errors.New("customer is already assigned to another company")
|
||||
}
|
||||
|
||||
// Assign customer
|
||||
err = s.repository.AssignCustomer(ctx, id, form.CustomerID)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to assign customer to company", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
"company_id": id,
|
||||
"customer_id": form.CustomerID,
|
||||
})
|
||||
return errors.New("failed to assign customer to company")
|
||||
}
|
||||
|
||||
s.logger.Info("Customer assigned to company successfully", map[string]interface{}{
|
||||
"company_id": id,
|
||||
"customer_id": form.CustomerID,
|
||||
"assigned_by": assignedBy,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnassignCustomer unassigns a customer from a company
|
||||
func (s *companyService) UnassignCustomer(ctx context.Context, id string, unassignedBy *string) error {
|
||||
// Get company to check if exists
|
||||
_, err := s.repository.GetByID(ctx, id)
|
||||
if err != nil {
|
||||
return errors.New("company not found")
|
||||
}
|
||||
|
||||
// Unassign customer
|
||||
err = s.repository.UnassignCustomer(ctx, id)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to unassign customer from company", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
"company_id": id,
|
||||
})
|
||||
return errors.New("failed to unassign customer from company")
|
||||
}
|
||||
|
||||
s.logger.Info("Customer unassigned from company successfully", map[string]interface{}{
|
||||
"company_id": id,
|
||||
"unassigned_by": unassignedBy,
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetCompanyByCustomerID retrieves a company by customer ID
|
||||
func (s *companyService) GetCompanyByCustomerID(ctx context.Context, customerID string) (*Company, error) {
|
||||
company, err := s.repository.GetByCustomerID(ctx, customerID)
|
||||
|
||||
Reference in New Issue
Block a user