Files
Mazyar 89faa08b1c
continuous-integration/drone/push Build is passing
Add functionality to manage external links for companies
- Introduced the ability to append external links to company profiles through a new API endpoint.
- Enhanced the `Company` entity to include a `Links` field for storing external resource links.
- Created `AddLinksForm` for validating incoming link data and implemented corresponding logic in the service layer.
- Added error handling for link validation, ensuring only valid URLs are accepted and limiting the number of links to 20.
- Implemented unit tests for link management functions, including sanitization and merging of links.
- Updated relevant API documentation to reflect the new functionality.

This update significantly enhances the company management capabilities by allowing the addition of external links, improving the overall user experience and data richness in company profiles.
2026-07-06 00:05:48 +03:30

135 lines
4.6 KiB
Go

package company
import (
"tm/pkg/mongo"
"go.mongodb.org/mongo-driver/v2/bson"
)
// CompanyStatus represents company account status
type CompanyStatus string
const (
CompanyStatusActive CompanyStatus = "active"
CompanyStatusInactive CompanyStatus = "inactive"
CompanyStatusSuspended CompanyStatus = "suspended"
)
// CompanyType represents the type of company
type CompanyType string
const (
CompanyTypePrivate CompanyType = "private"
CompanyTypePublic CompanyType = "public"
CompanyTypeGovernment CompanyType = "government"
CompanyTypeNgo CompanyType = "ngo"
CompanyTypeStartup CompanyType = "startup"
)
// Company represents a company in the tender management system
type Company struct {
mongo.Model `bson:",inline"`
Name string `bson:"name" json:"name"`
Type CompanyType `bson:"type" json:"type"`
Status CompanyStatus `bson:"status" json:"status"`
RegistrationNumber string `bson:"registration_number" json:"registration_number"`
TaxID string `bson:"tax_id" json:"tax_id"`
Industry string `bson:"industry" json:"industry"`
Description *string `bson:"description,omitempty" json:"description,omitempty"`
Website *string `bson:"website,omitempty" json:"website,omitempty"`
// Business information
EmployeeCount *int `bson:"employee_count,omitempty" json:"employee_count,omitempty"`
AnnualRevenue *float64 `bson:"annual_revenue,omitempty" json:"annual_revenue,omitempty"`
FoundedYear *int `bson:"founded_year,omitempty" json:"founded_year,omitempty"`
// Address information
Address *Address `bson:"address,omitempty" json:"address,omitempty"`
// Contact information
Phone *string `bson:"phone,omitempty" json:"phone,omitempty"`
Email *string `bson:"email,omitempty" json:"email,omitempty"`
// File references stored in GridFS
DocumentFileIDs []string `bson:"document_file_ids" json:"document_file_ids,omitempty"`
// External resource links (e.g. company profile pages, portfolios)
Links []CompanyLink `bson:"links,omitempty" json:"links,omitempty"`
// Tags for categorization and search
Tags *CompanyTags `bson:"tags,omitempty" json:"tags,omitempty"`
// Verification and compliance
IsVerified bool `bson:"is_verified" json:"is_verified"`
IsCompliant bool `bson:"is_compliant" json:"is_compliant"`
ComplianceNotes *string `bson:"compliance_notes,omitempty" json:"compliance_notes,omitempty"`
// Settings
Language string `bson:"language" json:"language"` // Default: "en"
Currency string `bson:"currency" json:"currency"` // Default: "USD"
Timezone string `bson:"timezone" json:"timezone"` // Default: "UTC"
}
// SetID sets the company ID (implements IDSetter interface)
func (c *Company) SetID(id string) {
c.ID, _ = bson.ObjectIDFromHex(id)
}
// GetID returns the company ID (implements IDGetter interface)
func (c *Company) GetID() string {
return c.ID.Hex()
}
// SetCreatedAt sets the created timestamp (implements Timestamp interface)
func (c *Company) SetCreatedAt(timestamp int64) {
c.CreatedAt = timestamp
}
// SetUpdatedAt sets the updated timestamp (implements Timestamp interface)
func (c *Company) SetUpdatedAt(timestamp int64) {
c.UpdatedAt = timestamp
}
// GetCreatedAt returns the created timestamp (implements Timestamp interface)
func (c *Company) GetCreatedAt() int64 {
return c.CreatedAt
}
// GetUpdatedAt returns the updated timestamp (implements Timestamp interface)
func (c *Company) GetUpdatedAt() int64 {
return c.UpdatedAt
}
// CompanyLink represents an external URL associated with a company.
type CompanyLink struct {
URL string `bson:"url" json:"url"`
Title *string `bson:"title,omitempty" json:"title,omitempty"`
}
// Address represents a company's address
type Address struct {
Street string `bson:"street" json:"street"`
City string `bson:"city" json:"city"`
State string `bson:"state" json:"state"`
PostalCode string `bson:"postal_code" json:"postal_code"`
Country string `bson:"country" json:"country"`
}
// CompanyTags represents tags for company categorization and search
type CompanyTags struct {
// CPV codes (Common Procurement Vocabulary)
CPVCodes []string `bson:"cpv_codes,omitempty" json:"cpv_codes,omitempty"`
// Categories
Categories []string `bson:"categories,omitempty" json:"categories,omitempty"`
// Keywords for search and matching
Keywords []string `bson:"keywords,omitempty" json:"keywords,omitempty"`
// Specializations
Specializations []string `bson:"specializations,omitempty" json:"specializations,omitempty"`
// Certifications
Certifications []string `bson:"certifications,omitempty" json:"certifications,omitempty"`
}