generated from VLADIMIR/template
add places operations
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user