generated from VLADIMIR/template
add questions
This commit is contained in:
@@ -599,6 +599,73 @@ func (s *server) DeleteScenarioPlace(ctx context.Context, req *proto.DeleteScena
|
||||
return &proto.DeleteScenarioPlaceRsp{}, nil
|
||||
}
|
||||
|
||||
func (s *server) AddScenarioQuestion(ctx context.Context, req *proto.AddScenarioQuestionReq) (*proto.AddScenarioQuestionRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
if !roles.HasRole(claims, roles.Author) {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
err := s.scenarioService.AddScenarioQuestion(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
convertQuestion(req.Question),
|
||||
claims.UserID,
|
||||
roles.HasRole(claims, roles.Admin),
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.AddScenarioQuestionRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &proto.AddScenarioQuestionRsp{}, nil
|
||||
}
|
||||
|
||||
func (s *server) UpdateScenarioQuestion(ctx context.Context, req *proto.UpdateScenarioQuestionReq) (*proto.UpdateScenarioQuestionRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
if !roles.HasRole(claims, roles.Author) {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
err := s.scenarioService.UpdateScenarioQuestion(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
req.Code,
|
||||
convertQuestion(req.Question),
|
||||
claims.UserID,
|
||||
roles.HasRole(claims, roles.Admin),
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.UpdateScenarioQuestionRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &proto.UpdateScenarioQuestionRsp{}, nil
|
||||
}
|
||||
|
||||
func (s *server) DeleteScenarioQuestion(ctx context.Context, req *proto.DeleteScenarioQuestionReq) (*proto.DeleteScenarioQuestionRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
if !roles.HasRole(claims, roles.Author) {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
|
||||
err := s.scenarioService.DeleteScenarioQuestion(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
req.Code,
|
||||
claims.UserID,
|
||||
roles.HasRole(claims, roles.Admin),
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.DeleteScenarioQuestionRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &proto.DeleteScenarioQuestionRsp{}, nil
|
||||
}
|
||||
|
||||
func (s *server) UpdateScenarioIntro(ctx context.Context, req *proto.UpdateScenarioIntroReq) (*proto.UpdateScenarioIntroRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
if !roles.HasRole(claims, roles.Author) {
|
||||
@@ -762,6 +829,25 @@ func (s *server) GetGame(ctx context.Context, req *proto.GetGameReq) (*proto.Get
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *server) GetGameAnswers(ctx context.Context, req *proto.GetGameAnswersReq) (*proto.GetGameAnswersRsp, 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")
|
||||
}
|
||||
|
||||
gameAnswers, err := s.gameService.GetGameAnswers(ctx, int(req.GameId))
|
||||
if err != nil {
|
||||
return &proto.GetGameAnswersRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &proto.GetGameAnswersRsp{
|
||||
Questions: mapQuestions(gameAnswers.Questions),
|
||||
Teams: mapTeamAnswers(gameAnswers.Teams),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *server) GetGames(ctx context.Context, req *proto.GetGamesReq) (*proto.GetGamesRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
if !roles.HasRole(claims, roles.Organizer) && !roles.HasRole(claims, roles.Author) {
|
||||
@@ -1022,3 +1108,63 @@ func (s *server) DeleteLastTeamAction(ctx context.Context, req *proto.DeleteLast
|
||||
|
||||
return &proto.DeleteLastTeamActionRsp{}, nil
|
||||
}
|
||||
|
||||
func (s *server) GetTeamAnswers(ctx context.Context, req *proto.GetTeamAnswersReq) (*proto.GetTeamAnswersRsp, error) {
|
||||
answers, err := s.gameService.GetTeamAnswers(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
req.Password,
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.GetTeamAnswersRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &proto.GetTeamAnswersRsp{
|
||||
Answers: mapAnswers(answers),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *server) SubmitTeamAnswers(ctx context.Context, req *proto.SubmitTeamAnswersReq) (*proto.SubmitTeamAnswersRsp, error) {
|
||||
err := s.gameService.SubmitTeamAnswers(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
req.Password,
|
||||
convertAnswers(req.Answers),
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.SubmitTeamAnswersRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &proto.SubmitTeamAnswersRsp{}, nil
|
||||
}
|
||||
|
||||
func (s *server) SetTeamAnswerScore(ctx context.Context, req *proto.SetTeamAnswerScoreReq) (*proto.SetTeamAnswerScoreRsp, 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")
|
||||
}
|
||||
|
||||
var score *int
|
||||
if req.Score != nil {
|
||||
v := int(req.GetScore())
|
||||
score = &v
|
||||
}
|
||||
|
||||
err := s.gameService.SetTeamAnswerScore(
|
||||
ctx,
|
||||
int(req.Id),
|
||||
req.QuestionCode,
|
||||
score,
|
||||
)
|
||||
if err != nil {
|
||||
return &proto.SetTeamAnswerScoreRsp{
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &proto.SetTeamAnswerScoreRsp{}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user