Enhance Company Management with Category Integration and API Documentation Updates

- Updated the Company service to include category validation during creation and updates, ensuring that only valid categories are associated with companies.
- Introduced a new CategoryResponse structure to encapsulate category details in API responses, improving the clarity of the data returned.
- Enhanced the CompanyResponse structure to include category details, providing more comprehensive information in API responses.
- Updated Swagger and YAML documentation to reflect the new category integration, including detailed descriptions and examples for the updated response structures.
- Improved error handling for invalid category data during company creation and updates, enhancing the robustness of the API.
- Refactored existing API handlers to accommodate the new category-related changes, ensuring a seamless user experience across the application.
This commit is contained in:
n.nakhostin
2025-09-08 13:01:45 +03:30
parent 991771ee19
commit 8670b3272d
8 changed files with 297 additions and 151 deletions
+54 -28
View File
@@ -98,36 +98,52 @@ type CompanyListResponse struct {
Meta *response.Meta `json:"-"`
}
// CompanyResponse represents the company data sent in API responses
type CompanyResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Status string `json:"status"`
RegistrationNumber string `json:"registration_number"`
TaxID string `json:"tax_id"`
Industry string `json:"industry"`
Description *string `json:"description,omitempty"`
Website *string `json:"website,omitempty"`
EmployeeCount *int `json:"employee_count,omitempty"`
AnnualRevenue *float64 `json:"annual_revenue,omitempty"`
FoundedYear *int `json:"founded_year,omitempty"`
Address *Address `json:"address,omitempty"`
Phone *string `json:"phone,omitempty"`
Email *string `json:"email,omitempty"`
Tags *CompanyTags `json:"tags,omitempty"`
IsVerified bool `json:"is_verified"`
IsCompliant bool `json:"is_compliant"`
ComplianceNotes *string `json:"compliance_notes,omitempty"`
Language string `json:"language"`
Currency string `json:"currency"`
Timezone string `json:"timezone"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
// CategoryResponse represents category data for company responses
type CategoryResponse struct {
ID string `json:"id"`
Name string `json:"name"`
}
// CompanyResponse represents the company data sent in API responses
type (
CompanyResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Status string `json:"status"`
RegistrationNumber string `json:"registration_number"`
TaxID string `json:"tax_id"`
Industry string `json:"industry"`
Description *string `json:"description,omitempty"`
Website *string `json:"website,omitempty"`
EmployeeCount *int `json:"employee_count,omitempty"`
AnnualRevenue *float64 `json:"annual_revenue,omitempty"`
FoundedYear *int `json:"founded_year,omitempty"`
Address *Address `json:"address,omitempty"`
Phone *string `json:"phone,omitempty"`
Email *string `json:"email,omitempty"`
Tags *CompanyTagsResponse `json:"tags,omitempty"`
IsVerified bool `json:"is_verified"`
IsCompliant bool `json:"is_compliant"`
ComplianceNotes *string `json:"compliance_notes,omitempty"`
Language string `json:"language"`
Currency string `json:"currency"`
Timezone string `json:"timezone"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
CompanyTagsResponse struct {
CPVCodes []string `json:"cpv_codes"`
Categories []*CategoryResponse `json:"categories"`
Keywords []string `json:"keywords"`
Specializations []string `json:"specializations"`
Certifications []string `json:"certifications"`
}
)
// ToResponse converts Company to CompanyResponse
func (c *Company) ToResponse() *CompanyResponse {
func (c *Company) ToResponse(categories []*CategoryResponse) *CompanyResponse {
return &CompanyResponse{
ID: c.ID.Hex(),
Name: c.Name,
@@ -144,7 +160,7 @@ func (c *Company) ToResponse() *CompanyResponse {
Address: c.Address,
Phone: c.Phone,
Email: c.Email,
Tags: c.Tags,
Tags: c.Tags.ToResponse(categories),
IsVerified: c.IsVerified,
IsCompliant: c.IsCompliant,
ComplianceNotes: c.ComplianceNotes,
@@ -156,6 +172,16 @@ func (c *Company) ToResponse() *CompanyResponse {
}
}
func (c *CompanyTags) ToResponse(categories []*CategoryResponse) *CompanyTagsResponse {
return &CompanyTagsResponse{
CPVCodes: c.CPVCodes,
Categories: categories,
Keywords: c.Keywords,
Specializations: c.Specializations,
Certifications: c.Certifications,
}
}
// CompanyProfileResponse represents the company profile data sent in API responses
type CompanyProfileResponse struct {
ID string `json:"id"`