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 {
|
func (r *ChatRepo) Create(ctx context.Context, chat *domain.Chat) error {
|
||||||
tx, err := r.pool.Begin(ctx)
|
tx, err := r.pool.Begin(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return mapError(err)
|
||||||
}
|
}
|
||||||
defer func() { _ = tx.Rollback(ctx) }()
|
defer func() { _ = tx.Rollback(ctx) }()
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ func (r *ChatRepo) Create(ctx context.Context, chat *domain.Chat) error {
|
|||||||
if checkViolation(err) {
|
if checkViolation(err) {
|
||||||
return &domain.ValidationError{Field: "chat", Message: "нарушено ограничение целостности"}
|
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)`
|
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: "дубликаты запрещены",
|
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) {
|
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)
|
rows, err = r.pool.Query(ctx, q, userID, limit+1)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, mapError(err)
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
@@ -127,12 +127,12 @@ func (r *ChatRepo) ListByMember(ctx context.Context, userID string, limit int, c
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var c domain.Chat
|
var c domain.Chat
|
||||||
if err := rows.Scan(&c.ID, &c.Title, &c.CreatedAt); err != nil {
|
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)
|
page = append(page, c)
|
||||||
}
|
}
|
||||||
if err := rows.Err(); err != nil {
|
if err := rows.Err(); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, mapError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var next *string
|
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)
|
rows, err := r.pool.Query(ctx, q, chatIDs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, mapError(err)
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
@@ -185,11 +185,11 @@ func (r *ChatRepo) loadMembers(ctx context.Context, chatIDs []string) (map[strin
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var chatID, userID string
|
var chatID, userID string
|
||||||
if err := rows.Scan(&chatID, &userID); err != nil {
|
if err := rows.Scan(&chatID, &userID); err != nil {
|
||||||
return nil, err
|
return nil, mapError(err)
|
||||||
}
|
}
|
||||||
result[chatID] = append(result[chatID], userID)
|
result[chatID] = append(result[chatID], userID)
|
||||||
}
|
}
|
||||||
return result, rows.Err()
|
return result, mapError(rows.Err())
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ domain.ChatRepository = (*ChatRepo)(nil)
|
var _ domain.ChatRepository = (*ChatRepo)(nil)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ func (r *SessionRepo) Create(ctx context.Context, s *domain.Session) error {
|
|||||||
Value: "",
|
Value: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return mapError(err)
|
||||||
}
|
}
|
||||||
return nil
|
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 {
|
func (r *SessionRepo) DeleteByTokenHash(ctx context.Context, tokenHash []byte) error {
|
||||||
const q = `DELETE FROM sessions WHERE token_hash = $1`
|
const q = `DELETE FROM sessions WHERE token_hash = $1`
|
||||||
_, err := r.pool.Exec(ctx, q, tokenHash)
|
_, err := r.pool.Exec(ctx, q, tokenHash)
|
||||||
return err
|
return mapError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ domain.SessionRepository = (*SessionRepo)(nil)
|
var _ domain.SessionRepository = (*SessionRepo)(nil)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func (r *UserRepo) Create(ctx context.Context, user *domain.User) error {
|
|||||||
Message: "нарушено ограничение целостности",
|
Message: "нарушено ограничение целостности",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return mapError(err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user