42 lines
983 B
Go
42 lines
983 B
Go
package grpc
|
|
|
|
import (
|
|
"git.sch9.ru/new_gate/ms-tester/internal/tester"
|
|
testerv1 "git.sch9.ru/new_gate/ms-tester/pkg/go/gen/proto/tester/v1"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
func NewTesterHandlers(gserver *grpc.Server, testerUC tester.TesterUseCase) {
|
|
handlers := &testerHandlers{
|
|
testerUC: testerUC,
|
|
}
|
|
|
|
testerv1.RegisterTesterServiceServer(gserver, handlers)
|
|
}
|
|
|
|
type testerHandlers struct {
|
|
testerv1.UnimplementedTesterServiceServer
|
|
|
|
testerUC tester.TesterUseCase
|
|
}
|
|
|
|
func (h *testerHandlers) CreateSolution(req *testerv1.CreateSolutionRequest, stream testerv1.TesterService_CreateSolutionServer) error {
|
|
id, err := h.testerUC.CreateSolution(stream.Context(), req.GetTaskId(), req.GetSolution(), req.GetLanguage())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
ch, err := h.testerUC.ProcessTesting(stream.Context(), id)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for state := range ch {
|
|
err = stream.Send(&testerv1.TestingState{Msg: state})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|