refactor: use DTOs instead of manual maps in auth responses
This commit is contained in:
@@ -151,22 +151,8 @@ func (h *AuthHandler) Register(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
userData := map[string]any{
|
responseDTO := dto.ToRegistrationResponseDTO(result.User, result.VerificationSent)
|
||||||
"id": result.User.ID,
|
SendCreatedResponse(w, "Registration successful. Check your email to confirm your account.", responseDTO)
|
||||||
"username": result.User.Username,
|
|
||||||
"email": result.User.Email,
|
|
||||||
"email_verified": result.User.EmailVerified,
|
|
||||||
"created_at": result.User.CreatedAt,
|
|
||||||
"updated_at": result.User.UpdatedAt,
|
|
||||||
"deleted_at": result.User.DeletedAt,
|
|
||||||
}
|
|
||||||
|
|
||||||
responseData := map[string]any{
|
|
||||||
"user": userData,
|
|
||||||
"verification_sent": result.VerificationSent,
|
|
||||||
}
|
|
||||||
|
|
||||||
SendCreatedResponse(w, "Registration successful. Check your email to confirm your account.", responseData)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Confirm email address
|
// @Summary Confirm email address
|
||||||
@@ -192,9 +178,7 @@ func (h *AuthHandler) ConfirmEmail(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userDTO := dto.ToUserDTO(user)
|
userDTO := dto.ToUserDTO(user)
|
||||||
SendSuccessResponse(w, "Email confirmed successfully", map[string]any{
|
SendSuccessResponse(w, "Email confirmed successfully", userDTO)
|
||||||
"user": userDTO,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Resend verification email
|
// @Summary Resend verification email
|
||||||
@@ -397,9 +381,7 @@ func (h *AuthHandler) UpdateEmail(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userDTO := dto.ToUserDTO(user)
|
userDTO := dto.ToUserDTO(user)
|
||||||
SendSuccessResponse(w, "Email updated. Check your inbox to confirm the new address.", map[string]any{
|
SendSuccessResponse(w, "Email updated. Check your inbox to confirm the new address.", userDTO)
|
||||||
"user": userDTO,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Update username
|
// @Summary Update username
|
||||||
@@ -445,9 +427,7 @@ func (h *AuthHandler) UpdateUsername(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userDTO := dto.ToUserDTO(user)
|
userDTO := dto.ToUserDTO(user)
|
||||||
SendSuccessResponse(w, "Username updated successfully.", map[string]any{
|
SendSuccessResponse(w, "Username updated successfully.", userDTO)
|
||||||
"user": userDTO,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Update password
|
// @Summary Update password
|
||||||
@@ -498,9 +478,7 @@ func (h *AuthHandler) UpdatePassword(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userDTO := dto.ToUserDTO(user)
|
userDTO := dto.ToUserDTO(user)
|
||||||
SendSuccessResponse(w, "Password updated successfully.", map[string]any{
|
SendSuccessResponse(w, "Password updated successfully.", userDTO)
|
||||||
"user": userDTO,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Request account deletion
|
// @Summary Request account deletion
|
||||||
@@ -565,18 +543,20 @@ func (h *AuthHandler) ConfirmAccountDeletion(w http.ResponseWriter, r *http.Requ
|
|||||||
case errors.Is(err, services.ErrEmailSenderUnavailable):
|
case errors.Is(err, services.ErrEmailSenderUnavailable):
|
||||||
SendErrorResponse(w, "Account deletion isn't available right now because email delivery is disabled.", http.StatusServiceUnavailable)
|
SendErrorResponse(w, "Account deletion isn't available right now because email delivery is disabled.", http.StatusServiceUnavailable)
|
||||||
case errors.Is(err, services.ErrDeletionEmailFailed):
|
case errors.Is(err, services.ErrDeletionEmailFailed):
|
||||||
SendSuccessResponse(w, "Your account has been deleted, but we couldn't send the confirmation email.", map[string]any{
|
responseDTO := dto.AccountDeletionResponseDTO{
|
||||||
"posts_deleted": req.DeletePosts,
|
PostsDeleted: req.DeletePosts,
|
||||||
})
|
}
|
||||||
|
SendSuccessResponse(w, "Your account has been deleted, but we couldn't send the confirmation email.", responseDTO)
|
||||||
default:
|
default:
|
||||||
SendErrorResponse(w, "We couldn't confirm the deletion right now.", http.StatusInternalServerError)
|
SendErrorResponse(w, "We couldn't confirm the deletion right now.", http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
SendSuccessResponse(w, "Your account has been deleted.", map[string]any{
|
responseDTO := dto.AccountDeletionResponseDTO{
|
||||||
"posts_deleted": req.DeletePosts,
|
PostsDeleted: req.DeletePosts,
|
||||||
})
|
}
|
||||||
|
SendSuccessResponse(w, "Your account has been deleted.", responseDTO)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Logout user
|
// @Summary Logout user
|
||||||
|
|||||||
Reference in New Issue
Block a user