generated from VLADIMIR/template
update
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"evening_detective_server/internal/modules/processor_jwt"
|
||||
"evening_detective_server/internal/modules/roles"
|
||||
"evening_detective_server/internal/services/scenarios_service"
|
||||
proto "evening_detective_server/proto"
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -53,6 +54,9 @@ func (s *server) GetScenariosCatalog(ctx context.Context, req *proto.GetScenario
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
if err := s.addScenarioRatings(ctx, scenarios); err != nil {
|
||||
return &proto.GetScenariosCatalogRsp{Error: err.Error()}, nil
|
||||
}
|
||||
|
||||
return &proto.GetScenariosCatalogRsp{
|
||||
Scenarios: mapScenarios(scenarios),
|
||||
@@ -84,12 +88,27 @@ func (s *server) GetScenario(ctx context.Context, req *proto.GetScenarioReq) (*p
|
||||
Error: err.Error(),
|
||||
}, nil
|
||||
}
|
||||
if err := s.addScenarioRatings(ctx, []*scenarios_service.Scenario{scenario}); err != nil {
|
||||
return &proto.GetScenarioRsp{Error: err.Error()}, nil
|
||||
}
|
||||
|
||||
return &proto.GetScenarioRsp{
|
||||
Scenario: mapScenario(scenario),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *server) addScenarioRatings(ctx context.Context, scenarios []*scenarios_service.Scenario) error {
|
||||
for _, scenario := range scenarios {
|
||||
average, count, err := s.reviewService.ScenarioRating(ctx, scenario.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
scenario.AverageRating = average
|
||||
scenario.ReviewsCount = count
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *server) UpdateScenario(ctx context.Context, req *proto.UpdateScenarioReq) (*proto.UpdateScenarioRsp, error) {
|
||||
claims := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
if !roles.HasRole(claims, roles.Author) {
|
||||
|
||||
Reference in New Issue
Block a user