Add Role Assignment Feature for Customers
- 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.
This commit is contained in:
@@ -6,6 +6,7 @@ import "tm/pkg/response"
|
||||
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"`
|
||||
@@ -17,6 +18,7 @@ type CreateCustomerForm struct {
|
||||
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"`
|
||||
@@ -52,6 +54,7 @@ type CustomerResponse struct {
|
||||
Email string `json:"email"`
|
||||
Status string `json:"status"`
|
||||
Type string `json:"type"`
|
||||
Role string `json:"role"`
|
||||
Phone *string `json:"phone"`
|
||||
CompanyIDs []string `json:"company_ids"`
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
@@ -69,6 +72,7 @@ func (c *Customer) ToResponse(companies []*CompanySummary) *CustomerResponse {
|
||||
Email: c.Email,
|
||||
Type: string(c.Type),
|
||||
Status: string(c.Status),
|
||||
Role: string(c.Role),
|
||||
Phone: c.Phone,
|
||||
CompanyIDs: c.CompanyIDs,
|
||||
UpdatedAt: c.UpdatedAt,
|
||||
@@ -154,3 +158,14 @@ type ResetPasswordResponse struct {
|
||||
Message string `json:"message" example:"Password reset successfully"`
|
||||
Success bool `json:"success" example:"true"`
|
||||
}
|
||||
|
||||
// AssignRoleForm represents the form for assigning a role to a customer
|
||||
type AssignRoleForm struct {
|
||||
Role string `json:"role" valid:"required,in(admin|analyst)" example:"analyst"`
|
||||
}
|
||||
|
||||
// AssignRoleResponse represents the response for role assignment
|
||||
type AssignRoleResponse struct {
|
||||
Message string `json:"message" example:"Role assigned successfully"`
|
||||
Success bool `json:"success" example:"true"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user