Files
tm_back/internal/company/entity.go
T
Mazyar 992d41374f
continuous-integration/drone/push Build is passing
Update company entity and repository for document file ID handling
- Modified the `DocumentFileIDs` field in the `Company` struct to ensure it is always persisted in BSON format, enhancing data consistency.
- Implemented logic in the `Update` method of the `companyRepository` to clear document file IDs when the slice is empty, ensuring accurate database updates.
- Added logging for errors encountered while clearing document file IDs, improving error tracking and debugging capabilities.

This update enhances the management of document file IDs within the company domain, ensuring proper handling and persistence in the database.
2026-06-22 23:38:57 +03:30

126 lines
4.3 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"`
// 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
}
// 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"`
}