From 778a2da4ef2cf333740d5419772e6d26bfbe48dd Mon Sep 17 00:00:00 2001 From: ga Date: Thu, 20 Aug 2026 16:29:02 +0000 Subject: [PATCH] Sprint 5.1: JSON snake_case tags + lowercased fields - All response types now use lowercase json tags (id, name, photo_url, etc.) - email/phone/birthdate/last_seen_at/photo_url use omitempty - audit.Metadata type []byte (was map[string]any) - fixes register/login inconsistency where login returned ID/Name (CamelCase) while register returned id/name (lowercase) --- internal/audit/repo.go | 18 +++++++-------- internal/chat/repo.go | 44 ++++++++++++++++++------------------ internal/locations/repo.go | 10 ++++---- internal/preferences/repo.go | 12 +++++----- internal/reviews/repo.go | 26 ++++++++++----------- internal/users/repo.go | 28 +++++++++++------------ 6 files changed, 69 insertions(+), 69 deletions(-) diff --git a/internal/audit/repo.go b/internal/audit/repo.go index 4e62bf9..cd31acf 100644 --- a/internal/audit/repo.go +++ b/internal/audit/repo.go @@ -9,15 +9,15 @@ import ( ) type Event struct { - ID int64 - UserID *uuid.UUID - Action string - TargetType string - TargetID string - Metadata map[string]any - IP string - UserAgent string - CreatedAt time.Time + ID int64 `json:"id"` + UserID *uuid.UUID `json:"user_id,omitempty"` + Action string `json:"action"` + TargetType string `json:"target_type,omitempty"` + TargetID string `json:"target_id,omitempty"` + Metadata []byte `json:"metadata,omitempty"` + IP string `json:"ip,omitempty"` + UserAgent string `json:"user_agent,omitempty"` + CreatedAt time.Time `json:"created_at"` } type Repo struct { diff --git a/internal/chat/repo.go b/internal/chat/repo.go index a35a313..4b6a297 100644 --- a/internal/chat/repo.go +++ b/internal/chat/repo.go @@ -11,24 +11,24 @@ import ( ) type Chat struct { - ID uuid.UUID - UserA uuid.UUID - UserB uuid.UUID - CreatedAt time.Time - LastMsgAt time.Time + ID uuid.UUID `json:"id"` + UserA uuid.UUID `json:"user_a"` + UserB uuid.UUID `json:"user_b"` + CreatedAt time.Time `json:"created_at"` + LastMsgAt time.Time `json:"last_msg_at"` } type Message struct { - ID uuid.UUID - ChatID uuid.UUID - SenderID uuid.UUID - Body string - PhotoURL string - Read bool - Edited bool - Deleted bool - CreatedAt time.Time - UpdatedAt time.Time + ID uuid.UUID `json:"id"` + ChatID uuid.UUID `json:"chat_id"` + SenderID uuid.UUID `json:"sender_id"` + Body string `json:"body"` + PhotoURL string `json:"photo_url,omitempty"` + Read bool `json:"read"` + Edited bool `json:"edited"` + Deleted bool `json:"deleted"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` } type Repo struct { @@ -87,13 +87,13 @@ func (r *Repo) GetByID(ctx context.Context, id uuid.UUID) (*Chat, error) { // ListChats — список чатов пользователя с инфой по последнему сообщению type ChatListItem struct { - Chat Chat - OtherID uuid.UUID - OtherName string - OtherPhoto string - LastMessage string - LastMsgAt time.Time - UnreadCount int + Chat Chat `json:"chat"` + OtherID uuid.UUID `json:"other_id"` + OtherName string `json:"other_name"` + OtherPhoto string `json:"other_photo,omitempty"` + LastMessage string `json:"last_message"` + LastMsgAt time.Time `json:"last_msg_at"` + UnreadCount int `json:"unread_count"` } func (r *Repo) ListChats(ctx context.Context, me uuid.UUID, limit, offset int) ([]ChatListItem, error) { diff --git a/internal/locations/repo.go b/internal/locations/repo.go index 7f13a0a..7820e8c 100644 --- a/internal/locations/repo.go +++ b/internal/locations/repo.go @@ -11,11 +11,11 @@ import ( ) type Location struct { - UserID uuid.UUID - Lat float64 - Lng float64 - Visible bool - UpdatedAt time.Time + UserID uuid.UUID `json:"user_id"` + Lat float64 `json:"lat"` + Lng float64 `json:"lng"` + Visible bool `json:"visible"` + UpdatedAt time.Time `json:"updated_at"` } type Repo struct { diff --git a/internal/preferences/repo.go b/internal/preferences/repo.go index 3004513..9219d7b 100644 --- a/internal/preferences/repo.go +++ b/internal/preferences/repo.go @@ -27,12 +27,12 @@ var AllowedPurposes = map[string]bool{ } type Prefs struct { - UserID uuid.UUID - Drinks []string - Activities []string - Purposes []string - Language string - UpdatedAt time.Time + UserID uuid.UUID `json:"user_id"` + Drinks []string `json:"drinks"` + Activities []string `json:"activities"` + Purposes []string `json:"purposes"` + Language string `json:"language"` + UpdatedAt time.Time `json:"updated_at"` } type Repo struct { diff --git a/internal/reviews/repo.go b/internal/reviews/repo.go index 9f5b054..fbe0900 100644 --- a/internal/reviews/repo.go +++ b/internal/reviews/repo.go @@ -11,22 +11,22 @@ import ( ) type Review struct { - ID uuid.UUID - ReviewerID uuid.UUID - ReviewedID uuid.UUID - ChatID uuid.UUID - Rating int - Body string - Anonymous bool - CreatedAt time.Time + ID uuid.UUID `json:"id"` + ReviewerID uuid.UUID `json:"reviewer_id"` + ReviewedID uuid.UUID `json:"reviewed_id"` + ChatID uuid.UUID `json:"chat_id"` + Rating int `json:"rating"` + Body string `json:"body"` + Anonymous bool `json:"anonymous"` + CreatedAt time.Time `json:"created_at"` } type Stats struct { - UserID uuid.UUID - RatingAvg float64 - RatingCount int - ReviewsLeft int - LastActiveAt *time.Time + UserID uuid.UUID `json:"user_id"` + RatingAvg float64 `json:"rating_avg"` + RatingCount int `json:"rating_count"` + ReviewsLeft int `json:"reviews_left"` + LastActiveAt *time.Time `json:"last_active_at,omitempty"` } type Repo struct { diff --git a/internal/users/repo.go b/internal/users/repo.go index d7fc5b2..172c0db 100644 --- a/internal/users/repo.go +++ b/internal/users/repo.go @@ -11,20 +11,20 @@ import ( ) type User struct { - ID uuid.UUID - Email string - Phone string - Name string - Birthdate *time.Time - Gender string - City string - Bio string - PhotoURL string - IsVerified bool - IsBlocked bool - CreatedAt time.Time - UpdatedAt time.Time - LastSeenAt *time.Time + ID uuid.UUID `json:"id"` + Email string `json:"email,omitempty"` + Phone string `json:"phone,omitempty"` + Name string `json:"name"` + Birthdate *time.Time `json:"birthdate,omitempty"` + Gender string `json:"gender"` + City string `json:"city"` + Bio string `json:"bio"` + PhotoURL string `json:"photo_url,omitempty"` + IsVerified bool `json:"is_verified"` + IsBlocked bool `json:"is_blocked"` + CreatedAt time.Time `json:"created_at"` + UpdatedAt time.Time `json:"updated_at"` + LastSeenAt *time.Time `json:"last_seen_at,omitempty"` } type Repo struct {