b429bcd24f
- Introduced a new role assignment feature for customers, allowing roles to be assigned as either 'admin' or 'analyst'. - Updated the Customer entity to include a Role field, enhancing the data model to support role management. - Created new request and response forms for role assignment, ensuring proper validation and structured responses. - Implemented the AssignRole method in the customer service layer, handling role assignment logic and error management. - Added a new AssignRole handler to process role assignment requests via the API, complete with Swagger documentation for clarity. - Updated routes to include the new role assignment endpoint, improving the administrative capabilities of the system. - Enhanced logging for role assignment operations to ensure traceability and debugging ease.
98 lines
2.9 KiB
Go
98 lines
2.9 KiB
Go
package customer
|
|
|
|
import (
|
|
"tm/pkg/mongo"
|
|
|
|
"go.mongodb.org/mongo-driver/v2/bson"
|
|
)
|
|
|
|
// 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"
|
|
)
|
|
|
|
// CustomerRole represents the role of customer
|
|
type CustomerRole string
|
|
|
|
const (
|
|
CustomerRoleAdmin CustomerRole = "admin"
|
|
CustomerRoleAnalyst CustomerRole = "analyst"
|
|
)
|
|
|
|
// 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"`
|
|
Role CustomerRole `bson:"role"`
|
|
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, _ = bson.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
|
|
}
|
|
|
|
// OTP represents a one-time password for password reset
|
|
type OTP struct {
|
|
Code string `bson:"code" json:"code"`
|
|
Email string `bson:"email" json:"email"`
|
|
ExpiresAt int64 `bson:"expires_at" json:"expires_at"`
|
|
CreatedAt int64 `bson:"created_at" json:"created_at"`
|
|
}
|
|
|
|
// ResetToken represents a temporary reset token for password reset
|
|
type ResetToken struct {
|
|
Token string `bson:"token" json:"token"`
|
|
Email string `bson:"email" json:"email"`
|
|
ExpiresAt int64 `bson:"expires_at" json:"expires_at"`
|
|
CreatedAt int64 `bson:"created_at" json:"created_at"`
|
|
}
|