generated from VLADIMIR/template
add play
This commit is contained in:
@@ -571,6 +571,22 @@ func (s *server) PauseGame(ctx context.Context, req *proto.PauseGameReq) (*proto
|
||||
return &proto.PauseGameRsp{}, nil
|
||||
}
|
||||
|
||||
func (s *server) PlayGame(ctx context.Context, req *proto.PlayGameReq) (*proto.PlayGameRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
if !roles.HasRole(claims, roles.Organizer) && !roles.HasRole(claims, roles.Author) {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
err := s.gameService.PlayGame(ctx, int(req.Id))
|
||||
if err != nil {
|
||||
return &proto.PlayGameRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &proto.PlayGameRsp{}, nil
|
||||
}
|
||||
|
||||
func (s *server) FinishGame(ctx context.Context, req *proto.FinishGameReq) (*proto.FinishGameRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
if !roles.HasRole(claims, roles.Organizer) && !roles.HasRole(claims, roles.Author) {
|
||||
|
||||
@@ -221,6 +221,25 @@ func (r *GamesRepo) PauseGame(ctx context.Context, id int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *GamesRepo) PlayGame(ctx context.Context, id int) error {
|
||||
tag, err := r.pool.Exec(
|
||||
ctx,
|
||||
`UPDATE games
|
||||
SET
|
||||
status = 'run',
|
||||
updated_at = NOW()
|
||||
WHERE id = $1`,
|
||||
id,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if tag.RowsAffected() == 0 {
|
||||
return ErrGameNotFound
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *GamesRepo) FinishGame(ctx context.Context, id int) error {
|
||||
tag, err := r.pool.Exec(
|
||||
ctx,
|
||||
|
||||
@@ -156,6 +156,10 @@ func (s *GameService) PauseGame(ctx context.Context, id int) error {
|
||||
return s.gamesRepo.PauseGame(ctx, id)
|
||||
}
|
||||
|
||||
func (s *GameService) PlayGame(ctx context.Context, id int) error {
|
||||
return s.gamesRepo.PlayGame(ctx, id)
|
||||
}
|
||||
|
||||
func (s *GameService) FinishGame(ctx context.Context, id int) error {
|
||||
return s.gamesRepo.FinishGame(ctx, id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user