diff --git a/api/main.proto b/api/main.proto index 039fb0c..a520115 100644 --- a/api/main.proto +++ b/api/main.proto @@ -789,7 +789,9 @@ message AddTeamReq { } message AddTeamRsp { - string error = 1; + string error = 1; + int32 id = 2; + string password = 3; } message UpdateTeamReq { diff --git a/bin/evening_detective_server b/bin/evening_detective_server index e1fb96d..bd8275e 100755 Binary files a/bin/evening_detective_server and b/bin/evening_detective_server differ diff --git a/cmd/evening_detective_server/main.swagger.json b/cmd/evening_detective_server/main.swagger.json index 6f05216..1e8bf0c 100644 --- a/cmd/evening_detective_server/main.swagger.json +++ b/cmd/evening_detective_server/main.swagger.json @@ -1514,6 +1514,13 @@ "properties": { "error": { "type": "string" + }, + "id": { + "type": "integer", + "format": "int32" + }, + "password": { + "type": "string" } } }, diff --git a/internal/app/server.go b/internal/app/server.go index badefec..1c8b8a6 100644 --- a/internal/app/server.go +++ b/internal/app/server.go @@ -545,7 +545,7 @@ func (s *server) AddTeam(ctx context.Context, req *proto.AddTeamReq) (*proto.Add return nil, status.Errorf(codes.PermissionDenied, "permission denied") } - err := s.gameService.AddTeam( + team, err := s.gameService.AddTeam( ctx, claims.UserID, int(req.GameId), @@ -557,7 +557,10 @@ func (s *server) AddTeam(ctx context.Context, req *proto.AddTeamReq) (*proto.Add }, nil } - return &proto.AddTeamRsp{}, nil + return &proto.AddTeamRsp{ + Id: int32(team.ID), + Password: team.Password, + }, nil } func (s *server) UpdateTeam(ctx context.Context, req *proto.UpdateTeamReq) (*proto.UpdateTeamRsp, error) { diff --git a/internal/services/game_service/service.go b/internal/services/game_service/service.go index b520470..f299172 100644 --- a/internal/services/game_service/service.go +++ b/internal/services/game_service/service.go @@ -144,17 +144,23 @@ func (s *GameService) AddTeam( creatorId int, gameId int, name string, -) error { +) (*Team, error) { game, err := s.gamesRepo.GetGameByID(ctx, gameId) if err != nil { - return err + return nil, err } password, err := s.passwordGenerator.Generate() if err != nil { - return err + return nil, err } - _, err = s.teamsRepo.AddTeam(ctx, creatorId, gameId, name, game.ScenarioId, password) - return err + id, err := s.teamsRepo.AddTeam(ctx, creatorId, gameId, name, game.ScenarioId, password) + if err != nil { + return nil, err + } + return &Team{ + ID: id, + Password: password, + }, nil } func (s *GameService) UpdateTeam(ctx context.Context, teamId int, name string) error { diff --git a/proto/main.pb.go b/proto/main.pb.go index 538c82e..c291e33 100644 --- a/proto/main.pb.go +++ b/proto/main.pb.go @@ -3568,6 +3568,8 @@ func (x *AddTeamReq) GetName() string { type AddTeamRsp struct { state protoimpl.MessageState `protogen:"open.v1"` Error string `protobuf:"bytes,1,opt,name=error,proto3" json:"error,omitempty"` + Id int32 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` + Password string `protobuf:"bytes,3,opt,name=password,proto3" json:"password,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -3609,6 +3611,20 @@ func (x *AddTeamRsp) GetError() string { return "" } +func (x *AddTeamRsp) GetId() int32 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *AddTeamRsp) GetPassword() string { + if x != nil { + return x.Password + } + return "" +} + type UpdateTeamReq struct { state protoimpl.MessageState `protogen:"open.v1"` Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` @@ -4407,10 +4423,12 @@ const file_main_proto_rawDesc = "" + "\n" + "AddTeamReq\x12\x17\n" + "\agame_id\x18\x01 \x01(\x05R\x06gameId\x12\x12\n" + - "\x04name\x18\x02 \x01(\tR\x04name\"\"\n" + + "\x04name\x18\x02 \x01(\tR\x04name\"N\n" + "\n" + "AddTeamRsp\x12\x14\n" + - "\x05error\x18\x01 \x01(\tR\x05error\"3\n" + + "\x05error\x18\x01 \x01(\tR\x05error\x12\x0e\n" + + "\x02id\x18\x02 \x01(\x05R\x02id\x12\x1a\n" + + "\bpassword\x18\x03 \x01(\tR\bpassword\"3\n" + "\rUpdateTeamReq\x12\x0e\n" + "\x02id\x18\x01 \x01(\x05R\x02id\x12\x12\n" + "\x04name\x18\x02 \x01(\tR\x04name\"%\n" +