Refactor user domain to utilize string IDs and integrate MongoDB ORM

- 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.
This commit is contained in:
n.nakhostin
2025-08-11 13:45:46 +03:30
parent 8c1e593686
commit 08cf927294
6 changed files with 252 additions and 355 deletions
+4 -19
View File
@@ -112,29 +112,14 @@ type UserListResponse struct {
// 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(),
ID: u.ID,
FullName: u.FullName,
Username: u.Username,
Email: u.Email,
Role: string(u.Role),
Status: string(u.Status),
CompanyID: &companyID,
CompanyID: u.CompanyID,
Department: u.Department,
Position: u.Position,
Phone: u.Phone,
@@ -143,7 +128,7 @@ func (u *User) ToResponse() *UserResponse {
LastLoginAt: u.LastLoginAt,
CreatedAt: u.CreatedAt,
UpdatedAt: u.UpdatedAt,
CreatedBy: &createdBy,
UpdatedBy: &updatedBy,
CreatedBy: u.CreatedBy,
UpdatedBy: u.UpdatedBy,
}
}