generated from VLADIMIR/template
up
This commit is contained in:
@@ -128,6 +128,30 @@ func (r *Repo) ScenarioRating(ctx context.Context, scenarioID int) (float64, int
|
||||
return average, int32(count), err
|
||||
}
|
||||
|
||||
func (r *Repo) ListByScenario(ctx context.Context, scenarioID int) ([]*Review, float64, int32, error) {
|
||||
rows, err := r.pool.Query(ctx, `SELECT r.id,r.game_id,r.team_id,t.name,g.name,r.rating,r.text,r.status,r.created_at
|
||||
FROM game_reviews r JOIN teams t ON t.id=r.team_id JOIN games g ON g.id=r.game_id
|
||||
WHERE g.scenario_id=$1 AND g.status='finish' AND r.status='approved'
|
||||
ORDER BY r.created_at DESC`, scenarioID)
|
||||
if err != nil {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var reviews []*Review
|
||||
for rows.Next() {
|
||||
review := &Review{}
|
||||
if err := rows.Scan(&review.ID, &review.GameID, &review.TeamID, &review.TeamName, &review.GameName, &review.Rating, &review.Text, &review.Status, &review.CreatedAt); err != nil {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
reviews = append(reviews, review)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
average, count, err := r.ScenarioRating(ctx, scenarioID)
|
||||
return reviews, average, count, err
|
||||
}
|
||||
|
||||
func (r *Repo) queryOne(ctx context.Context, condition string, id int) (*Review, error) {
|
||||
review := &Review{}
|
||||
err := r.pool.QueryRow(ctx, `SELECT r.id,r.game_id,r.team_id,t.name,g.name,r.rating,r.text,r.status,r.created_at
|
||||
|
||||
Reference in New Issue
Block a user