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 -4
View File
@@ -53,7 +53,7 @@ func (h *Handler) AuthMiddleware() echo.MiddlewareFunc {
}
// Store user information in context for handlers to use
c.Set("user_id", userID)
c.Set("user_id", userID.String())
c.Set("user_email", validationResult.Claims.Email)
c.Set("user_role", validationResult.Claims.Role)
c.Set("company_id", validationResult.Claims.CompanyID)
@@ -147,10 +147,10 @@ func (h *Handler) CompanyAccessMiddleware() echo.MiddlewareFunc {
}
// GetUserIDFromContext extracts user ID from Echo context
func GetUserIDFromContext(c echo.Context) (uuid.UUID, error) {
userID, ok := c.Get("user_id").(uuid.UUID)
func GetUserIDFromContext(c echo.Context) (string, error) {
userID, ok := c.Get("user_id").(string)
if !ok {
return uuid.Nil, echo.NewHTTPError(http.StatusUnauthorized, "User ID not found in context")
return "", echo.NewHTTPError(http.StatusUnauthorized, "User ID not found in context")
}
return userID, nil
}