Enhance API documentation and restructure routes for improved clarity
- Updated README.md to include comprehensive Swagger documentation details, highlighting new features and endpoint categories. - Introduced a new router structure to streamline route registration for admin and public endpoints, enhancing maintainability. - Updated health check endpoint documentation to reflect comprehensive server status information. - Enhanced customer and company management routes with improved descriptions and examples in Swagger. - Refactored customer and user handlers to remove obsolete route registrations, aligning with the new router structure. - Improved response handling in customer and user services to utilize string IDs consistently. - Updated validation rules and forms for customer management to support multiple company assignments. - Enhanced logging practices across services to ensure better traceability and error handling.
This commit is contained in:
+51
-30
@@ -2,6 +2,8 @@ package customer
|
||||
|
||||
import (
|
||||
"tm/pkg/mongo"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
// CustomerStatus represents customer account status
|
||||
@@ -26,9 +28,9 @@ const (
|
||||
// Customer represents a customer in the tender management system
|
||||
// A customer can have an associated company for login purposes
|
||||
type Customer struct {
|
||||
mongo.Model
|
||||
Type CustomerType `bson:"type" json:"type"`
|
||||
Status CustomerStatus `bson:"status" json:"status"`
|
||||
mongo.Model `bson:",inline"`
|
||||
Type CustomerType `bson:"type" json:"type"`
|
||||
Status CustomerStatus `bson:"status" json:"status"`
|
||||
|
||||
// Individual customer fields
|
||||
FirstName *string `bson:"first_name,omitempty" json:"first_name,omitempty"`
|
||||
@@ -40,8 +42,10 @@ type Customer struct {
|
||||
Phone *string `bson:"phone,omitempty" json:"phone,omitempty"`
|
||||
Mobile *string `bson:"mobile,omitempty" json:"mobile,omitempty"`
|
||||
|
||||
// Company customer fields (for when customer represents a company)
|
||||
CompanyID *string `bson:"company_id,omitempty" json:"company_id,omitempty"`
|
||||
// Company relationships - each customer can be assigned to multiple companies
|
||||
CompanyIDs []string `bson:"company_ids,omitempty" json:"company_ids,omitempty"`
|
||||
|
||||
// Company customer fields
|
||||
RegistrationNumber *string `bson:"registration_number,omitempty" json:"registration_number,omitempty"`
|
||||
TaxID *string `bson:"tax_id,omitempty" json:"tax_id,omitempty"`
|
||||
Industry *string `bson:"industry,omitempty" json:"industry,omitempty"`
|
||||
@@ -75,12 +79,12 @@ type Customer struct {
|
||||
|
||||
// SetID sets the customer ID (implements IDSetter interface)
|
||||
func (c *Customer) SetID(id string) {
|
||||
c.ID = id
|
||||
c.ID, _ = primitive.ObjectIDFromHex(id)
|
||||
}
|
||||
|
||||
// GetID returns the customer ID (implements IDGetter interface)
|
||||
func (c *Customer) GetID() string {
|
||||
return c.ID
|
||||
return c.ID.Hex()
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the created timestamp (implements Timestampable interface)
|
||||
@@ -126,44 +130,54 @@ type ContactPerson struct {
|
||||
IsPrimary bool `bson:"is_primary" json:"is_primary"`
|
||||
}
|
||||
|
||||
// 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 `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
FirstName *string `json:"first_name,omitempty"`
|
||||
LastName *string `json:"last_name,omitempty"`
|
||||
FullName *string `json:"full_name,omitempty"`
|
||||
Email string `json:"email"`
|
||||
Phone *string `json:"phone,omitempty"`
|
||||
Mobile *string `json:"mobile,omitempty"`
|
||||
CompanyID *string `json:"company_id,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
FirstName *string `json:"first_name,omitempty"`
|
||||
LastName *string `json:"last_name,omitempty"`
|
||||
FullName *string `json:"full_name,omitempty"`
|
||||
Email string `json:"email"`
|
||||
Phone *string `json:"phone,omitempty"`
|
||||
Mobile *string `json:"mobile,omitempty"`
|
||||
|
||||
// Company relationships
|
||||
Companies []*CompanySummary `json:"companies,omitempty"`
|
||||
|
||||
// Company customer fields
|
||||
RegistrationNumber *string `json:"registration_number,omitempty"`
|
||||
TaxID *string `json:"tax_id,omitempty"`
|
||||
Industry *string `json:"industry,omitempty"`
|
||||
Address *Address `json:"address,omitempty"`
|
||||
BusinessType *string `json:"business_type,omitempty"`
|
||||
EmployeeCount *int `json:"employee_count,omitempty"`
|
||||
AnnualRevenue *float64 `json:"annual_revenue,omitempty"`
|
||||
FoundedYear *int `json:"founded_year,omitempty"`
|
||||
ContactPerson *ContactPerson `json:"contact_person,omitempty"`
|
||||
TaxID *string `json:"tax_id"`
|
||||
Industry *string `json:"industry"`
|
||||
Address *Address `json:"address"`
|
||||
BusinessType *string `json:"business_type"`
|
||||
EmployeeCount *int `json:"employee_count"`
|
||||
AnnualRevenue *float64 `json:"annual_revenue"`
|
||||
FoundedYear *int `json:"founded_year"`
|
||||
ContactPerson *ContactPerson `json:"contact_person"`
|
||||
IsVerified bool `json:"is_verified"`
|
||||
IsCompliant bool `json:"is_compliant"`
|
||||
ComplianceNotes *string `json:"compliance_notes,omitempty"`
|
||||
ComplianceNotes *string `json:"compliance_notes"`
|
||||
Language string `json:"language"`
|
||||
Username string `json:"username"`
|
||||
Currency string `json:"currency"`
|
||||
Timezone string `json:"timezone"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
CreatedBy *string `json:"created_by,omitempty"`
|
||||
UpdatedBy *string `json:"updated_by,omitempty"`
|
||||
CreatedBy *string `json:"created_by"`
|
||||
UpdatedBy *string `json:"updated_by"`
|
||||
}
|
||||
|
||||
// ToResponse converts Customer to CustomerResponse
|
||||
func (c *Customer) ToResponse() *CustomerResponse {
|
||||
return &CustomerResponse{
|
||||
ID: c.ID,
|
||||
ID: c.ID.Hex(),
|
||||
Type: string(c.Type),
|
||||
Status: string(c.Status),
|
||||
FirstName: c.FirstName,
|
||||
@@ -173,7 +187,7 @@ func (c *Customer) ToResponse() *CustomerResponse {
|
||||
Email: c.Email,
|
||||
Phone: c.Phone,
|
||||
Mobile: c.Mobile,
|
||||
CompanyID: c.CompanyID,
|
||||
Companies: nil, // Will be populated by service layer
|
||||
RegistrationNumber: c.RegistrationNumber,
|
||||
TaxID: c.TaxID,
|
||||
Industry: c.Industry,
|
||||
@@ -195,3 +209,10 @@ func (c *Customer) ToResponse() *CustomerResponse {
|
||||
UpdatedBy: c.UpdatedBy,
|
||||
}
|
||||
}
|
||||
|
||||
// ToResponseWithCompanies converts Customer to CustomerResponse with company information
|
||||
func (c *Customer) ToResponseWithCompanies(companies []*CompanySummary) *CustomerResponse {
|
||||
response := c.ToResponse()
|
||||
response.Companies = companies
|
||||
return response
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user