merch-api/internal/user/repository.go

33 lines
580 B
Go
Raw Normal View History

2026-03-02 17:29:43 +03:00
package user
2026-03-04 17:02:11 +03:00
import (
"context"
"github.com/jackc/pgx/v5/pgxpool"
)
2026-03-02 17:29:43 +03:00
type Repository interface {
2026-03-04 17:02:11 +03:00
getUserId(ctx context.Context, userUuid string) (string, error)
2026-03-02 17:29:43 +03:00
}
type repo struct {
2026-03-04 17:02:11 +03:00
db *pgxpool.Pool
2026-03-02 17:29:43 +03:00
}
2026-03-04 17:02:11 +03:00
func newRepository(db *pgxpool.Pool) Repository {
2026-03-02 17:29:43 +03:00
return &repo{
db: db,
}
}
2026-03-04 17:02:11 +03:00
func (r *repo) getUserId(ctx context.Context, userUuid string) (string, error) {
2026-03-02 17:29:43 +03:00
q := `SELECT id FROM users WHERE uuid = $1 AND deleted_at IS NULL LIMIT 1`
2026-03-04 17:02:11 +03:00
row := r.db.QueryRow(ctx, q, userUuid)
2026-03-02 17:29:43 +03:00
var id string
if err := row.Scan(&id); err != nil {
return "", err
}
return id, nil
}