switch to pgx driver + create merch
This commit is contained in:
parent
546fe13107
commit
97f8d27430
13 changed files with 289 additions and 69 deletions
|
|
@ -1,7 +1,7 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"merch-api/pkg/utils"
|
||||
)
|
||||
|
||||
|
|
@ -10,7 +10,7 @@ type Handler struct {
|
|||
}
|
||||
|
||||
type Deps struct {
|
||||
DB *sql.DB
|
||||
DB *pgxpool.Pool
|
||||
Utils utils.Utils
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package user
|
||||
|
||||
import "context"
|
||||
|
||||
type Provider interface {
|
||||
GetUserId(userUuid string) (string, error)
|
||||
GetUserId(ctx context.Context, userUuid string) (string, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,27 @@
|
|||
package user
|
||||
|
||||
import "database/sql"
|
||||
import (
|
||||
"context"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
getUserId(userUuid string) (string, error)
|
||||
getUserId(ctx context.Context, userUuid string) (string, error)
|
||||
}
|
||||
|
||||
type repo struct {
|
||||
db *sql.DB
|
||||
db *pgxpool.Pool
|
||||
}
|
||||
|
||||
func newRepository(db *sql.DB) Repository {
|
||||
func newRepository(db *pgxpool.Pool) Repository {
|
||||
return &repo{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *repo) getUserId(userUuid string) (string, error) {
|
||||
func (r *repo) getUserId(ctx context.Context, userUuid string) (string, error) {
|
||||
q := `SELECT id FROM users WHERE uuid = $1 AND deleted_at IS NULL LIMIT 1`
|
||||
row := r.db.QueryRow(q, userUuid)
|
||||
row := r.db.QueryRow(ctx, q, userUuid)
|
||||
|
||||
var id string
|
||||
if err := row.Scan(&id); err != nil {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"merch-api/pkg/utils"
|
||||
)
|
||||
|
|
@ -17,10 +18,10 @@ func newService(repo Repository, utils utils.Utils) *service {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *service) GetUserId(userUuid string) (string, error) {
|
||||
func (s *service) GetUserId(ctx context.Context, userUuid string) (string, error) {
|
||||
if userUuid == "" {
|
||||
return "", errors.New("user uuid is empty")
|
||||
}
|
||||
|
||||
return s.repo.getUserId(userUuid)
|
||||
return s.repo.getUserId(ctx, userUuid)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue