fix add team

This commit is contained in:
2026-07-29 00:59:37 +07:00
parent 1b3e0b768d
commit d1b263fa78
6 changed files with 46 additions and 10 deletions
+3 -1
View File
@@ -789,7 +789,9 @@ message AddTeamReq {
}
message AddTeamRsp {
string error = 1;
string error = 1;
int32 id = 2;
string password = 3;
}
message UpdateTeamReq {
Binary file not shown.
@@ -1514,6 +1514,13 @@
"properties": {
"error": {
"type": "string"
},
"id": {
"type": "integer",
"format": "int32"
},
"password": {
"type": "string"
}
}
},
+5 -2
View File
@@ -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) {
+11 -5
View File
@@ -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 {
+20 -2
View File
@@ -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" +