generated from VLADIMIR/template
add catalog
This commit is contained in:
@@ -103,6 +103,65 @@ func (s *ScenariosRepo) GetScenariosByAuthorID(
|
||||
return scenarios, nil
|
||||
}
|
||||
|
||||
func (s *ScenariosRepo) GetScenariosByStatus(
|
||||
ctx context.Context,
|
||||
status string,
|
||||
) ([]*repos.Scenario, error) {
|
||||
rows, err := s.pool.Query(
|
||||
ctx,
|
||||
`SELECT
|
||||
scenarios.id,
|
||||
scenarios.name,
|
||||
scenarios.description,
|
||||
scenarios.image,
|
||||
scenarios.scenario,
|
||||
users.id,
|
||||
users.username,
|
||||
scenarios.status,
|
||||
scenarios.updated_at,
|
||||
scenarios.created_at,
|
||||
scenarios.published_at
|
||||
FROM scenarios
|
||||
LEFT JOIN users on scenarios.author_id = users.id
|
||||
WHERE scenarios.status = $1 and is_deleted = FALSE
|
||||
ORDER BY created_at DESC`,
|
||||
status,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var scenarios []*repos.Scenario
|
||||
for rows.Next() {
|
||||
scenario := &repos.Scenario{
|
||||
Author: &repos.User{},
|
||||
}
|
||||
err := rows.Scan(
|
||||
&scenario.ID,
|
||||
&scenario.Name,
|
||||
&scenario.Description,
|
||||
&scenario.Image,
|
||||
&scenario.Scenario,
|
||||
&scenario.Author.ID,
|
||||
&scenario.Author.Username,
|
||||
&scenario.Status,
|
||||
&scenario.UpdatedAt,
|
||||
&scenario.CreatedAt,
|
||||
&scenario.PublishedAt,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
scenarios = append(scenarios, scenario)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return scenarios, nil
|
||||
}
|
||||
|
||||
func (s *ScenariosRepo) GetScenarioByID(
|
||||
ctx context.Context,
|
||||
id int,
|
||||
|
||||
Reference in New Issue
Block a user