refactor: use DTOs instead of manual maps in user responses

This commit is contained in:
2026-01-10 22:34:43 +01:00
parent 00ef0c236e
commit ef4a05f8a5

View File

@@ -47,13 +47,13 @@ func (h *UserHandler) GetUsers(w http.ResponseWriter, r *http.Request) {
} }
userDTOs := dto.ToSanitizedUserDTOs(users) userDTOs := dto.ToSanitizedUserDTOs(users)
responseDTO := dto.UserListDTO{
SendSuccessResponse(w, "Users retrieved successfully", map[string]any{ Users: userDTOs,
"users": userDTOs, Count: len(userDTOs),
"count": len(userDTOs), Limit: limit,
"limit": limit, Offset: offset,
"offset": offset, }
}) SendSuccessResponse(w, "Users retrieved successfully", responseDTO)
} }
// @Summary Get user // @Summary Get user
@@ -132,10 +132,8 @@ func (h *UserHandler) CreateUser(w http.ResponseWriter, r *http.Request) {
} }
} }
SendCreatedResponse(w, "User created successfully. Verification email sent.", map[string]any{ responseDTO := dto.ToRegistrationResponseDTO(result.User, result.VerificationSent)
"user": result.User, SendCreatedResponse(w, "User created successfully. Verification email sent.", responseDTO)
"verification_sent": result.VerificationSent,
})
} }
// @Summary Get user posts // @Summary Get user posts
@@ -167,12 +165,13 @@ func (h *UserHandler) GetUserPosts(w http.ResponseWriter, r *http.Request) {
} }
postDTOs := dto.ToPostDTOs(posts) postDTOs := dto.ToPostDTOs(posts)
SendSuccessResponse(w, "User posts retrieved successfully", map[string]any{ responseDTO := dto.PostListDTO{
"posts": postDTOs, Posts: postDTOs,
"count": len(postDTOs), Count: len(postDTOs),
"limit": limit, Limit: limit,
"offset": offset, Offset: offset,
}) }
SendSuccessResponse(w, "User posts retrieved successfully", responseDTO)
} }
func (h *UserHandler) MountRoutes(r chi.Router, config RouteModuleConfig) { func (h *UserHandler) MountRoutes(r chi.Router, config RouteModuleConfig) {