From 8c06c916e150d81a7bfcf01def4d13befd98e0bb Mon Sep 17 00:00:00 2001 From: Kharec Date: Sat, 10 Jan 2026 22:59:43 +0100 Subject: [PATCH] refactor: use GetValidatedDTO for request validation --- internal/handlers/post_handler.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/internal/handlers/post_handler.go b/internal/handlers/post_handler.go index cd52390..ffe74c6 100644 --- a/internal/handlers/post_handler.go +++ b/internal/handlers/post_handler.go @@ -109,9 +109,8 @@ func (h *PostHandler) GetPost(w http.ResponseWriter, r *http.Request) { // @Failure 500 {object} PostResponse "Internal server error" // @Router /api/posts [post] func (h *PostHandler) CreatePost(w http.ResponseWriter, r *http.Request) { - req, ok := GetValidatedDTO[dto.CreatePostRequest](r) + request, ok := GetValidatedDTO[dto.CreatePostRequest](w, r) if !ok { - SendErrorResponse(w, "Invalid request", http.StatusBadRequest) return } @@ -120,9 +119,9 @@ func (h *PostHandler) CreatePost(w http.ResponseWriter, r *http.Request) { return } - title := security.SanitizeInput(req.Title) - url := security.SanitizeURL(req.URL) - content := security.SanitizePostContent(req.Content) + title := security.SanitizeInput(request.Title) + url := security.SanitizeURL(request.URL) + content := security.SanitizePostContent(request.Content) if url == "" { SendErrorResponse(w, "Invalid URL", http.StatusBadRequest) @@ -263,14 +262,13 @@ func (h *PostHandler) UpdatePost(w http.ResponseWriter, r *http.Request) { return } - req, ok := GetValidatedDTO[dto.UpdatePostRequest](r) + request, ok := GetValidatedDTO[dto.UpdatePostRequest](w, r) if !ok { - SendErrorResponse(w, "Invalid request", http.StatusBadRequest) return } - title := security.SanitizeInput(req.Title) - content := security.SanitizePostContent(req.Content) + title := security.SanitizeInput(request.Title) + content := security.SanitizePostContent(request.Content) post.Title = title post.Content = content