generated from VLADIMIR/template
add last action delete
This commit is contained in:
@@ -451,9 +451,6 @@ service EveningDetectiveServer {
|
|||||||
delete: "/api/teams/{id}/last-actions"
|
delete: "/api/teams/{id}/last-actions"
|
||||||
};
|
};
|
||||||
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
|
option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = {
|
||||||
security: {
|
|
||||||
security_requirement: {}
|
|
||||||
}
|
|
||||||
tags : "Ходы";
|
tags : "Ходы";
|
||||||
summary: "Удалить последний ход";
|
summary: "Удалить последний ход";
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1016,11 +1016,6 @@
|
|||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
"Ходы"
|
"Ходы"
|
||||||
],
|
|
||||||
"security": [
|
|
||||||
{
|
|
||||||
"": []
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,10 +2,15 @@ package actions_repo
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
|
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrActionsNotFound = errors.New("Ход не найден")
|
||||||
|
)
|
||||||
|
|
||||||
type ActionsRepo struct {
|
type ActionsRepo struct {
|
||||||
pool *pgxpool.Pool
|
pool *pgxpool.Pool
|
||||||
}
|
}
|
||||||
@@ -101,3 +106,25 @@ func (r *ActionsRepo) GetActionsCountByTeamIDs(ctx context.Context, teamIds []in
|
|||||||
|
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *ActionsRepo) DeleteLastActionByTeamId(ctx context.Context, teamId int) error {
|
||||||
|
tag, err := r.pool.Exec(
|
||||||
|
ctx,
|
||||||
|
`DELETE FROM actions
|
||||||
|
WHERE id IN (
|
||||||
|
SELECT id
|
||||||
|
FROM actions
|
||||||
|
WHERE team_id = $1
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT 1
|
||||||
|
)`,
|
||||||
|
teamId,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if tag.RowsAffected() == 0 {
|
||||||
|
return ErrActionsNotFound
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -110,3 +110,26 @@ func (r *ApplicationsRepo) UpdateApplicationStatus(
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *ApplicationsRepo) DeleteApplicationByTeamIdAndName(ctx context.Context, teamId int, name string) error {
|
||||||
|
tag, err := r.pool.Exec(
|
||||||
|
ctx,
|
||||||
|
`DELETE FROM applications
|
||||||
|
WHERE id IN (
|
||||||
|
SELECT id
|
||||||
|
FROM applications
|
||||||
|
WHERE team_id = $1 and name = $2
|
||||||
|
ORDER BY created_at DESC
|
||||||
|
LIMIT 1
|
||||||
|
)`,
|
||||||
|
teamId,
|
||||||
|
name,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if tag.RowsAffected() == 0 {
|
||||||
|
return ErrApplicationNotFound
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -233,5 +233,30 @@ func (s *GameService) AddTeamAction(ctx context.Context, teamId int, password st
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *GameService) DeleteLastTeamAction(ctx context.Context, teamId int) error {
|
func (s *GameService) DeleteLastTeamAction(ctx context.Context, teamId int) error {
|
||||||
panic("unimplemented")
|
team, err := s.teamsRepo.GetTeamByID(ctx, teamId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
actions, err := s.actionsRepo.GetActionsByTeamID(ctx, teamId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
scenario, err := s.scenarioService.GetFullScenarioByID(ctx, team.ScenarioId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
teamStory := s.storyteller.GetStory(scenario.Story, actions)
|
||||||
|
|
||||||
|
lastPlace := teamStory.Places[len(teamStory.Places)-1]
|
||||||
|
|
||||||
|
for _, application := range lastPlace.Applications {
|
||||||
|
if err := s.applicationsRepo.DeleteApplicationByTeamIdAndName(ctx, teamId, application.Name); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.actionsRepo.DeleteLastActionByTeamId(ctx, teamId)
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-6
@@ -4440,7 +4440,7 @@ const file_main_proto_rawDesc = "" +
|
|||||||
"\x17DeleteLastTeamActionReq\x12\x0e\n" +
|
"\x17DeleteLastTeamActionReq\x12\x0e\n" +
|
||||||
"\x02id\x18\x01 \x01(\x03R\x02id\"/\n" +
|
"\x02id\x18\x01 \x01(\x03R\x02id\"/\n" +
|
||||||
"\x17DeleteLastTeamActionRsp\x12\x14\n" +
|
"\x17DeleteLastTeamActionRsp\x12\x14\n" +
|
||||||
"\x05error\x18\x01 \x01(\tR\x05error2\x80>\n" +
|
"\x05error\x18\x01 \x01(\tR\x05error2\xf8=\n" +
|
||||||
"\x16EveningDetectiveServer\x12\xa6\x01\n" +
|
"\x16EveningDetectiveServer\x12\xa6\x01\n" +
|
||||||
"\x04Ping\x12'.crabs.evening_detective_server.PingReq\x1a'.crabs.evening_detective_server.PingRsp\"L\x92A3\x12)Проверить доступностьb\x06\n" +
|
"\x04Ping\x12'.crabs.evening_detective_server.PingReq\x1a'.crabs.evening_detective_server.PingRsp\"L\x92A3\x12)Проверить доступностьb\x06\n" +
|
||||||
"\x04\n" +
|
"\x04\n" +
|
||||||
@@ -4540,11 +4540,9 @@ const file_main_proto_rawDesc = "" +
|
|||||||
"\rAddTeamAction\x120.crabs.evening_detective_server.AddTeamActionReq\x1a0.crabs.evening_detective_server.AddTeamActionRsp\"N\x92A)\n" +
|
"\rAddTeamAction\x120.crabs.evening_detective_server.AddTeamActionReq\x1a0.crabs.evening_detective_server.AddTeamActionRsp\"N\x92A)\n" +
|
||||||
"\bХоды\x12\x15Сделать ходb\x06\n" +
|
"\bХоды\x12\x15Сделать ходb\x06\n" +
|
||||||
"\x04\n" +
|
"\x04\n" +
|
||||||
"\x00\x12\x00\x82\xd3\xe4\x93\x02\x1c:\x01*\"\x17/api/teams/{id}/actions\x12\xed\x01\n" +
|
"\x00\x12\x00\x82\xd3\xe4\x93\x02\x1c:\x01*\"\x17/api/teams/{id}/actions\x12\xe5\x01\n" +
|
||||||
"\x14DeleteLastTeamAction\x127.crabs.evening_detective_server.DeleteLastTeamActionReq\x1a7.crabs.evening_detective_server.DeleteLastTeamActionRsp\"c\x92A<\n" +
|
"\x14DeleteLastTeamAction\x127.crabs.evening_detective_server.DeleteLastTeamActionReq\x1a7.crabs.evening_detective_server.DeleteLastTeamActionRsp\"[\x92A4\n" +
|
||||||
"\bХоды\x12(Удалить последний ходb\x06\n" +
|
"\bХоды\x12(Удалить последний ход\x82\xd3\xe4\x93\x02\x1e*\x1c/api/teams/{id}/last-actionsB\xd7\x01\x92A\xc8\x01\x12U\n" +
|
||||||
"\x04\n" +
|
|
||||||
"\x00\x12\x00\x82\xd3\xe4\x93\x02\x1e*\x1c/api/teams/{id}/last-actionsB\xd7\x01\x92A\xc8\x01\x12U\n" +
|
|
||||||
"KДокументация сервиса \"Вечерний детектив\"2\x06v0.1.0Z]\n" +
|
"KДокументация сервиса \"Вечерний детектив\"2\x06v0.1.0Z]\n" +
|
||||||
"[\n" +
|
"[\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
|
|||||||
Reference in New Issue
Block a user