Refactor User Management API and Update Documentation
- Changed API tags from "Admin-Users" to "Admin-Authorization" for better clarity in user management endpoints. - Removed unused endpoints for retrieving users by company ID and role, streamlining the user management functionality. - Updated user entity and forms to reflect new example values for improved clarity in API documentation. - Enhanced pagination handling in user listing responses, ensuring consistent metadata structure. - Updated API documentation to reflect changes in endpoint structure and response formats, improving clarity for API consumers.
This commit is contained in:
+45
-47
@@ -1,40 +1,40 @@
|
||||
package user
|
||||
|
||||
import "tm/pkg/response"
|
||||
|
||||
// User Registration DTOs
|
||||
|
||||
// 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)
|
||||
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:"Admin User"` // Full name of the user
|
||||
Username string `json:"username" valid:"required,alphanum,length(3|30)" example:"admin"` // Unique username (alphanumeric only)
|
||||
Email string `json:"email" valid:"required,email" example:"admin@opplens.com"` // Valid email address
|
||||
Password string `json:"password" valid:"required,length(8|128)" example:"Admin!1234"` // Password (minimum 8 characters)
|
||||
Role string `json:"role" valid:"required,in(admin|manager|operator|viewer)" example:"admin"` // User role (admin, manager, operator, viewer)
|
||||
Department *string `json:"department" valid:"optional,length(2|100)" example:"Information Technology"` // Optional department name
|
||||
Position *string `json:"position" valid:"optional,length(2|100)" example:"Lead"` // Optional job position
|
||||
Phone *string `json:"phone" valid:"optional,length(10|20)" example:"+18289784438"` // Optional phone number
|
||||
ProfileImage *string `json:"profile_image" valid:"optional,url" example:""` // Optional profile image URL
|
||||
}
|
||||
|
||||
// UpdateUserForm represents the data for updating an existing user account
|
||||
type UpdateUserForm struct {
|
||||
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)" example:"John Smith"` // Updated full name
|
||||
Username *string `json:"username,omitempty" valid:"optional,alphanum,length(3|30)" example:"johnsmith"` // Updated username
|
||||
Email *string `json:"email,omitempty" valid:"optional,email" example:"john.smith@newcompany.com"` // Updated email address
|
||||
Role *string `json:"role,omitempty" valid:"optional,in(admin|manager|operator|viewer)" example:"admin"` // Updated user role
|
||||
CompanyID *string `json:"company_id,omitempty" valid:"optional,uuid" example:"123e4567-e89b-12d3-a456-426614174000"` // Updated company ID
|
||||
Department *string `json:"department,omitempty" valid:"optional,length(2|100)" example:"Product Management"` // Updated department
|
||||
Position *string `json:"position,omitempty" valid:"optional,length(2|100)" example:"Tech Lead"` // Updated position
|
||||
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)" example:"+1234567890"` // Updated phone number
|
||||
ProfileImage *string `json:"profile_image,omitempty" valid:"optional,url" example:"https://example.com/new-avatar.jpg"` // Updated profile image URL
|
||||
Status *string `json:"status,omitempty" valid:"optional,in(active|inactive|suspended)" example:"active"` // Updated account status
|
||||
FullName *string `json:"full_name" valid:"optional,length(2|100)" example:"Admin User"` // Updated full name
|
||||
Username *string `json:"username" valid:"optional,alphanum,length(3|30)" example:"admin"` // Updated username
|
||||
Email *string `json:"email" valid:"optional,email" example:"admin@opplens.com"` // Updated email address
|
||||
Role *string `json:"role" valid:"optional,in(admin|manager|operator|viewer)" example:"admin"` // Updated user role
|
||||
Department *string `json:"department" valid:"optional,length(2|100)" example:"Information Technology"` // Updated department
|
||||
Position *string `json:"position" valid:"optional,length(2|100)" example:"Lead"` // Updated position
|
||||
Phone *string `json:"phone" valid:"optional,length(10|20)" example:"+18289784438"` // Updated phone number
|
||||
ProfileImage *string `json:"profile_image" valid:"optional,url" example:""` // Updated profile image URL
|
||||
}
|
||||
|
||||
// User Authentication DTOs
|
||||
|
||||
// LoginForm represents the credentials required for user authentication
|
||||
type LoginForm struct {
|
||||
Username string `json:"username" valid:"required" example:"nakhostin"` // Username or email address
|
||||
Password string `json:"password" valid:"required" example:"Nima.1998"` // User password
|
||||
Username string `json:"username" valid:"required" example:"admin"` // Username or email address
|
||||
Password string `json:"password" valid:"required" example:"Admin!1234"` // User password
|
||||
}
|
||||
|
||||
// RefreshTokenForm represents the refresh token required to generate new access tokens
|
||||
@@ -44,22 +44,22 @@ type RefreshTokenForm struct {
|
||||
|
||||
// ChangePasswordForm represents the data required to change user password
|
||||
type ChangePasswordForm struct {
|
||||
OldPassword string `json:"old_password" valid:"required" example:"OldPassword123!"` // Current password for verification
|
||||
NewPassword string `json:"new_password" valid:"required,length(8|128)" example:"NewPass456!"` // New password (minimum 8 characters)
|
||||
OldPassword string `json:"old_password" valid:"required" example:"Admin!1234"` // Current password for verification
|
||||
NewPassword string `json:"new_password" valid:"required,length(8|128)" example:"NewAdmin!1234"` // New password (minimum 8 characters)
|
||||
}
|
||||
|
||||
// UpdateProfileForm represents the data for updating user profile information
|
||||
type UpdateProfileForm struct {
|
||||
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)" example:"John Smith"` // Updated full name
|
||||
Department *string `json:"department,omitempty" valid:"optional,length(2|100)" example:"Engineering"` // Updated department
|
||||
Position *string `json:"position,omitempty" valid:"optional,length(2|100)" example:"Senior Engineer"` // Updated position
|
||||
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)" example:"+1234567890"` // Updated phone number
|
||||
ProfileImage *string `json:"profile_image,omitempty" valid:"optional,url" example:"https://example.com/profile.jpg"` // Updated profile image URL
|
||||
FullName *string `json:"full_name,omitempty" valid:"optional,length(2|100)" example:"Admin User"` // Updated full name
|
||||
Department *string `json:"department,omitempty" valid:"optional,length(2|100)" example:"Information Technology"` // Updated department
|
||||
Position *string `json:"position,omitempty" valid:"optional,length(2|100)" example:"Lead"` // Updated position
|
||||
Phone *string `json:"phone,omitempty" valid:"optional,length(10|20)" example:"+18289784438"` // Updated phone number
|
||||
ProfileImage *string `json:"profile_image,omitempty" valid:"optional,url" example:""` // Updated profile image URL
|
||||
}
|
||||
|
||||
// ResetPasswordForm represents the email address for password reset
|
||||
type ResetPasswordForm struct {
|
||||
Email string `json:"email" valid:"required,email" example:"john.smith@company.com"` // Email address for password reset
|
||||
Email string `json:"email" valid:"required,email" example:"admin@opplens.com"` // Email address for password reset
|
||||
}
|
||||
|
||||
// Admin DTOs
|
||||
@@ -67,7 +67,7 @@ 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"`
|
||||
CompanyID *string `query:"company_id" valid:"optional"`
|
||||
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)"`
|
||||
@@ -90,17 +90,14 @@ type UserResponse struct {
|
||||
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"`
|
||||
Department *string `json:"department"`
|
||||
Position *string `json:"position"`
|
||||
Phone *string `json:"phone"`
|
||||
ProfileImage *string `json:"profile_image"`
|
||||
IsVerified bool `json:"is_verified"`
|
||||
LastLoginAt *int64 `json:"last_login_at,omitempty"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
LastLoginAt *int64 `json:"last_login_at"`
|
||||
UpdatedAt int64 `json:"updated_at"`
|
||||
CreatedBy *string `json:"created_by,omitempty"`
|
||||
UpdatedBy *string `json:"updated_by,omitempty"`
|
||||
CreatedAt int64 `json:"created_at"`
|
||||
}
|
||||
|
||||
type AuthResponse struct {
|
||||
@@ -111,11 +108,14 @@ type AuthResponse struct {
|
||||
}
|
||||
|
||||
type UserListResponse struct {
|
||||
Users []*UserResponse `json:"users"`
|
||||
Total int64 `json:"total"`
|
||||
Limit int `json:"limit"`
|
||||
Offset int `json:"offset"`
|
||||
TotalPages int `json:"total_pages"`
|
||||
Users []*UserResponse `json:"users"`
|
||||
Meta *response.Meta `json:"meta"`
|
||||
}
|
||||
|
||||
type SearchUsersForm 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)"`
|
||||
}
|
||||
|
||||
// Helper function to convert User to UserResponse
|
||||
@@ -133,9 +133,7 @@ func (u *User) ToResponse() *UserResponse {
|
||||
ProfileImage: u.ProfileImage,
|
||||
IsVerified: u.IsVerified,
|
||||
LastLoginAt: u.LastLoginAt,
|
||||
CreatedAt: u.CreatedAt,
|
||||
UpdatedAt: u.UpdatedAt,
|
||||
CreatedBy: u.CreatedBy,
|
||||
UpdatedBy: u.UpdatedBy,
|
||||
CreatedAt: u.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user