Enhance cursor rules and add user management functionality
- Updated cursor rules to emphasize the importance of dependency injection and logging practices. - Introduced a new user management domain, including entities, services, handlers, and validation. - Implemented user authentication features such as login, registration, and role-based access control. - Added Redis integration for token management and caching. - Enhanced API documentation with Swagger for user-related endpoints. - Updated configuration to support new JWT settings and Redis connection parameters.
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
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 {
|
||||
companyID := ""
|
||||
if u.CompanyID != nil {
|
||||
companyID = u.CompanyID.String()
|
||||
}
|
||||
|
||||
createdBy := ""
|
||||
if u.CreatedBy != nil {
|
||||
createdBy = u.CreatedBy.String()
|
||||
}
|
||||
|
||||
updatedBy := ""
|
||||
if u.UpdatedBy != nil {
|
||||
updatedBy = u.UpdatedBy.String()
|
||||
}
|
||||
|
||||
return &UserResponse{
|
||||
ID: u.ID.String(),
|
||||
FullName: u.FullName,
|
||||
Username: u.Username,
|
||||
Email: u.Email,
|
||||
Role: string(u.Role),
|
||||
Status: string(u.Status),
|
||||
CompanyID: &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: &createdBy,
|
||||
UpdatedBy: &updatedBy,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user