ms-tester/internal/tester/delivery/grpc/handlers.go

42 lines
983 B
Go
Raw Normal View History

2024-10-09 18:55:16 +00:00
package grpc
2024-11-01 18:22:43 +00:00
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
}