add games operations

This commit is contained in:
2026-07-26 22:38:33 +07:00
parent cf32a6114f
commit 6fc19833d3
24 changed files with 2430 additions and 96 deletions
+18 -18
View File
@@ -23,13 +23,13 @@ func NewScenariosRepo(pool *pgxpool.Pool) *ScenariosRepo {
}
}
func (s *ScenariosRepo) AddScenario(
func (r *ScenariosRepo) AddScenario(
ctx context.Context,
name string,
authorId int,
) (int, error) {
id := 0
err := s.pool.QueryRow(
err := r.pool.QueryRow(
ctx,
`INSERT INTO scenarios (name, author_id)
VALUES ($1, $2)
@@ -44,11 +44,11 @@ func (s *ScenariosRepo) AddScenario(
return id, nil
}
func (s *ScenariosRepo) GetScenariosByAuthorID(
func (r *ScenariosRepo) GetScenariosByAuthorID(
ctx context.Context,
authorId int,
) ([]*repos.Scenario, error) {
rows, err := s.pool.Query(
rows, err := r.pool.Query(
ctx,
`SELECT
scenarios.id,
@@ -103,11 +103,11 @@ func (s *ScenariosRepo) GetScenariosByAuthorID(
return scenarios, nil
}
func (s *ScenariosRepo) GetScenariosByStatus(
func (r *ScenariosRepo) GetScenariosByStatus(
ctx context.Context,
status string,
) ([]*repos.Scenario, error) {
rows, err := s.pool.Query(
rows, err := r.pool.Query(
ctx,
`SELECT
scenarios.id,
@@ -162,14 +162,14 @@ func (s *ScenariosRepo) GetScenariosByStatus(
return scenarios, nil
}
func (s *ScenariosRepo) GetScenarioByID(
func (r *ScenariosRepo) GetScenarioByID(
ctx context.Context,
id int,
) (*repos.Scenario, error) {
scenario := &repos.Scenario{
Author: &repos.User{},
}
row := s.pool.QueryRow(
row := r.pool.QueryRow(
ctx,
`SELECT
scenarios.id,
@@ -213,14 +213,14 @@ func (s *ScenariosRepo) GetScenarioByID(
return scenario, nil
}
func (s *ScenariosRepo) UpdateScenarioByID(
func (r *ScenariosRepo) UpdateScenarioByID(
ctx context.Context,
id int,
name string,
description string,
image string,
) error {
tag, err := s.pool.Exec(
tag, err := r.pool.Exec(
ctx,
`UPDATE scenarios
SET
@@ -243,12 +243,12 @@ func (s *ScenariosRepo) UpdateScenarioByID(
return nil
}
func (s *ScenariosRepo) UpdateScenarioStatusByID(
func (r *ScenariosRepo) UpdateScenarioStatusByID(
ctx context.Context,
id int,
status string,
) error {
tag, err := s.pool.Exec(
tag, err := r.pool.Exec(
ctx,
`UPDATE scenarios
SET
@@ -268,11 +268,11 @@ func (s *ScenariosRepo) UpdateScenarioStatusByID(
return nil
}
func (s *ScenariosRepo) DeleteScenarioByID(
func (r *ScenariosRepo) DeleteScenarioByID(
ctx context.Context,
id int,
) error {
tag, err := s.pool.Exec(
tag, err := r.pool.Exec(
ctx,
`UPDATE scenarios
SET
@@ -289,12 +289,12 @@ func (s *ScenariosRepo) DeleteScenarioByID(
return nil
}
func (s *ScenariosRepo) GetStoryByScenarioID(
func (r *ScenariosRepo) GetStoryByScenarioID(
ctx context.Context,
id int,
) (string, error) {
story := ""
row := s.pool.QueryRow(
row := r.pool.QueryRow(
ctx,
`SELECT
scenario
@@ -315,12 +315,12 @@ func (s *ScenariosRepo) GetStoryByScenarioID(
return story, nil
}
func (s *ScenariosRepo) UpdateStoryByScenarioID(
func (r *ScenariosRepo) UpdateStoryByScenarioID(
ctx context.Context,
id int,
story string,
) error {
tag, err := s.pool.Exec(
tag, err := r.pool.Exec(
ctx,
`UPDATE scenarios
SET