32 lines
576 B
Go
32 lines
576 B
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
)
|
|
|
|
type Repository interface {
|
|
getUserId(ctx context.Context, userUuid string) (int64, error)
|
|
}
|
|
|
|
type repo struct {
|
|
db *pgxpool.Pool
|
|
}
|
|
|
|
func newRepository(db *pgxpool.Pool) Repository {
|
|
return &repo{
|
|
db: db,
|
|
}
|
|
}
|
|
|
|
func (r *repo) getUserId(ctx context.Context, userUuid string) (int64, error) {
|
|
q := `SELECT id FROM users WHERE uuid = $1 AND deleted_at IS NULL LIMIT 1`
|
|
row := r.db.QueryRow(ctx, q, userUuid)
|
|
|
|
var id int64
|
|
if err := row.Scan(&id); err != nil {
|
|
return 0, err
|
|
}
|
|
|
|
return id, nil
|
|
}
|