add AnswerService

This commit is contained in:
2026-09-17 02:38:05 +07:00
parent c70d839038
commit 87bd07019a
18 changed files with 448 additions and 304 deletions
+7 -7
View File
@@ -1,11 +1,11 @@
package app
import (
"evening_detective_server/internal/services/game_service"
"evening_detective_server/internal/services/answer_service"
proto "evening_detective_server/proto"
)
func mapAnswers(o []game_service.Answer) []*proto.Answer {
func mapAnswers(o []answer_service.Answer) []*proto.Answer {
res := make([]*proto.Answer, 0, len(o))
for _, item := range o {
res = append(res, &proto.Answer{
@@ -16,10 +16,10 @@ func mapAnswers(o []game_service.Answer) []*proto.Answer {
return res
}
func convertAnswers(o []*proto.Answer) []game_service.Answer {
res := make([]game_service.Answer, 0, len(o))
func convertAnswers(o []*proto.Answer) []answer_service.Answer {
res := make([]answer_service.Answer, 0, len(o))
for _, item := range o {
res = append(res, game_service.Answer{
res = append(res, answer_service.Answer{
QuestionCode: item.QuestionCode,
Text: item.Answer,
})
@@ -27,7 +27,7 @@ func convertAnswers(o []*proto.Answer) []game_service.Answer {
return res
}
func mapAnswerScores(o []game_service.AnswerScore) []*proto.AnswerScore {
func mapAnswerScores(o []answer_service.AnswerScore) []*proto.AnswerScore {
res := make([]*proto.AnswerScore, 0, len(o))
for _, item := range o {
score := &proto.AnswerScore{
@@ -43,7 +43,7 @@ func mapAnswerScores(o []game_service.AnswerScore) []*proto.AnswerScore {
return res
}
func mapTeamAnswers(o []game_service.TeamAnswers) []*proto.TeamAnswers {
func mapTeamAnswers(o []answer_service.TeamAnswers) []*proto.TeamAnswers {
res := make([]*proto.TeamAnswers, 0, len(o))
for _, item := range o {
res = append(res, &proto.TeamAnswers{
+3 -3
View File
@@ -12,7 +12,7 @@ import (
)
func (s *server) GetTeamAnswers(ctx context.Context, req *proto.GetTeamAnswersReq) (*proto.GetTeamAnswersRsp, error) {
answers, err := s.gameService.GetTeamAnswers(
answers, err := s.answerService.GetTeamAnswers(
ctx,
int(req.Id),
req.Password,
@@ -29,7 +29,7 @@ func (s *server) GetTeamAnswers(ctx context.Context, req *proto.GetTeamAnswersRe
}
func (s *server) SubmitTeamAnswers(ctx context.Context, req *proto.SubmitTeamAnswersReq) (*proto.SubmitTeamAnswersRsp, error) {
err := s.gameService.SubmitTeamAnswers(
err := s.answerService.SubmitTeamAnswers(
ctx,
int(req.Id),
req.Password,
@@ -56,7 +56,7 @@ func (s *server) SetTeamAnswerScore(ctx context.Context, req *proto.SetTeamAnswe
score = &v
}
err := s.gameService.SetTeamAnswerScore(
err := s.answerService.SetTeamAnswerScore(
ctx,
int(req.Id),
req.QuestionCode,
+2 -2
View File
@@ -83,7 +83,7 @@ func (s *server) GetGameAnswers(ctx context.Context, req *proto.GetGameAnswersRe
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
}
gameAnswers, err := s.gameService.GetGameAnswers(ctx, int(req.GameId))
gameAnswers, err := s.answerService.GetGameAnswers(ctx, int(req.GameId))
if err != nil {
return &proto.GetGameAnswersRsp{
Error: err.Error(),
@@ -102,7 +102,7 @@ func (s *server) GetGameResults(ctx context.Context, req *proto.GetGameResultsRe
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
}
results, err := s.gameService.GetGameResults(ctx, int(req.GameId))
results, err := s.answerService.GetGameResults(ctx, int(req.GameId))
if err != nil {
return &proto.GetGameResultsRsp{
Error: err.Error(),
+2 -2
View File
@@ -2,7 +2,7 @@ package app
import (
"evening_detective_server/internal/modules/storytelling"
"evening_detective_server/internal/services/game_service"
"evening_detective_server/internal/services/answer_service"
proto "evening_detective_server/proto"
)
@@ -23,7 +23,7 @@ func mapResultsQuestions(o []*storytelling.Question) []*proto.ResultsQuestion {
// mapTeamResults мапит строки итоговой таблицы. Команда мапится целиком
// (включая password/applications — аудитория та же, что у GetGameAnswers:
// организатор/автор); actionsCount продублирован на уровне строки таблицы.
func mapTeamResults(o []game_service.TeamResult) []*proto.TeamResult {
func mapTeamResults(o []answer_service.TeamResult) []*proto.TeamResult {
res := make([]*proto.TeamResult, 0, len(o))
for _, item := range o {
res = append(res, &proto.TeamResult{
+3 -3
View File
@@ -4,12 +4,12 @@ import (
"evening_detective_server/internal/modules/game_model"
"testing"
"evening_detective_server/internal/services/game_service"
"evening_detective_server/internal/services/answer_service"
)
func TestMapTeamResults(t *testing.T) {
sc := 5
results := []game_service.TeamResult{
results := []answer_service.TeamResult{
{
Team: &game_model.Team{
ID: 1,
@@ -17,7 +17,7 @@ func TestMapTeamResults(t *testing.T) {
Status: "play",
ActionsCount: 7,
},
Answers: []game_service.AnswerScore{
Answers: []answer_service.AnswerScore{
{QuestionCode: "q1", Text: "ответ", Score: &sc},
},
TotalScore: 5,
+1 -1
View File
@@ -262,7 +262,7 @@ func (s *server) GetScreenResults(ctx context.Context, req *proto.GetScreenResul
if game.Status != "finish" {
return nil, status.Error(codes.FailedPrecondition, "результаты доступны после завершения игры")
}
results, err := s.gameService.GetGameResults(ctx, *session.GameID)
results, err := s.answerService.GetGameResults(ctx, *session.GameID)
if err != nil {
return nil, status.Error(codes.Internal, "не удалось получить результаты")
}
+4
View File
@@ -4,6 +4,7 @@ import (
"evening_detective_server/internal/modules/string_tools"
"evening_detective_server/internal/repos/game_map_repo"
"evening_detective_server/internal/repos/screen_sessions_repo"
"evening_detective_server/internal/services/answer_service"
"evening_detective_server/internal/services/file_service"
"evening_detective_server/internal/services/game_service"
"evening_detective_server/internal/services/participation_service"
@@ -25,6 +26,7 @@ type server struct {
fileService *file_service.FileService
scenarioService *scenarios_service.ScenarioService
gameService *game_service.GameService
answerService *answer_service.AnswerService
teamService *team_service.TeamService
participationService *participation_service.ParticipationService
screenRepo *screen_sessions_repo.ScreenSessionsRepo
@@ -37,6 +39,7 @@ func NewServer(
fileService *file_service.FileService,
scenarioService *scenarios_service.ScenarioService,
gameService *game_service.GameService,
answerService *answer_service.AnswerService,
teamService *team_service.TeamService,
participationService *participation_service.ParticipationService,
screenRepo *screen_sessions_repo.ScreenSessionsRepo,
@@ -48,6 +51,7 @@ func NewServer(
fileService: fileService,
scenarioService: scenarioService,
gameService: gameService,
answerService: answerService,
teamService: teamService,
participationService: participationService,
screenRepo: screenRepo,