generated from VLADIMIR/template
add tickets api
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"evening_detective_server/internal/services/participation_service"
|
||||
"evening_detective_server/internal/services/scenarios_service"
|
||||
"evening_detective_server/internal/services/team_service"
|
||||
"evening_detective_server/internal/services/ticket_service"
|
||||
"evening_detective_server/internal/services/ui_service"
|
||||
"evening_detective_server/internal/services/users_service"
|
||||
proto "evening_detective_server/proto"
|
||||
@@ -28,6 +29,7 @@ type server struct {
|
||||
answerService *answer_service.AnswerService
|
||||
reviewService *game_review_service.Service
|
||||
teamService *team_service.TeamService
|
||||
ticketService *ticket_service.Service
|
||||
participationService *participation_service.ParticipationService
|
||||
screenRepo *screen_sessions_repo.ScreenSessionsRepo
|
||||
mapRepo *game_map_repo.Repo
|
||||
@@ -43,6 +45,7 @@ func NewServer(
|
||||
answerService *answer_service.AnswerService,
|
||||
reviewService *game_review_service.Service,
|
||||
teamService *team_service.TeamService,
|
||||
ticketService *ticket_service.Service,
|
||||
participationService *participation_service.ParticipationService,
|
||||
screenRepo *screen_sessions_repo.ScreenSessionsRepo,
|
||||
mapRepo *game_map_repo.Repo,
|
||||
@@ -57,6 +60,7 @@ func NewServer(
|
||||
answerService: answerService,
|
||||
reviewService: reviewService,
|
||||
teamService: teamService,
|
||||
ticketService: ticketService,
|
||||
participationService: participationService,
|
||||
screenRepo: screenRepo,
|
||||
mapRepo: mapRepo,
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"evening_detective_server/internal/modules/processor_jwt"
|
||||
"evening_detective_server/internal/modules/roles"
|
||||
"evening_detective_server/proto"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func (s *server) IssueGameTickets(ctx context.Context, req *proto.IssueGameTicketsReq) (*proto.IssueGameTicketsRsp, error) {
|
||||
claims, ok := ctx.Value("claims").(*processor_jwt.JWTClaims)
|
||||
if !ok || claims == nil {
|
||||
return nil, status.Error(codes.Unauthenticated, "необходима авторизация")
|
||||
}
|
||||
if !roles.HasRole(claims, roles.Organizer) && !roles.HasRole(claims, roles.Author) {
|
||||
return nil, status.Error(codes.PermissionDenied, "permission denied")
|
||||
}
|
||||
if req == nil || req.GameId <= 0 {
|
||||
return nil, status.Error(codes.InvalidArgument, "некорректный идентификатор игры")
|
||||
}
|
||||
|
||||
tickets, err := s.ticketService.Issue(ctx, int(req.GameId), int(req.Count))
|
||||
if err != nil {
|
||||
return &proto.IssueGameTicketsRsp{Error: err.Error()}, nil
|
||||
}
|
||||
|
||||
result := make([]*proto.Ticket, 0, len(tickets))
|
||||
for _, ticket := range tickets {
|
||||
result = append(result, &proto.Ticket{Id: int32(ticket.ID), Url: ticket.URL})
|
||||
}
|
||||
return &proto.IssueGameTicketsRsp{Tickets: result}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user