feat:
This commit is contained in:
parent
4cdd751b16
commit
be25404852
51 changed files with 606 additions and 1194 deletions
|
@ -1 +1,51 @@
|
|||
package grpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.sch9.ru/new_gate/ms-tester/internal/contests"
|
||||
contestv1 "git.sch9.ru/new_gate/ms-tester/pkg/go/gen/proto/contest/v1"
|
||||
"git.sch9.ru/new_gate/ms-tester/pkg/utils"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
||||
type ContestHandlers struct {
|
||||
contestv1.UnimplementedContestServiceServer
|
||||
|
||||
contestUC contests.ContestUseCase
|
||||
}
|
||||
|
||||
func NewContestHandlers(gserver *grpc.Server, contestUC contests.ContestUseCase) {
|
||||
handlers := &ContestHandlers{contestUC: contestUC}
|
||||
|
||||
contestv1.RegisterContestServiceServer(gserver, handlers)
|
||||
}
|
||||
|
||||
func (h *ContestHandlers) CreateContest(ctx context.Context, req *contestv1.CreateContestRequest) (*contestv1.CreateContestResponse, error) {
|
||||
id, err := h.contestUC.CreateContest(ctx, req.GetTitle())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &contestv1.CreateContestResponse{Id: id}, nil
|
||||
}
|
||||
|
||||
func (h *ContestHandlers) ReadContest(ctx context.Context, req *contestv1.ReadContestRequest) (*contestv1.ReadContestResponse, error) {
|
||||
contest, err := h.contestUC.ReadContestById(ctx, req.GetId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &contestv1.ReadContestResponse{Contest: &contestv1.ReadContestResponse_Contest{
|
||||
Id: *contest.Id,
|
||||
Title: *contest.Title,
|
||||
CreatedAt: utils.TimestampP(contest.CreatedAt),
|
||||
UpdatedAt: utils.TimestampP(contest.UpdatedAt),
|
||||
}}, nil
|
||||
}
|
||||
|
||||
func (h *ContestHandlers) DeleteContest(ctx context.Context, req *contestv1.DeleteContestRequest) (*emptypb.Empty, error) {
|
||||
err := h.contestUC.DeleteContest(ctx, req.GetId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue