3b265e567d
- Moved CompanySummary and CustomerResponse structures from entity.go to form.go, improving organization and clarity of customer-related data representations. - Updated the ToResponse method to maintain functionality while aligning with the new structure, ensuring consistent API responses for customer data. - This refactor enhances the maintainability of the codebase by adhering to clean architecture principles and improving the separation of concerns.
123 lines
4.8 KiB
Go
123 lines
4.8 KiB
Go
package customer
|
|
|
|
import "tm/pkg/response"
|
|
|
|
// CreateCustomerForm represents the form for creating a new customer
|
|
type CreateCustomerForm struct {
|
|
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)" example:"User"`
|
|
Type string `json:"type" valid:"required,in(individual|company|government)" example:"individual"`
|
|
CompanyIDs []string `json:"company_ids,omitempty" valid:"optional"`
|
|
Username string `json:"username" valid:"required,alphanum,length(3|30)" example:"user"`
|
|
Email string `json:"email" valid:"required,email" example:"user@opplens.com"`
|
|
Password string `json:"password" valid:"required,length(8|128)" example:"User!1234"`
|
|
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)" example:"+1234567890"`
|
|
}
|
|
|
|
// UpdateCustomerForm represents the form for updating a customer
|
|
type UpdateCustomerForm struct {
|
|
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)" example:"User"`
|
|
Type string `json:"type" valid:"required,in(individual|company|government)" example:"individual"`
|
|
CompanyIDs []string `json:"company_ids,omitempty" valid:"optional"`
|
|
Username string `json:"username" valid:"required,alphanum,length(3|30)" example:"user"`
|
|
Email string `json:"email" valid:"required,email" example:"user@opplens.com"`
|
|
Password string `json:"password" valid:"required,length(8|128)" example:"User!1234"`
|
|
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)" example:"+1234567890"`
|
|
}
|
|
|
|
// CustomerStatusForm represents the form for suspending a customer
|
|
type UpdateStatusForm struct {
|
|
Status string `json:"status" valid:"required,in(active|inactive|suspended)" example:"active"`
|
|
Reason string `json:"reason" valid:"required,length(10|500)" example:"Customer is active"`
|
|
}
|
|
|
|
// ListCustomersForm represents the form for listing customers with filters
|
|
type SearchCustomersForm struct {
|
|
Search *string `query:"q" valid:"optional"`
|
|
Type *string `query:"type" valid:"optional,in(individual|company|government)"`
|
|
Status *string `query:"status" valid:"optional,in(active|inactive|suspended)"`
|
|
CompanyID *string `query:"company_id" valid:"optional"`
|
|
}
|
|
|
|
// 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,
|
|
}
|
|
}
|
|
|
|
// CustomerListResponse represents the response for listing customers
|
|
type CustomerListResponse struct {
|
|
Customers []*CustomerResponse `json:"customers"`
|
|
Meta *response.Meta `json:"-"`
|
|
}
|
|
|
|
type LoginForm struct {
|
|
Username string `json:"username" valid:"required" example:"app"`
|
|
Password string `json:"password" valid:"required" example:"App!1234"`
|
|
}
|
|
|
|
type RefreshTokenForm struct {
|
|
RefreshToken string `json:"refresh_token" valid:"required"`
|
|
}
|
|
|
|
type ChangePasswordForm struct {
|
|
OldPassword string `json:"old_password" valid:"required"`
|
|
NewPassword string `json:"new_password" valid:"required,length(8|128)"`
|
|
}
|
|
|
|
type UpdateProfileForm struct {
|
|
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)"`
|
|
Username *string `json:"username,omitempty" valid:"optional,alphanum,length(3|30)"`
|
|
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
|
|
}
|
|
|
|
type AuthResponse struct {
|
|
Customer *CustomerResponse `json:"customer"`
|
|
AccessToken string `json:"access_token"`
|
|
RefreshToken string `json:"refresh_token"`
|
|
ExpiresAt int64 `json:"expires_at"`
|
|
}
|
|
|
|
type AssignCompaniesForm struct {
|
|
CompanyIDs []string `json:"company_ids" valid:"required"`
|
|
}
|
|
|
|
type RemoveCompaniesForm struct {
|
|
CompanyIDs []string `json:"company_ids" valid:"required"`
|
|
}
|