Refactor Customer Entity and Forms to Use 'Companies' Field
- Updated the Customer entity to replace 'CompanyIDs' with 'Companies' for improved clarity and consistency. - Modified CreateCustomerForm and UpdateCustomerForm to reflect the change from 'CompanyIDs' to 'Companies', ensuring proper validation and structured responses. - Adjusted service methods to handle the new 'Companies' field, including registration and company assignment logic, enhancing the overall data model and API usability.
This commit is contained in:
+18
-20
@@ -4,26 +4,26 @@ 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"`
|
||||
Role string `json:"role" valid:"required,in(admin|analyst)" example:"analyst"`
|
||||
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"`
|
||||
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"`
|
||||
Role string `json:"role" valid:"required,in(admin|analyst)" example:"analyst"`
|
||||
Companies []string `json:"companies,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"`
|
||||
Role string `json:"role" valid:"required,in(admin|analyst)" example:"analyst"`
|
||||
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"`
|
||||
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"`
|
||||
Role string `json:"role" valid:"required,in(admin|analyst)" example:"analyst"`
|
||||
Companies []string `json:"companies,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
|
||||
@@ -56,7 +56,6 @@ type CustomerResponse struct {
|
||||
Type string `json:"type"`
|
||||
Role string `json:"role"`
|
||||
Phone *string `json:"phone"`
|
||||
CompanyIDs []string `json:"company_ids"`
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
LastLoginAt *int64 `json:"last_login_at"`
|
||||
@@ -74,7 +73,6 @@ func (c *Customer) ToResponse(companies []*CompanySummary) *CustomerResponse {
|
||||
Status: string(c.Status),
|
||||
Role: string(c.Role),
|
||||
Phone: c.Phone,
|
||||
CompanyIDs: c.CompanyIDs,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
CreatedAt: c.CreatedAt,
|
||||
LastLoginAt: c.LastLoginAt,
|
||||
@@ -117,11 +115,11 @@ type AuthResponse struct {
|
||||
}
|
||||
|
||||
type AssignCompaniesForm struct {
|
||||
CompanyIDs []string `json:"company_ids" valid:"required"`
|
||||
Companies []string `json:"companies" valid:"required"`
|
||||
}
|
||||
|
||||
type RemoveCompaniesForm struct {
|
||||
CompanyIDs []string `json:"company_ids" valid:"required"`
|
||||
Companies []string `json:"companies" valid:"required"`
|
||||
}
|
||||
|
||||
// RequestResetPasswordForm represents the form for requesting password reset
|
||||
|
||||
Reference in New Issue
Block a user