From f39dcff67d2000756aa84f287fe30b27a0721204 Mon Sep 17 00:00:00 2001 From: Kharec Date: Sat, 10 Jan 2026 22:44:39 +0100 Subject: [PATCH] refactor: use DTOs instead of maps and nil for responses --- internal/handlers/auth_handler.go | 19 ++++++++++--------- internal/handlers/post_handler.go | 9 +++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/internal/handlers/auth_handler.go b/internal/handlers/auth_handler.go index d43127a..1159b1a 100644 --- a/internal/handlers/auth_handler.go +++ b/internal/handlers/auth_handler.go @@ -214,9 +214,10 @@ func (h *AuthHandler) ResendVerificationEmail(w http.ResponseWriter, r *http.Req return } - SendSuccessResponse(w, "Verification email sent successfully", map[string]any{ - "message": "Check your inbox for the verification link", - }) + responseDTO := dto.MessageResponseDTO{ + Message: "Check your inbox for the verification link", + } + SendSuccessResponse(w, "Verification email sent successfully", responseDTO) } // @Summary Get current user profile @@ -271,7 +272,7 @@ func (h *AuthHandler) RequestPasswordReset(w http.ResponseWriter, r *http.Reques if err := h.authService.RequestPasswordReset(usernameOrEmail); err != nil { } - SendSuccessResponse(w, "If an account with that username or email exists, we've sent a password reset link.", nil) + SendSuccessResponse(w, "If an account with that username or email exists, we've sent a password reset link.", dto.EmptyResponseDTO{}) } // @Summary Reset password @@ -311,7 +312,7 @@ func (h *AuthHandler) ResetPassword(w http.ResponseWriter, r *http.Request) { return } - SendSuccessResponse(w, "Password reset successfully. You can now sign in with your new password.", nil) + SendSuccessResponse(w, "Password reset successfully. You can now sign in with your new password.", dto.EmptyResponseDTO{}) } // @Summary Update email address @@ -471,7 +472,7 @@ func (h *AuthHandler) DeleteAccount(w http.ResponseWriter, r *http.Request) { return } - SendSuccessResponse(w, "Check your inbox for a confirmation link to finish deleting your account.", nil) + SendSuccessResponse(w, "Check your inbox for a confirmation link to finish deleting your account.", dto.EmptyResponseDTO{}) } // @Summary Confirm account deletion @@ -532,7 +533,7 @@ func (h *AuthHandler) ConfirmAccountDeletion(w http.ResponseWriter, r *http.Requ // @Failure 401 {object} AuthResponse "Authentication required" // @Router /api/auth/logout [post] func (h *AuthHandler) Logout(w http.ResponseWriter, r *http.Request) { - SendSuccessResponse(w, "Logged out successfully", nil) + SendSuccessResponse(w, "Logged out successfully", dto.EmptyResponseDTO{}) } // @Summary Refresh access token @@ -597,7 +598,7 @@ func (h *AuthHandler) RevokeToken(w http.ResponseWriter, r *http.Request) { return } - SendSuccessResponse(w, "Token revoked successfully", nil) + SendSuccessResponse(w, "Token revoked successfully", dto.EmptyResponseDTO{}) } // @Summary Revoke all user tokens @@ -622,7 +623,7 @@ func (h *AuthHandler) RevokeAllTokens(w http.ResponseWriter, r *http.Request) { return } - SendSuccessResponse(w, "All tokens revoked successfully", nil) + SendSuccessResponse(w, "All tokens revoked successfully", dto.EmptyResponseDTO{}) } func (h *AuthHandler) MountRoutes(r chi.Router, config RouteModuleConfig) { diff --git a/internal/handlers/post_handler.go b/internal/handlers/post_handler.go index 5bdf835..cd52390 100644 --- a/internal/handlers/post_handler.go +++ b/internal/handlers/post_handler.go @@ -329,7 +329,7 @@ func (h *PostHandler) DeletePost(w http.ResponseWriter, r *http.Request) { return } - SendSuccessResponse(w, "Post deleted successfully", nil) + SendSuccessResponse(w, "Post deleted successfully", dto.EmptyResponseDTO{}) } // @Summary Fetch title from URL @@ -371,9 +371,10 @@ func (h *PostHandler) FetchTitleFromURL(w http.ResponseWriter, r *http.Request) return } - SendSuccessResponse(w, "Title fetched successfully", map[string]string{ - "title": title, - }) + responseDTO := dto.TitleResponseDTO{ + Title: title, + } + SendSuccessResponse(w, "Title fetched successfully", responseDTO) } func translatePostCreateError(err error) (string, int) {