This commit is contained in:
2026-09-18 03:24:01 +07:00
parent f8a4ca0f55
commit fc171dace5
9 changed files with 547 additions and 288 deletions
+8
View File
@@ -40,6 +40,14 @@ func (s *server) GetGameReviews(ctx context.Context, req *proto.GetGameReviewsRe
return &proto.GetGameReviewsRsp{AverageRating: average, ReviewsCount: count, Reviews: mapGameReviews(reviews)}, nil
}
func (s *server) GetScenarioReviews(ctx context.Context, req *proto.GetScenarioReviewsReq) (*proto.GetGameReviewsRsp, error) {
reviews, average, count, err := s.reviewService.ListByScenario(ctx, int(req.ScenarioId))
if err != nil {
return &proto.GetGameReviewsRsp{Error: err.Error()}, nil
}
return &proto.GetGameReviewsRsp{AverageRating: average, ReviewsCount: count, Reviews: mapGameReviews(reviews)}, nil
}
func (s *server) GetGameReviewsForModeration(ctx context.Context, req *proto.GetGameReviewsReq) (*proto.GetGameReviewsRsp, error) {
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
if !roles.HasRole(claims, roles.Admin) {
+24
View File
@@ -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
@@ -70,6 +70,10 @@ func (s *Service) ScenarioRating(ctx context.Context, scenarioID int) (float64,
return s.reviews.ScenarioRating(ctx, scenarioID)
}
func (s *Service) ListByScenario(ctx context.Context, scenarioID int) ([]*game_reviews_repo.Review, float64, int32, error) {
return s.reviews.ListByScenario(ctx, scenarioID)
}
func reviewReminderEmail(job *teams_repo.ReviewReminder, baseURL string) email_sender.Message {
link := strings.TrimRight(baseURL, "/") + "/team-story/" + fmt.Sprint(job.TeamID) + "?" + url.Values{"password": {job.Password}, "review": {"1"}}.Encode()
body := fmt.Sprintf("Команда «%s», поделитесь впечатлениями об игре «%s».\n\nОценка и отзыв займут пару минут: %s\n\nОтзыв можно оставить один раз от команды.", job.TeamName, job.GameName, link)