Implement customer management domain with authorization and API enhancements
- Introduced a new customer management domain, including entities, services, handlers, and forms for customer operations. - Added JWT-based user authorization settings in the configuration file for both user and customer management. - Updated API endpoints to reflect the new structure, including changes to health check and user management routes. - Enhanced Swagger documentation to include new customer-related endpoints and authorization details. - Refactored the Makefile to include a target for generating API documentation. - Removed obsolete documentation files to streamline the project structure.
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
package customer
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// CustomerStatus represents customer account status
|
||||
type CustomerStatus string
|
||||
|
||||
const (
|
||||
CustomerStatusActive CustomerStatus = "active"
|
||||
CustomerStatusInactive CustomerStatus = "inactive"
|
||||
CustomerStatusSuspended CustomerStatus = "suspended"
|
||||
CustomerStatusPending CustomerStatus = "pending"
|
||||
)
|
||||
|
||||
// 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
|
||||
type Customer struct {
|
||||
ID uuid.UUID `bson:"_id"`
|
||||
Type CustomerType `bson:"type"`
|
||||
Status CustomerStatus `bson:"status"`
|
||||
CompanyID *uuid.UUID `bson:"company_id,omitempty"`
|
||||
|
||||
// Individual customer fields
|
||||
FirstName *string `bson:"first_name,omitempty"`
|
||||
LastName *string `bson:"last_name,omitempty"`
|
||||
FullName *string `bson:"full_name,omitempty"`
|
||||
Username string `bson:"username"` // Username for authentication
|
||||
Email string `bson:"email"`
|
||||
Password string `bson:"password"` // Hashed password for authentication
|
||||
Phone *string `bson:"phone,omitempty"`
|
||||
Mobile *string `bson:"mobile,omitempty"`
|
||||
|
||||
// Company customer fields
|
||||
CompanyName *string `bson:"company_name,omitempty"`
|
||||
RegistrationNumber *string `bson:"registration_number,omitempty"`
|
||||
TaxID *string `bson:"tax_id,omitempty"`
|
||||
Industry *string `bson:"industry,omitempty"`
|
||||
|
||||
// Address information
|
||||
Address *Address `bson:"address,omitempty"`
|
||||
|
||||
// Business information
|
||||
BusinessType *string `bson:"business_type,omitempty"`
|
||||
EmployeeCount *int `bson:"employee_count,omitempty"`
|
||||
AnnualRevenue *float64 `bson:"annual_revenue,omitempty"`
|
||||
FoundedYear *int `bson:"founded_year,omitempty"`
|
||||
|
||||
// Contact person (for company customers)
|
||||
ContactPerson *ContactPerson `bson:"contact_person,omitempty"`
|
||||
|
||||
// Verification and compliance
|
||||
IsVerified bool `bson:"is_verified"`
|
||||
IsCompliant bool `bson:"is_compliant"`
|
||||
ComplianceNotes *string `bson:"compliance_notes,omitempty"`
|
||||
|
||||
// Preferences and settings
|
||||
Language string `bson:"language"` // Default: "en"
|
||||
Currency string `bson:"currency"` // Default: "USD"
|
||||
Timezone string `bson:"timezone"` // Default: "UTC"
|
||||
|
||||
// Audit fields
|
||||
CreatedAt int64 `bson:"created_at"` // Unix timestamp
|
||||
UpdatedAt int64 `bson:"updated_at"` // Unix timestamp
|
||||
CreatedBy *uuid.UUID `bson:"created_by,omitempty"`
|
||||
UpdatedBy *uuid.UUID `bson:"updated_by,omitempty"`
|
||||
}
|
||||
|
||||
// Address represents a customer's address
|
||||
type Address struct {
|
||||
Street string `bson:"street"`
|
||||
City string `bson:"city"`
|
||||
State string `bson:"state"`
|
||||
PostalCode string `bson:"postal_code"`
|
||||
Country string `bson:"country"`
|
||||
AddressType string `bson:"address_type"` // billing, shipping, etc.
|
||||
IsDefault bool `bson:"is_default"`
|
||||
}
|
||||
|
||||
// ContactPerson represents a contact person for company customers
|
||||
type ContactPerson struct {
|
||||
FirstName string `bson:"first_name"`
|
||||
LastName string `bson:"last_name"`
|
||||
FullName string `bson:"full_name"`
|
||||
Position string `bson:"position"`
|
||||
Email string `bson:"email"`
|
||||
Phone string `bson:"phone"`
|
||||
Mobile *string `bson:"mobile,omitempty"`
|
||||
IsPrimary bool `bson:"is_primary"`
|
||||
}
|
||||
|
||||
// CustomerResponse represents the customer data sent in API responses
|
||||
type CustomerResponse struct {
|
||||
ID string `json:"id"`
|
||||
Type string `json:"type"`
|
||||
Status string `json:"status"`
|
||||
CompanyID *string `json:"company_id,omitempty"`
|
||||
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"`
|
||||
CompanyName *string `json:"company_name,omitempty"`
|
||||
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"`
|
||||
IsVerified bool `json:"is_verified"`
|
||||
IsCompliant bool `json:"is_compliant"`
|
||||
ComplianceNotes *string `json:"compliance_notes,omitempty"`
|
||||
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"`
|
||||
}
|
||||
|
||||
// ToResponse converts Customer to CustomerResponse
|
||||
func (c *Customer) ToResponse() *CustomerResponse {
|
||||
companyID := ""
|
||||
if c.CompanyID != nil {
|
||||
companyID = c.CompanyID.String()
|
||||
}
|
||||
|
||||
createdBy := ""
|
||||
if c.CreatedBy != nil {
|
||||
createdBy = c.CreatedBy.String()
|
||||
}
|
||||
|
||||
updatedBy := ""
|
||||
if c.UpdatedBy != nil {
|
||||
updatedBy = c.UpdatedBy.String()
|
||||
}
|
||||
|
||||
return &CustomerResponse{
|
||||
ID: c.ID.String(),
|
||||
Type: string(c.Type),
|
||||
Status: string(c.Status),
|
||||
CompanyID: &companyID,
|
||||
FirstName: c.FirstName,
|
||||
LastName: c.LastName,
|
||||
FullName: c.FullName,
|
||||
Username: c.Username,
|
||||
Email: c.Email,
|
||||
Phone: c.Phone,
|
||||
Mobile: c.Mobile,
|
||||
CompanyName: c.CompanyName,
|
||||
RegistrationNumber: c.RegistrationNumber,
|
||||
TaxID: c.TaxID,
|
||||
Industry: c.Industry,
|
||||
Address: c.Address,
|
||||
BusinessType: c.BusinessType,
|
||||
EmployeeCount: c.EmployeeCount,
|
||||
AnnualRevenue: c.AnnualRevenue,
|
||||
FoundedYear: c.FoundedYear,
|
||||
ContactPerson: c.ContactPerson,
|
||||
IsVerified: c.IsVerified,
|
||||
IsCompliant: c.IsCompliant,
|
||||
ComplianceNotes: c.ComplianceNotes,
|
||||
Language: c.Language,
|
||||
Currency: c.Currency,
|
||||
Timezone: c.Timezone,
|
||||
CreatedAt: c.CreatedAt,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
CreatedBy: &createdBy,
|
||||
UpdatedBy: &updatedBy,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user