From 537ec40c8a2ff060d8858f9298fcf5be446c589c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=93=D0=BE=D0=BB=D0=B8=D0=BA=D0=BE=D0=B2=20Maximillian?= =?UTF-8?q?=20=D0=90=D0=BD=D1=82=D0=BE=D0=BD?= Date: Fri, 2 Oct 2026 09:12:21 +0300 Subject: [PATCH] fix(postgres): map drivers --- backend/internal/storage/postgres/chat.go | 20 ++++++++++---------- backend/internal/storage/postgres/session.go | 4 ++-- backend/internal/storage/postgres/user.go | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/backend/internal/storage/postgres/chat.go b/backend/internal/storage/postgres/chat.go index 1c430d0e..8afc6f29 100644 --- a/backend/internal/storage/postgres/chat.go +++ b/backend/internal/storage/postgres/chat.go @@ -22,7 +22,7 @@ func NewChatRepo(pool *pgxpool.Pool) *ChatRepo { func (r *ChatRepo) Create(ctx context.Context, chat *domain.Chat) error { tx, err := r.pool.Begin(ctx) if err != nil { - return err + return mapError(err) } defer func() { _ = tx.Rollback(ctx) }() @@ -31,7 +31,7 @@ func (r *ChatRepo) Create(ctx context.Context, chat *domain.Chat) error { if checkViolation(err) { return &domain.ValidationError{Field: "chat", Message: "нарушено ограничение целостности"} } - return err + return mapError(err) } const qMember = `INSERT INTO chat_members (chat_id, user_id) VALUES ($1::uuid, $2::uuid)` @@ -49,11 +49,11 @@ func (r *ChatRepo) Create(ctx context.Context, chat *domain.Chat) error { Message: "дубликаты запрещены", } } - return err + return mapError(err) } } - return tx.Commit(ctx) + return mapError(tx.Commit(ctx)) } func (r *ChatRepo) GetByID(ctx context.Context, id string) (*domain.Chat, error) { @@ -119,7 +119,7 @@ func (r *ChatRepo) ListByMember(ctx context.Context, userID string, limit int, c rows, err = r.pool.Query(ctx, q, userID, limit+1) } if err != nil { - return nil, nil, err + return nil, nil, mapError(err) } defer rows.Close() @@ -127,12 +127,12 @@ func (r *ChatRepo) ListByMember(ctx context.Context, userID string, limit int, c for rows.Next() { var c domain.Chat if err := rows.Scan(&c.ID, &c.Title, &c.CreatedAt); err != nil { - return nil, nil, err + return nil, nil, mapError(err) } page = append(page, c) } if err := rows.Err(); err != nil { - return nil, nil, err + return nil, nil, mapError(err) } var next *string @@ -177,7 +177,7 @@ func (r *ChatRepo) loadMembers(ctx context.Context, chatIDs []string) (map[strin ` rows, err := r.pool.Query(ctx, q, chatIDs) if err != nil { - return nil, err + return nil, mapError(err) } defer rows.Close() @@ -185,11 +185,11 @@ func (r *ChatRepo) loadMembers(ctx context.Context, chatIDs []string) (map[strin for rows.Next() { var chatID, userID string if err := rows.Scan(&chatID, &userID); err != nil { - return nil, err + return nil, mapError(err) } result[chatID] = append(result[chatID], userID) } - return result, rows.Err() + return result, mapError(rows.Err()) } var _ domain.ChatRepository = (*ChatRepo)(nil) diff --git a/backend/internal/storage/postgres/session.go b/backend/internal/storage/postgres/session.go index fa983aa0..430a9e6f 100644 --- a/backend/internal/storage/postgres/session.go +++ b/backend/internal/storage/postgres/session.go @@ -30,7 +30,7 @@ func (r *SessionRepo) Create(ctx context.Context, s *domain.Session) error { Value: "", } } - return err + return mapError(err) } return nil } @@ -53,7 +53,7 @@ func (r *SessionRepo) GetByTokenHash(ctx context.Context, tokenHash []byte) (*do func (r *SessionRepo) DeleteByTokenHash(ctx context.Context, tokenHash []byte) error { const q = `DELETE FROM sessions WHERE token_hash = $1` _, err := r.pool.Exec(ctx, q, tokenHash) - return err + return mapError(err) } var _ domain.SessionRepository = (*SessionRepo)(nil) diff --git a/backend/internal/storage/postgres/user.go b/backend/internal/storage/postgres/user.go index 804b9552..418f35a6 100644 --- a/backend/internal/storage/postgres/user.go +++ b/backend/internal/storage/postgres/user.go @@ -38,7 +38,7 @@ func (r *UserRepo) Create(ctx context.Context, user *domain.User) error { Message: "нарушено ограничение целостности", } } - return err + return mapError(err) } return nil }