generated from VLADIMIR/template
add mcp label
This commit is contained in:
@@ -1098,7 +1098,7 @@ func (s *server) GiveTeamApplications(ctx context.Context, req *proto.GiveTeamAp
|
||||
}
|
||||
|
||||
func (s *server) GetTeamStory(ctx context.Context, req *proto.GetTeamStoryReq) (*proto.GetTeamStoryRsp, error) {
|
||||
story, game, err := s.gameService.GetTeamActions(
|
||||
story, game, actions, err := s.gameService.GetTeamActions(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
req.Password,
|
||||
@@ -1108,10 +1108,15 @@ func (s *server) GetTeamStory(ctx context.Context, req *proto.GetTeamStoryReq) (
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
protoActions := make([]*proto.TeamAction, 0, len(actions))
|
||||
for _, action := range actions {
|
||||
protoActions = append(protoActions, &proto.TeamAction{Code: action.Code, Mcp: action.ViaMCP})
|
||||
}
|
||||
|
||||
return &proto.GetTeamStoryRsp{
|
||||
Story: mapStory(story),
|
||||
Game: mapGame(game),
|
||||
Story: mapStory(story),
|
||||
Game: mapGame(game),
|
||||
Actions: protoActions,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,11 @@ type ActionsRepo struct {
|
||||
pool *pgxpool.Pool
|
||||
}
|
||||
|
||||
type Action struct {
|
||||
Code string
|
||||
ViaMCP bool
|
||||
}
|
||||
|
||||
func NewActionsRepo(pool *pgxpool.Pool) *ActionsRepo {
|
||||
return &ActionsRepo{
|
||||
pool: pool,
|
||||
@@ -39,11 +44,12 @@ func (r *ActionsRepo) AddAction(ctx context.Context, teamId int, code string, vi
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (r *ActionsRepo) GetActionsByTeamID(ctx context.Context, teamId int) ([]string, error) {
|
||||
func (r *ActionsRepo) GetActionsByTeamID(ctx context.Context, teamId int) ([]Action, error) {
|
||||
rows, err := r.pool.Query(
|
||||
ctx,
|
||||
`SELECT
|
||||
code
|
||||
code,
|
||||
via_mcp
|
||||
FROM actions
|
||||
WHERE team_id = $1
|
||||
ORDER BY created_at ASC`,
|
||||
@@ -54,22 +60,23 @@ func (r *ActionsRepo) GetActionsByTeamID(ctx context.Context, teamId int) ([]str
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var codes []string
|
||||
var actions []Action
|
||||
for rows.Next() {
|
||||
code := ""
|
||||
action := Action{}
|
||||
err := rows.Scan(
|
||||
&code,
|
||||
&action.Code,
|
||||
&action.ViaMCP,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
codes = append(codes, code)
|
||||
actions = append(actions, action)
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return codes, nil
|
||||
return actions, nil
|
||||
}
|
||||
|
||||
func (r *ActionsRepo) GetActionsCountByTeamIDs(ctx context.Context, teamIds []int) (map[int]int, error) {
|
||||
|
||||
@@ -206,32 +206,36 @@ func (s *GameService) GiveTeamApplications(ctx context.Context, teamId int, name
|
||||
return s.applicationsRepo.UpdateApplicationStatus(ctx, teamId, name, "done")
|
||||
}
|
||||
|
||||
func (s *GameService) GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, *Game, error) {
|
||||
func (s *GameService) GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, *Game, []actions_repo.Action, error) {
|
||||
team, err := s.teamsRepo.GetTeamByID(ctx, teamId)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
if team.Password != password {
|
||||
return nil, nil, teams_repo.ErrTeamNotFound
|
||||
return nil, nil, nil, teams_repo.ErrTeamNotFound
|
||||
}
|
||||
|
||||
game, err := s.gamesRepo.GetGameByID(ctx, team.GameId)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, game.ScenarioId)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
return s.storyteller.GetStory(scenario.Story, actions), mapGame(game, s.domain), nil
|
||||
codes := make([]string, len(actions))
|
||||
for i, action := range actions {
|
||||
codes[i] = action.Code
|
||||
}
|
||||
return s.storyteller.GetStory(scenario.Story, codes), mapGame(game, s.domain), actions, nil
|
||||
}
|
||||
|
||||
func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password string, actionCode string, viaMCP bool) error {
|
||||
@@ -254,7 +258,7 @@ func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password st
|
||||
return err
|
||||
}
|
||||
|
||||
actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
|
||||
actionDetails, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -264,6 +268,10 @@ func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password st
|
||||
return err
|
||||
}
|
||||
|
||||
actions := make([]string, len(actionDetails))
|
||||
for i, action := range actionDetails {
|
||||
actions[i] = action.Code
|
||||
}
|
||||
teamStory := s.storyteller.GetStory(scenario.Story, actions)
|
||||
|
||||
lastPlace := teamStory.Places[len(teamStory.Places)-1]
|
||||
@@ -290,7 +298,7 @@ func (s *GameService) DeleteLastTeamAction(ctx context.Context, teamId int) erro
|
||||
return err
|
||||
}
|
||||
|
||||
actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
|
||||
actionDetails, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -300,6 +308,10 @@ func (s *GameService) DeleteLastTeamAction(ctx context.Context, teamId int) erro
|
||||
return err
|
||||
}
|
||||
|
||||
actions := make([]string, len(actionDetails))
|
||||
for i, action := range actionDetails {
|
||||
actions[i] = action.Code
|
||||
}
|
||||
teamStory := s.storyteller.GetStory(scenario.Story, actions)
|
||||
|
||||
lastPlace := teamStory.Places[len(teamStory.Places)-1]
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"time"
|
||||
|
||||
"evening_detective_server/internal/modules/storytelling"
|
||||
"evening_detective_server/internal/repos/actions_repo"
|
||||
"evening_detective_server/internal/services/game_service"
|
||||
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
@@ -29,7 +30,7 @@ const defaultCallTimeout = 10 * time.Second
|
||||
// *game_service.GameService; интерфейс позволяет тестировать сервис
|
||||
// без БД.
|
||||
type GamePlayer interface {
|
||||
GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, *game_service.Game, error)
|
||||
GetTeamActions(ctx context.Context, teamId int, password string) (*storytelling.Story, *game_service.Game, []actions_repo.Action, error)
|
||||
AddTeamAction(ctx context.Context, teamId int, password, actionCode string, viaMCP bool) error
|
||||
SubmitTeamAnswers(ctx context.Context, teamId int, password string, answers []game_service.Answer) error
|
||||
}
|
||||
@@ -203,7 +204,7 @@ func (s *MCPService) handleConnect(ctx context.Context, req mcp.CallToolRequest)
|
||||
ctx, cancel := context.WithTimeout(ctx, defaultCallTimeout)
|
||||
defer cancel()
|
||||
|
||||
story, game, err := s.game.GetTeamActions(ctx, int(args.teamID), args.password)
|
||||
story, game, _, err := s.game.GetTeamActions(ctx, int(args.teamID), args.password)
|
||||
if err != nil {
|
||||
return mcp.NewToolResultError(fmt.Sprintf("connect: %v", err)), nil
|
||||
}
|
||||
@@ -234,7 +235,7 @@ func (s *MCPService) handleGetTeamStory(ctx context.Context, req mcp.CallToolReq
|
||||
ctx, cancel := context.WithTimeout(ctx, defaultCallTimeout)
|
||||
defer cancel()
|
||||
|
||||
story, game, err := s.game.GetTeamActions(ctx, int(teamID), password)
|
||||
story, game, _, err := s.game.GetTeamActions(ctx, int(teamID), password)
|
||||
if err != nil {
|
||||
return mcp.NewToolResultError(fmt.Sprintf("get_team_story: %v", err)), nil
|
||||
}
|
||||
@@ -265,7 +266,7 @@ func (s *MCPService) handleMakeMove(ctx context.Context, req mcp.CallToolRequest
|
||||
return mcp.NewToolResultError(fmt.Sprintf("make_move: %v", err)), nil
|
||||
}
|
||||
|
||||
story, game, err := s.game.GetTeamActions(ctx, int(teamID), password)
|
||||
story, game, _, err := s.game.GetTeamActions(ctx, int(teamID), password)
|
||||
if err != nil {
|
||||
return mcp.NewToolResultError(fmt.Sprintf("make_move: %v", err)), nil
|
||||
}
|
||||
@@ -337,7 +338,7 @@ func (s *MCPService) handleSubmitAnswers(ctx context.Context, req mcp.CallToolRe
|
||||
return mcp.NewToolResultError(fmt.Sprintf("submit_answers: %v", err)), nil
|
||||
}
|
||||
|
||||
story, game, err := s.game.GetTeamActions(ctx, int(args.teamID), args.password)
|
||||
story, game, _, err := s.game.GetTeamActions(ctx, int(args.teamID), args.password)
|
||||
if err != nil {
|
||||
return mcp.NewToolResultError(fmt.Sprintf("submit_answers: %v", err)), nil
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"time"
|
||||
|
||||
"evening_detective_server/internal/modules/storytelling"
|
||||
"evening_detective_server/internal/repos/actions_repo"
|
||||
"evening_detective_server/internal/services/game_service"
|
||||
|
||||
"github.com/mark3labs/mcp-go/client"
|
||||
@@ -23,11 +24,11 @@ type fakeGamePlayer struct {
|
||||
viaMCP bool
|
||||
}
|
||||
|
||||
func (f *fakeGamePlayer) GetTeamActions(_ context.Context, teamID int, password string) (*storytelling.Story, *game_service.Game, error) {
|
||||
func (f *fakeGamePlayer) GetTeamActions(_ context.Context, teamID int, password string) (*storytelling.Story, *game_service.Game, []actions_repo.Action, error) {
|
||||
if f.err != nil {
|
||||
return nil, nil, f.err
|
||||
return nil, nil, nil, f.err
|
||||
}
|
||||
return f.story, f.game, nil
|
||||
return f.story, f.game, nil, nil
|
||||
}
|
||||
|
||||
func (f *fakeGamePlayer) AddTeamAction(_ context.Context, teamID int, password, code string, viaMCP bool) error {
|
||||
|
||||
Reference in New Issue
Block a user