fix(postgres): map drivers
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -38,7 +38,7 @@ func (r *UserRepo) Create(ctx context.Context, user *domain.User) error {
|
||||
Message: "нарушено ограничение целостности",
|
||||
}
|
||||
}
|
||||
return err
|
||||
return mapError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user