add places operations

This commit is contained in:
2026-07-14 01:25:57 +07:00
parent 2b11c49b3c
commit 7a657926f1
12 changed files with 502 additions and 175 deletions
+50
View File
@@ -204,3 +204,53 @@ func (s *ScenariosRepo) DeleteScenarioByID(
}
return nil
}
func (s *ScenariosRepo) GetStoryByScenarioID(
ctx context.Context,
id int,
) (string, error) {
story := ""
row := s.pool.QueryRow(
ctx,
`SELECT
scenario
FROM scenarios
WHERE scenarios.id = $1`,
id,
)
err := row.Scan(
&story,
)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return "", ErrScenarioNotFound
}
return "", err
}
return story, nil
}
func (s *ScenariosRepo) UpdateStoryByScenarioID(
ctx context.Context,
id int,
story string,
) error {
tag, err := s.pool.Exec(
ctx,
`UPDATE scenarios
SET
scenario = $1,
updated_at = NOW()
WHERE id = $2`,
story,
id,
)
if err != nil {
return err
}
if tag.RowsAffected() == 0 {
return ErrScenarioNotFound
}
return nil
}