lab2: fix review — cache consistency, readiness, timeouts, uuid validation, tuple index
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
2026-10-10 01:14:56 +03:00
parent a327909856
commit 40f260612f
21 changed files with 185 additions and 189 deletions
+5 -13
View File
@@ -24,12 +24,12 @@ func NewUserRepository(pool *pgxpool.Pool) *UserRepository {
func (r *UserRepository) Create(ctx context.Context, user *domain.User, passwordHash string) error {
const q = `
INSERT INTO users (id, username, display_name, password_hash, created_at)
VALUES ($1, $2, $3, $4, $5)
VALUES ($1::uuid, $2, $3, $4, $5)
`
_, err := r.pool.Exec(ctx, q, user.ID, user.Username, user.DisplayName, passwordHash, user.CreatedAt)
if err != nil {
var pgErr *pgconn.PgError
if errors.As(err, &pgErr) && pgErr.Code == "23505" { // unique_violation
if errors.As(err, &pgErr) && pgErr.Code == "23505" {
return repository.ErrConflict
}
return fmt.Errorf("insert user: %w", err)
@@ -38,11 +38,7 @@ func (r *UserRepository) Create(ctx context.Context, user *domain.User, password
}
func (r *UserRepository) GetByID(ctx context.Context, id string) (*domain.User, error) {
const q = `
SELECT id, username, display_name, created_at
FROM users
WHERE id = $1
`
const q = `SELECT id, username, display_name, created_at FROM users WHERE id = $1::uuid`
var u domain.User
err := r.pool.QueryRow(ctx, q, id).Scan(&u.ID, &u.Username, &u.DisplayName, &u.CreatedAt)
if err != nil {
@@ -55,11 +51,7 @@ func (r *UserRepository) GetByID(ctx context.Context, id string) (*domain.User,
}
func (r *UserRepository) GetByUsername(ctx context.Context, username string) (*domain.User, error) {
const q = `
SELECT id, username, display_name, created_at
FROM users
WHERE username = $1
`
const q = `SELECT id, username, display_name, created_at FROM users WHERE username = $1`
var u domain.User
err := r.pool.QueryRow(ctx, q, username).Scan(&u.ID, &u.Username, &u.DisplayName, &u.CreatedAt)
if err != nil {
@@ -72,7 +64,7 @@ func (r *UserRepository) GetByUsername(ctx context.Context, username string) (*d
}
func (r *UserRepository) GetPasswordHash(ctx context.Context, userID string) (string, error) {
const q = `SELECT password_hash FROM users WHERE id = $1`
const q = `SELECT password_hash FROM users WHERE id = $1::uuid`
var hash string
err := r.pool.QueryRow(ctx, q, userID).Scan(&hash)
if err != nil {