64 lines
2.0 KiB
Go
64 lines
2.0 KiB
Go
package grpc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
|
|
|
pb "datarush/pkg/api/competition"
|
|
)
|
|
|
|
type CompetitionService interface {
|
|
CreateCompetition(ctx context.Context, req *pb.Competition) (*pb.Competition, error)
|
|
GetCompetition(ctx context.Context, req *pb.GetCompetitionRequest) (*pb.Competition, error)
|
|
EditCompetition(ctx context.Context, req *pb.Competition) (*pb.Competition, error)
|
|
DeleteCompetition(ctx context.Context, req *pb.DeleteCompetitionRequest) (*emptypb.Empty, error)
|
|
ListCompetitions(ctx context.Context, req *pb.ListCompetitionsRequest) (*pb.ListCompetitionsResponse, error)
|
|
ChangeCompetitionState(ctx context.Context, req *pb.ChangeCompetitionStateRequest) (*pb.Competition, error)
|
|
}
|
|
|
|
type CompetitionHandler struct {
|
|
pb.UnimplementedCompetitionServiceServer
|
|
service CompetitionService
|
|
}
|
|
|
|
func NewCompetitionHandler(service CompetitionService) *CompetitionHandler {
|
|
return &CompetitionHandler{service: service}
|
|
}
|
|
|
|
func (h *CompetitionHandler) CreateCompetition(ctx context.Context, req *pb.Competition) (*pb.Competition, error) {
|
|
return h.service.CreateCompetition(ctx, req)
|
|
}
|
|
|
|
func (h *CompetitionHandler) GetCompetition(
|
|
ctx context.Context,
|
|
req *pb.GetCompetitionRequest,
|
|
) (*pb.Competition, error) {
|
|
return h.service.GetCompetition(ctx, req)
|
|
}
|
|
|
|
func (h *CompetitionHandler) EditCompetition(ctx context.Context, req *pb.Competition) (*pb.Competition, error) {
|
|
return h.service.EditCompetition(ctx, req)
|
|
}
|
|
|
|
func (h *CompetitionHandler) DeleteCompetition(
|
|
ctx context.Context,
|
|
req *pb.DeleteCompetitionRequest,
|
|
) (*emptypb.Empty, error) {
|
|
return h.service.DeleteCompetition(ctx, req)
|
|
}
|
|
|
|
func (h *CompetitionHandler) ListCompetitions(
|
|
ctx context.Context,
|
|
req *pb.ListCompetitionsRequest,
|
|
) (*pb.ListCompetitionsResponse, error) {
|
|
return h.service.ListCompetitions(ctx, req)
|
|
}
|
|
|
|
func (h *CompetitionHandler) ChangeCompetitionState(
|
|
ctx context.Context,
|
|
req *pb.ChangeCompetitionStateRequest,
|
|
) (*pb.Competition, error) {
|
|
return h.service.ChangeCompetitionState(ctx, req)
|
|
}
|