package transport import ( "context" "git.sch9.ru/new_gate/ms-tester/internal/lib" "git.sch9.ru/new_gate/ms-tester/internal/models" testerv1 "git.sch9.ru/new_gate/ms-tester/pkg/go/gen/tester/v1" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/emptypb" ) func (s *TesterServer) CreateProblem(ctx context.Context, req *testerv1.CreateProblemRequest) (*testerv1.CreateProblemResponse, error) { problem := req.GetProblem() if problem == nil { return nil, status.Errorf(codes.Unknown, "") // FIXME } id, err := s.problemService.CreateProblem( ctx, &models.Problem{ Name: lib.AsStringP(problem.Name), Description: lib.AsStringP(problem.Description), TimeLimit: lib.AsInt32P(problem.TimeLimit), MemoryLimit: lib.AsInt32P(problem.MemoryLimit), }, ) if err != nil { return nil, status.Errorf(codes.Unknown, err.Error()) // FIXME } return &testerv1.CreateProblemResponse{ Id: id, }, nil } func (s *TesterServer) ReadProblem(ctx context.Context, req *testerv1.ReadProblemRequest) (*testerv1.ReadProblemResponse, error) { problem, err := s.problemService.ReadProblem(ctx, req.GetId()) if err != nil { return nil, status.Errorf(codes.Unknown, err.Error()) // FIXME } return &testerv1.ReadProblemResponse{ Problem: &testerv1.ReadProblemResponse_Problem{ Id: *problem.Id, Name: *problem.Name, Description: *problem.Description, TimeLimit: *problem.TimeLimit, MemoryLimit: *problem.MemoryLimit, CreatedAt: AsTimestampP(problem.CreatedAt), UpdatedAt: AsTimestampP(problem.UpdatedAt), }, }, nil } func (s *TesterServer) UpdateProblem(ctx context.Context, req *testerv1.UpdateProblemRequest) (*emptypb.Empty, error) { problem := req.GetProblem() if problem == nil { return nil, status.Errorf(codes.Unknown, "") // FIXME } err := s.problemService.UpdateProblem( ctx, &models.Problem{ Id: lib.AsInt32P(problem.Id), Name: problem.Name, Description: problem.Description, TimeLimit: problem.TimeLimit, MemoryLimit: problem.MemoryLimit, }, ) if err != nil { return nil, status.Errorf(codes.Unknown, err.Error()) // FIXME } return &emptypb.Empty{}, nil } func (s *TesterServer) DeleteProblem(ctx context.Context, req *testerv1.DeleteProblemRequest) (*emptypb.Empty, error) { err := s.problemService.DeleteProblem(ctx, req.GetId()) if err != nil { return nil, status.Errorf(codes.Unknown, err.Error()) // FIXME } return &emptypb.Empty{}, nil }