Refactor company domain by removing customer-related fields and methods

- Removed OwnerCustomerID from Company entity and CompanyResponse to streamline ownership representation.
- Eliminated customer assignment fields from CreateCompanyForm and ListCompaniesForm for clarity.
- Updated repository and service methods to remove GetByCustomerID and CountWithCustomer, simplifying the codebase.
- Adjusted Search method parameters to exclude hasCustomer filter, enhancing search functionality.
- Improved API documentation by removing references to customer assignment in handler comments.
This commit is contained in:
n.nakhostin
2025-08-11 18:31:15 +03:30
parent 3e4831c2e7
commit f5407abbf0
5 changed files with 23 additions and 107 deletions
+5 -24
View File
@@ -325,7 +325,7 @@ func (s *companyService) ListCompanies(ctx context.Context, form *ListCompaniesF
}
// Get companies
companies, err := s.repository.Search(ctx, search, form.Type, form.Status, form.Industry, form.IsVerified, form.IsCompliant, form.Language, form.Currency, form.HasCustomer, form.CPVCodes, form.Categories, form.Keywords, form.Specializations, form.EmployeeCountMin, form.EmployeeCountMax, form.AnnualRevenueMin, form.AnnualRevenueMax, form.FoundedYearMin, form.FoundedYearMax, limit, offset, sortBy, sortOrder)
companies, err := s.repository.Search(ctx, search, form.Type, form.Status, form.Industry, form.IsVerified, form.IsCompliant, form.Language, form.Currency, form.CPVCodes, form.Categories, form.Keywords, form.Specializations, form.EmployeeCountMin, form.EmployeeCountMax, form.AnnualRevenueMin, form.AnnualRevenueMax, form.FoundedYearMin, form.FoundedYearMax, limit, offset, sortBy, sortOrder)
if err != nil {
s.logger.Error("Failed to list companies", map[string]interface{}{
"error": err.Error(),
@@ -371,7 +371,7 @@ func (s *companyService) SearchCompanies(ctx context.Context, form *CompanySearc
}
// Get companies using search
companies, err := s.repository.Search(ctx, query, nil, nil, form.Industry, form.IsVerified, form.IsCompliant, nil, nil, nil, form.CPVCodes, form.Categories, form.Keywords, form.Specializations, form.MinEmployees, form.MaxEmployees, form.MinRevenue, form.MaxRevenue, nil, nil, limit, offset, "created_at", "desc")
companies, err := s.repository.Search(ctx, query, nil, nil, form.Industry, form.IsVerified, form.IsCompliant, nil, nil, form.CPVCodes, form.Categories, form.Keywords, form.Specializations, form.MinEmployees, form.MaxEmployees, form.MinRevenue, form.MaxRevenue, nil, nil, limit, offset, "created_at", "desc")
if err != nil {
s.logger.Error("Failed to search companies", map[string]interface{}{
"error": err.Error(),
@@ -469,25 +469,6 @@ func (s *companyService) UpdateCompanyVerification(ctx context.Context, id strin
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)
if err != nil {
s.logger.Error("Failed to get company by customer ID", map[string]interface{}{
"error": err.Error(),
"customer_id": customerID,
})
return nil, err
}
s.logger.Info("Company retrieved by customer ID successfully", map[string]interface{}{
"company_id": company.ID,
"customer_id": customerID,
})
return company, nil
}
// UpdateCompanyTags updates company tags
func (s *companyService) UpdateCompanyTags(ctx context.Context, id string, form *UpdateCompanyTagsForm, updatedBy *string) error {
// Get company to check if exists
@@ -663,7 +644,7 @@ func (s *companyService) GetCompanyStats(ctx context.Context) (*CompanyStatsResp
func (s *companyService) GetCompaniesByType(ctx context.Context, companyType CompanyType, limit, offset int) ([]*Company, int64, error) {
// Use search method with type filter
typeStr := string(companyType)
companies, err := s.repository.Search(ctx, "", &typeStr, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, limit, offset, "created_at", "desc")
companies, err := s.repository.Search(ctx, "", &typeStr, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, limit, offset, "created_at", "desc")
if err != nil {
s.logger.Error("Failed to get companies by type", map[string]interface{}{
"error": err.Error(),
@@ -689,7 +670,7 @@ func (s *companyService) GetCompaniesByType(ctx context.Context, companyType Com
func (s *companyService) GetCompaniesByStatus(ctx context.Context, status CompanyStatus, limit, offset int) ([]*Company, int64, error) {
// Use search method with status filter
statusStr := string(status)
companies, err := s.repository.Search(ctx, "", nil, &statusStr, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, limit, offset, "created_at", "desc")
companies, err := s.repository.Search(ctx, "", nil, &statusStr, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, limit, offset, "created_at", "desc")
if err != nil {
s.logger.Error("Failed to get companies by status", map[string]interface{}{
"error": err.Error(),
@@ -714,7 +695,7 @@ func (s *companyService) GetCompaniesByStatus(ctx context.Context, status Compan
// GetCompaniesByIndustry retrieves companies by industry with pagination
func (s *companyService) GetCompaniesByIndustry(ctx context.Context, industry string, limit, offset int) ([]*Company, int64, error) {
// Use search method with industry filter
companies, err := s.repository.Search(ctx, "", nil, nil, &industry, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, limit, offset, "created_at", "desc")
companies, err := s.repository.Search(ctx, "", nil, nil, &industry, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, limit, offset, "created_at", "desc")
if err != nil {
s.logger.Error("Failed to get companies by industry", map[string]interface{}{
"error": err.Error(),