fix: updated handlers to use new DecodeJSON generic function

This commit is contained in:
2026-08-14 16:58:52 +02:00
parent e0ab3bb51a
commit 93fd79560c
6 changed files with 20 additions and 69 deletions
-32
View File
@@ -1,11 +1,5 @@
package request
import (
"encoding/json"
"fmt"
"net/http"
)
type LoginPayload struct {
Email string `json:"email"`
Password string `json:"password"`
@@ -14,29 +8,3 @@ type LoginPayload struct {
type RefreshPayload struct {
RefreshToken string `json:"refresh_token"`
}
func DecodeLogin(r *http.Request) (LoginPayload, error) {
var payload LoginPayload
decoder := json.NewDecoder(r.Body)
decoder.DisallowUnknownFields()
if err := decoder.Decode(&payload); err != nil {
return payload, fmt.Errorf("error decoding login payload: %w", err)
}
return payload, nil
}
func DecodeRefresh(r *http.Request) (RefreshPayload, error) {
var payload RefreshPayload
decoder := json.NewDecoder(r.Body)
decoder.DisallowUnknownFields()
if err := decoder.Decode(&payload); err != nil {
return payload, fmt.Errorf("error decoding refresh payload: %w", err)
}
return payload, nil
}