Remove company_id field from user-related forms and documentation
- Deleted the company_id field from CreateUserForm, User entity, and related API documentation in Swagger and YAML files to streamline user creation process. - Updated the CreateUser service method to reflect the removal of company_id, ensuring consistency across the user management functionality.
This commit is contained in:
@@ -7001,11 +7001,6 @@ const docTemplate = `{
|
||||
"user.CreateUserForm": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"company_id": {
|
||||
"description": "Optional company UUID",
|
||||
"type": "string",
|
||||
"example": "123e4567-e89b-12d3-a456-426614174000"
|
||||
},
|
||||
"department": {
|
||||
"description": "Optional department name",
|
||||
"type": "string",
|
||||
|
||||
@@ -6995,11 +6995,6 @@
|
||||
"user.CreateUserForm": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"company_id": {
|
||||
"description": "Optional company UUID",
|
||||
"type": "string",
|
||||
"example": "123e4567-e89b-12d3-a456-426614174000"
|
||||
},
|
||||
"department": {
|
||||
"description": "Optional department name",
|
||||
"type": "string",
|
||||
|
||||
@@ -1308,10 +1308,6 @@ definitions:
|
||||
type: object
|
||||
user.CreateUserForm:
|
||||
properties:
|
||||
company_id:
|
||||
description: Optional company UUID
|
||||
example: 123e4567-e89b-12d3-a456-426614174000
|
||||
type: string
|
||||
department:
|
||||
description: Optional department name
|
||||
example: Information Technology
|
||||
|
||||
@@ -34,7 +34,6 @@ type User struct {
|
||||
Password string `bson:"password" json:"-"` // Never serialize password
|
||||
Role UserRole `bson:"role" json:"role"`
|
||||
Status UserStatus `bson:"status" json:"status"`
|
||||
CompanyID *string `bson:"company_id,omitempty" json:"company_id,omitempty"`
|
||||
Department *string `bson:"department,omitempty" json:"department,omitempty"`
|
||||
Position *string `bson:"position,omitempty" json:"position,omitempty"`
|
||||
Phone *string `bson:"phone,omitempty" json:"phone,omitempty"`
|
||||
|
||||
+9
-11
@@ -4,16 +4,15 @@ package user
|
||||
|
||||
// CreateUserForm represents the data required to create a new user account
|
||||
type CreateUserForm struct {
|
||||
FullName string `json:"full_name" valid:"required,length(2|100)" example:"John Smith"` // Full name of the user
|
||||
Username string `json:"username" valid:"required,alphanum,length(3|30)" example:"johnsmith"` // Unique username (alphanumeric only)
|
||||
Email string `json:"email" valid:"required,email" example:"john.smith@company.com"` // Valid email address
|
||||
Password string `json:"password" valid:"required,length(8|128)" example:"SecurePass123!"` // Password (minimum 8 characters)
|
||||
Role string `json:"role" valid:"required,in(admin|manager|operator|viewer)" example:"manager"` // User role (admin, manager, operator, viewer)
|
||||
CompanyID *string `json:"company_id,omitempty" valid:"optional,uuid" example:"123e4567-e89b-12d3-a456-426614174000"` // Optional company UUID
|
||||
Department *string `json:"department,omitempty" valid:"optional,length(2|100)" example:"Information Technology"` // Optional department name
|
||||
Position *string `json:"position,omitempty" valid:"optional,length(2|100)" example:"Senior Developer"` // Optional job position
|
||||
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)" example:"+1234567890"` // Optional phone number
|
||||
ProfileImage *string `json:"profile_image,omitempty" valid:"optional,url" example:"https://example.com/avatar.jpg"` // Optional profile image URL
|
||||
FullName string `json:"full_name" valid:"required,length(2|100)" example:"John Smith"` // Full name of the user
|
||||
Username string `json:"username" valid:"required,alphanum,length(3|30)" example:"johnsmith"` // Unique username (alphanumeric only)
|
||||
Email string `json:"email" valid:"required,email" example:"john.smith@company.com"` // Valid email address
|
||||
Password string `json:"password" valid:"required,length(8|128)" example:"SecurePass123!"` // Password (minimum 8 characters)
|
||||
Role string `json:"role" valid:"required,in(admin|manager|operator|viewer)" example:"manager"` // User role (admin, manager, operator, viewer)
|
||||
Department *string `json:"department,omitempty" valid:"optional,length(2|100)" example:"Information Technology"` // Optional department name
|
||||
Position *string `json:"position,omitempty" valid:"optional,length(2|100)" example:"Senior Developer"` // Optional job position
|
||||
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)" example:"+1234567890"` // Optional phone number
|
||||
ProfileImage *string `json:"profile_image,omitempty" valid:"optional,url" example:"https://example.com/avatar.jpg"` // Optional profile image URL
|
||||
}
|
||||
|
||||
// UpdateUserForm represents the data for updating an existing user account
|
||||
@@ -128,7 +127,6 @@ func (u *User) ToResponse() *UserResponse {
|
||||
Email: u.Email,
|
||||
Role: string(u.Role),
|
||||
Status: string(u.Status),
|
||||
CompanyID: u.CompanyID,
|
||||
Department: u.Department,
|
||||
Position: u.Position,
|
||||
Phone: u.Phone,
|
||||
|
||||
@@ -73,12 +73,6 @@ func (s *userService) CreateUser(ctx context.Context, form *CreateUserForm, crea
|
||||
return nil, errors.New("failed to process password")
|
||||
}
|
||||
|
||||
// Parse optional fields
|
||||
var companyID *string
|
||||
if form.CompanyID != nil {
|
||||
companyID = form.CompanyID
|
||||
}
|
||||
|
||||
// Validate role
|
||||
role := UserRole(form.Role)
|
||||
if !s.validator.IsValidRole(role) {
|
||||
@@ -93,7 +87,6 @@ func (s *userService) CreateUser(ctx context.Context, form *CreateUserForm, crea
|
||||
Password: string(hashedPassword),
|
||||
Role: role,
|
||||
Status: UserStatusActive,
|
||||
CompanyID: companyID,
|
||||
Department: form.Department,
|
||||
Position: form.Position,
|
||||
Phone: form.Phone,
|
||||
@@ -168,17 +161,11 @@ func (s *userService) Login(ctx context.Context, form *LoginForm) (*AuthResponse
|
||||
})
|
||||
}
|
||||
|
||||
// Generate JWT tokens using authorization service
|
||||
companyID := ""
|
||||
if user.CompanyID != nil {
|
||||
companyID = *user.CompanyID
|
||||
}
|
||||
|
||||
tokenPair, err := s.authService.GenerateTokenPair(
|
||||
user.ID.Hex(),
|
||||
user.Email,
|
||||
string(user.Role),
|
||||
companyID,
|
||||
"",
|
||||
)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to generate JWT tokens", map[string]interface{}{
|
||||
@@ -443,10 +430,6 @@ func (s *userService) UpdateUser(ctx context.Context, id string, form *UpdateUse
|
||||
user.Role = role
|
||||
}
|
||||
|
||||
if form.CompanyID != nil {
|
||||
user.CompanyID = form.CompanyID
|
||||
}
|
||||
|
||||
if form.Department != nil {
|
||||
user.Department = form.Department
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user