08cf927294
- Updated User entity to embed MongoDB model and replace uuid.UUID with string for ID fields. - Modified repository methods to accept string IDs instead of uuid.UUID, enhancing compatibility with MongoDB. - Refactored service and handler methods to align with the new ID type, ensuring consistent usage across the user management functionality. - Improved response handling in UserListResponse to directly use string IDs. - Streamlined index creation in the user repository using the MongoDB ORM for better maintainability.
135 lines
5.3 KiB
Go
135 lines
5.3 KiB
Go
package user
|
|
|
|
// User Registration DTOs
|
|
type CreateUserForm struct {
|
|
FullName string `json:"full_name" valid:"required,length(2|100)"`
|
|
Username string `json:"username" valid:"required,alphanum,length(3|30)"`
|
|
Email string `json:"email" valid:"required,email"`
|
|
Password string `json:"password" valid:"required,length(8|128)"`
|
|
Role string `json:"role" valid:"required,in(admin|manager|operator|viewer)"`
|
|
CompanyID *string `json:"company_id,omitempty" valid:"optional,uuid"`
|
|
Department *string `json:"department,omitempty" valid:"optional,length(2|100)"`
|
|
Position *string `json:"position,omitempty" valid:"optional,length(2|100)"`
|
|
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
|
|
ProfileImage *string `json:"profile_image,omitempty" valid:"optional,url"`
|
|
}
|
|
|
|
type UpdateUserForm struct {
|
|
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)"`
|
|
Username *string `json:"username,omitempty" valid:"optional,alphanum,length(3|30)"`
|
|
Email *string `json:"email,omitempty" valid:"optional,email"`
|
|
Role *string `json:"role,omitempty" valid:"optional,in(admin|manager|operator|viewer)"`
|
|
CompanyID *string `json:"company_id,omitempty" valid:"optional,uuid"`
|
|
Department *string `json:"department,omitempty" valid:"optional,length(2|100)"`
|
|
Position *string `json:"position,omitempty" valid:"optional,length(2|100)"`
|
|
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
|
|
ProfileImage *string `json:"profile_image,omitempty" valid:"optional,url"`
|
|
Status *string `json:"status,omitempty" valid:"optional,in(active|inactive|suspended)"`
|
|
}
|
|
|
|
// User Authentication DTOs
|
|
type LoginForm struct {
|
|
Username string `json:"username" valid:"required"`
|
|
Password string `json:"password" valid:"required"`
|
|
}
|
|
|
|
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)"`
|
|
Department *string `json:"department,omitempty" valid:"optional,length(2|100)"`
|
|
Position *string `json:"position,omitempty" valid:"optional,length(2|100)"`
|
|
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
|
|
ProfileImage *string `json:"profile_image,omitempty" valid:"optional,url"`
|
|
}
|
|
|
|
type ResetPasswordForm struct {
|
|
Email string `json:"email" valid:"required,email"`
|
|
}
|
|
|
|
// Admin DTOs
|
|
type ListUsersForm struct {
|
|
Search *string `query:"search" valid:"optional"`
|
|
Status *string `query:"status" valid:"optional,in(active|inactive|suspended)"`
|
|
Role *string `query:"role" valid:"optional,in(admin|manager|operator|viewer)"`
|
|
CompanyID *string `query:"company_id" valid:"optional,uuid"`
|
|
Limit *int `query:"limit" valid:"optional,range(1|100)"`
|
|
Offset *int `query:"offset" valid:"optional,min(0)"`
|
|
SortBy *string `query:"sort_by" valid:"optional,in(full_name|email|username|role|created_at|last_login_at)"`
|
|
SortOrder *string `query:"sort_order" valid:"optional,in(asc|desc)"`
|
|
}
|
|
|
|
type UpdateUserStatusForm struct {
|
|
Status string `json:"status" valid:"required,in(active|inactive|suspended)"`
|
|
}
|
|
|
|
type UpdateUserRoleForm struct {
|
|
Role string `json:"role" valid:"required,in(admin|manager|operator|viewer)"`
|
|
}
|
|
|
|
// Response DTOs
|
|
type UserResponse struct {
|
|
ID string `json:"id"`
|
|
FullName string `json:"full_name"`
|
|
Username string `json:"username"`
|
|
Email string `json:"email"`
|
|
Role string `json:"role"`
|
|
Status string `json:"status"`
|
|
CompanyID *string `json:"company_id,omitempty"`
|
|
Department *string `json:"department,omitempty"`
|
|
Position *string `json:"position,omitempty"`
|
|
Phone *string `json:"phone,omitempty"`
|
|
ProfileImage *string `json:"profile_image,omitempty"`
|
|
IsVerified bool `json:"is_verified"`
|
|
LastLoginAt *int64 `json:"last_login_at,omitempty"`
|
|
CreatedAt int64 `json:"created_at"`
|
|
UpdatedAt int64 `json:"updated_at"`
|
|
CreatedBy *string `json:"created_by,omitempty"`
|
|
UpdatedBy *string `json:"updated_by,omitempty"`
|
|
}
|
|
|
|
type AuthResponse struct {
|
|
User *UserResponse `json:"user"`
|
|
AccessToken string `json:"access_token"`
|
|
RefreshToken string `json:"refresh_token"`
|
|
ExpiresAt int64 `json:"expires_at"`
|
|
}
|
|
|
|
type UserListResponse struct {
|
|
Users []*UserResponse `json:"users"`
|
|
Total int64 `json:"total"`
|
|
Limit int `json:"limit"`
|
|
Offset int `json:"offset"`
|
|
TotalPages int `json:"total_pages"`
|
|
}
|
|
|
|
// Helper function to convert User to UserResponse
|
|
func (u *User) ToResponse() *UserResponse {
|
|
return &UserResponse{
|
|
ID: u.ID,
|
|
FullName: u.FullName,
|
|
Username: u.Username,
|
|
Email: u.Email,
|
|
Role: string(u.Role),
|
|
Status: string(u.Status),
|
|
CompanyID: u.CompanyID,
|
|
Department: u.Department,
|
|
Position: u.Position,
|
|
Phone: u.Phone,
|
|
ProfileImage: u.ProfileImage,
|
|
IsVerified: u.IsVerified,
|
|
LastLoginAt: u.LastLoginAt,
|
|
CreatedAt: u.CreatedAt,
|
|
UpdatedAt: u.UpdatedAt,
|
|
CreatedBy: u.CreatedBy,
|
|
UpdatedBy: u.UpdatedBy,
|
|
}
|
|
}
|