generated from VLADIMIR/template
fix
This commit is contained in:
@@ -7,8 +7,10 @@ import (
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
)
|
||||
|
||||
// ErrItemNotFound означает, что объект карты не найден.
|
||||
var ErrItemNotFound = errors.New("объект карты не найден")
|
||||
|
||||
// Item — объект на карте игры.
|
||||
type Item struct {
|
||||
GameID int
|
||||
Kind string
|
||||
@@ -18,14 +20,17 @@ type Item struct {
|
||||
Hidden bool
|
||||
}
|
||||
|
||||
// Repo работает с объектами карт в PostgreSQL.
|
||||
type Repo struct {
|
||||
pool *pgxpool.Pool
|
||||
}
|
||||
|
||||
// New создаёт repository объектов карты.
|
||||
func New(pool *pgxpool.Pool) *Repo {
|
||||
return &Repo{pool: pool}
|
||||
}
|
||||
|
||||
// Ensure добавляет объект карты, если он ещё не существует.
|
||||
func (r *Repo) Ensure(ctx context.Context, gameID int, kind string, itemID int) error {
|
||||
_, err := r.pool.Exec(ctx, `
|
||||
INSERT INTO game_map_items (game_id, kind, item_id)
|
||||
@@ -38,6 +43,7 @@ func (r *Repo) Ensure(ctx context.Context, gameID int, kind string, itemID int)
|
||||
return err
|
||||
}
|
||||
|
||||
// List возвращает объекты карты игры.
|
||||
func (r *Repo) List(ctx context.Context, gameID int) ([]Item, error) {
|
||||
rows, err := r.pool.Query(
|
||||
ctx,
|
||||
@@ -68,6 +74,7 @@ func (r *Repo) List(ctx context.Context, gameID int) ([]Item, error) {
|
||||
return items, rows.Err()
|
||||
}
|
||||
|
||||
// Update изменяет координаты и видимость объекта карты.
|
||||
func (r *Repo) Update(ctx context.Context, item Item) error {
|
||||
result, err := r.pool.Exec(
|
||||
ctx,
|
||||
@@ -95,6 +102,7 @@ func (r *Repo) Update(ctx context.Context, item Item) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Delete удаляет объект карты.
|
||||
func (r *Repo) Delete(ctx context.Context, item Item) error {
|
||||
_, err := r.pool.Exec(
|
||||
ctx,
|
||||
|
||||
Reference in New Issue
Block a user