company feedback performance update

This commit is contained in:
Mazyar
2026-05-25 11:27:55 +03:30
parent 3c86d35663
commit 51defd9438
4 changed files with 163 additions and 5 deletions
+25
View File
@@ -16,6 +16,7 @@ type Service interface {
Update(ctx context.Context, id string, form *CompanyForm) (*CompanyResponse, error)
GetByID(ctx context.Context, id string) (*CompanyResponse, error)
GetByIDs(ctx context.Context, ids []string) ([]*CompanyResponse, error)
GetNamesByIDs(ctx context.Context, ids []string) (map[string]*CompanyResponse, error)
Delete(ctx context.Context, id string) error
// Company listing and search
@@ -389,6 +390,30 @@ func (s *companyService) GetByIDs(ctx context.Context, ids []string) ([]*Company
return companyResponses, nil
}
// GetNamesByIDs returns company id and name keyed by company ID without loading categories.
func (s *companyService) GetNamesByIDs(ctx context.Context, ids []string) (map[string]*CompanyResponse, error) {
if len(ids) == 0 {
return map[string]*CompanyResponse{}, nil
}
companies, err := s.repository.GetByIDs(ctx, ids)
if err != nil {
s.logger.Error("Failed to get companies by IDs for names", map[string]interface{}{
"count": len(ids),
"error": err.Error(),
})
return nil, errors.New("failed to get companies by IDs")
}
out := make(map[string]*CompanyResponse, len(companies))
for _, c := range companies {
id := c.ID.Hex()
out[id] = &CompanyResponse{ID: id, Name: c.Name}
}
return out, nil
}
// UpdateCompanyStatus updates company status
func (s *companyService) UpdateStatus(ctx context.Context, id string, form *StatusForm) error {
// Get company to check if exists