add user service

This commit is contained in:
Timur Kh.
2025-12-17 12:09:25 +03:00
parent 843c50a103
commit 6f21e895f0
9 changed files with 596 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
package grpc
import (
"context"
pb "datarush/pkg/api/user"
"google.golang.org/protobuf/types/known/emptypb"
)
type UserService interface {
GetProfile(ctx context.Context, req *pb.GetProfileRequest) (*pb.User, error)
RegisterForCompetition(ctx context.Context, req *pb.RegisterForCompetitionRequest) (*emptypb.Empty, error)
UnregisterFromCompetition(ctx context.Context, req *pb.UnregisterFromCompetitionRequest) (*emptypb.Empty, error)
ListUserCompetitions(ctx context.Context, req *pb.ListUserCompetitionsRequest) (*pb.ListUserCompetitionsResponse, error)
}
type UserHandler struct {
pb.UnimplementedUserServiceServer
service UserService
}
func NewUserHandler(service UserService) *UserHandler {
return &UserHandler{service: service}
}
func (h *UserHandler) GetProfile(ctx context.Context, req *pb.GetProfileRequest) (*pb.User, error) {
return h.service.GetProfile(ctx, req)
}
func (h *UserHandler) RegisterForCompetition(ctx context.Context, req *pb.RegisterForCompetitionRequest) (*emptypb.Empty, error) {
return h.service.RegisterForCompetition(ctx, req)
}
func (h *UserHandler) UnregisterFromCompetition(ctx context.Context, req *pb.UnregisterFromCompetitionRequest) (*emptypb.Empty, error) {
return h.service.UnregisterFromCompetition(ctx, req)
}
func (h *UserHandler) ListUserCompetitions(ctx context.Context, req *pb.ListUserCompetitionsRequest) (*pb.ListUserCompetitionsResponse, error) {
return h.service.ListUserCompetitions(ctx, req)
}