From 5d4b38ddc43d7eee4204691d730165120cad8d08 Mon Sep 17 00:00:00 2001 From: Kharec Date: Sun, 23 Nov 2025 13:34:53 +0100 Subject: [PATCH] feat: add validation tags to request DTOs --- internal/dto/auth_request.go | 32 ++++++++++++++++---------------- internal/dto/post_request.go | 10 +++++----- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/internal/dto/auth_request.go b/internal/dto/auth_request.go index 52d72d8..65caccd 100644 --- a/internal/dto/auth_request.go +++ b/internal/dto/auth_request.go @@ -1,51 +1,51 @@ package dto type LoginRequest struct { - Username string `json:"username"` - Password string `json:"password"` + Username string `json:"username" validate:"required,min=3,max=50"` + Password string `json:"password" validate:"required,min=8,max=128"` } type RegisterRequest struct { - Username string `json:"username"` - Email string `json:"email"` - Password string `json:"password"` + Username string `json:"username" validate:"required,min=3,max=50"` + Email string `json:"email" validate:"required,email,max=254"` + Password string `json:"password" validate:"required,min=8,max=128"` } type ResendVerificationRequest struct { - Email string `json:"email"` + Email string `json:"email" validate:"required,email,max=254"` } type ForgotPasswordRequest struct { - UsernameOrEmail string `json:"username_or_email"` + UsernameOrEmail string `json:"username_or_email" validate:"required"` } type ResetPasswordRequest struct { - Token string `json:"token"` - NewPassword string `json:"new_password"` + Token string `json:"token" validate:"required"` + NewPassword string `json:"new_password" validate:"required,min=8,max=128"` } type UpdateEmailRequest struct { - Email string `json:"email"` + Email string `json:"email" validate:"required,email,max=254"` } type UpdateUsernameRequest struct { - Username string `json:"username"` + Username string `json:"username" validate:"required,min=3,max=50"` } type UpdatePasswordRequest struct { - CurrentPassword string `json:"current_password"` - NewPassword string `json:"new_password"` + CurrentPassword string `json:"current_password" validate:"required"` + NewPassword string `json:"new_password" validate:"required,min=8,max=128"` } type ConfirmAccountDeletionRequest struct { - Token string `json:"token"` + Token string `json:"token" validate:"required"` DeletePosts bool `json:"delete_posts"` } type RefreshTokenRequest struct { - RefreshToken string `json:"refresh_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." binding:"required"` + RefreshToken string `json:"refresh_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." validate:"required"` } type RevokeTokenRequest struct { - RefreshToken string `json:"refresh_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." binding:"required"` + RefreshToken string `json:"refresh_token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." validate:"required"` } diff --git a/internal/dto/post_request.go b/internal/dto/post_request.go index b1250d4..1287622 100644 --- a/internal/dto/post_request.go +++ b/internal/dto/post_request.go @@ -1,12 +1,12 @@ package dto type CreatePostRequest struct { - Title string `json:"title"` - URL string `json:"url"` - Content string `json:"content"` + Title string `json:"title" validate:"omitempty,min=3,max=200"` + URL string `json:"url" validate:"required,url,max=2048"` + Content string `json:"content" validate:"omitempty,max=10000"` } type UpdatePostRequest struct { - Title string `json:"title"` - Content string `json:"content"` + Title string `json:"title" validate:"required,min=3,max=200"` + Content string `json:"content" validate:"omitempty,max=10000"` }