Files
tm_back/internal/customer/entity.go
T
n.nakhostin e848b625ce Refactor Customer API Endpoints and Update Documentation
- Changed customer-related API endpoints to improve clarity and consistency, including renaming and restructuring routes.
- Removed unused query parameters and handlers, streamlining the customer management functionality.
- Updated customer entity and forms to reflect new example values for enhanced API documentation clarity.
- Enhanced response structures to return customer entities directly, simplifying the response handling in API endpoints.
- Updated API documentation to reflect changes in endpoint structure and response formats, ensuring consistency for API consumers.
2025-09-06 16:08:53 +03:30

115 lines
3.5 KiB
Go

package customer
import (
"tm/pkg/mongo"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// CustomerStatus represents customer account status
type CustomerStatus string
const (
CustomerStatusActive CustomerStatus = "active"
CustomerStatusInactive CustomerStatus = "inactive"
CustomerStatusSuspended CustomerStatus = "suspended"
)
// CustomerType represents the type of customer
type CustomerType string
const (
CustomerTypeIndividual CustomerType = "individual"
CustomerTypeCompany CustomerType = "company"
CustomerTypeGovernment CustomerType = "government"
)
// Customer represents a customer in the tender management system
// A customer can have an associated company for login purposes
type Customer struct {
mongo.Model `bson:",inline"`
FullName *string `bson:"full_name"`
Username string `bson:"username"`
Email string `bson:"email"`
Password string `bson:"password"`
Status CustomerStatus `bson:"status"`
Type CustomerType `bson:"type"`
Phone *string `bson:"phone"`
CompanyIDs []string `bson:"company_ids"`
LastLoginAt *int64 `bson:"last_login_at"`
UpdatedAt int64 `bson:"updated_at"`
CreatedAt int64 `bson:"created_at"`
}
// SetID sets the customer ID (implements IDSetter interface)
func (c *Customer) SetID(id string) {
c.ID, _ = primitive.ObjectIDFromHex(id)
}
// GetID returns the customer ID (implements IDGetter interface)
func (c *Customer) GetID() string {
return c.ID.Hex()
}
// SetCreatedAt sets the created timestamp (implements Timestamp interface)
func (c *Customer) SetCreatedAt(timestamp int64) {
c.CreatedAt = timestamp
}
// SetUpdatedAt sets the updated timestamp (implements Timestamp interface)
func (c *Customer) SetUpdatedAt(timestamp int64) {
c.UpdatedAt = timestamp
}
// GetCreatedAt returns the created timestamp (implements Timestamp interface)
func (c *Customer) GetCreatedAt() int64 {
return c.CreatedAt
}
// GetUpdatedAt returns the updated timestamp (implements Timestamp interface)
func (c *Customer) GetUpdatedAt() int64 {
return c.UpdatedAt
}
// CompanySummary represents company summary data for customer responses
type CompanySummary struct {
ID string `json:"id"`
Name string `json:"name"`
}
// CustomerResponse represents the customer data sent in API responses
type CustomerResponse struct {
ID string `bson:"id"`
FullName *string `bson:"full_name"`
Username string `bson:"username"`
Email string `bson:"email"`
Password string `bson:"password"`
Status string `bson:"status"`
Type string `bson:"type"`
Phone *string `bson:"phone"`
CompanyIDs []string `bson:"company_ids"`
UpdatedAt int64 `bson:"updated_at"`
CreatedAt int64 `bson:"created_at"`
LastLoginAt *int64 `bson:"last_login_at"`
Companies []*CompanySummary `json:"companies"`
}
// ToResponse converts Customer to CustomerResponse
func (c *Customer) ToResponse(companies []*CompanySummary) *CustomerResponse {
return &CustomerResponse{
ID: c.ID.Hex(),
FullName: c.FullName,
Username: c.Username,
Email: c.Email,
Password: c.Password,
Type: string(c.Type),
Status: string(c.Status),
Phone: c.Phone,
CompanyIDs: c.CompanyIDs,
UpdatedAt: c.UpdatedAt,
CreatedAt: c.CreatedAt,
LastLoginAt: c.LastLoginAt,
Companies: companies,
}
}