package app import ( "context" "evening_detective_server/internal/services/users_service" proto "evening_detective_server/proto" ) type server struct { proto.UnsafeEveningDetectiveServerServer usersService *users_service.UsersService } func NewServer( usersService *users_service.UsersService, ) proto.EveningDetectiveServerServer { return &server{ usersService: usersService, } } func (s *server) Ping(_ context.Context, _ *proto.PingReq) (*proto.PingRsp, error) { return &proto.PingRsp{}, nil } func (s *server) Echo(_ context.Context, req *proto.EchoReq) (*proto.EchoRsp, error) { return &proto.EchoRsp{Text: req.Text}, nil } func (s *server) Signup(ctx context.Context, req *proto.SignupReq) (*proto.SignupRsp, error) { err := s.usersService.AddUser(ctx, req.Username, req.Email) if err != nil { return &proto.SignupRsp{ Error: err.Error(), }, nil } return &proto.SignupRsp{}, nil } func (s *server) RefreshPassword(ctx context.Context, req *proto.RefreshPasswordReq) (*proto.RefreshPasswordRsp, error) { err := s.usersService.RefreshPassword(ctx, req.Email) if err != nil { return &proto.RefreshPasswordRsp{ Error: err.Error(), }, nil } return &proto.RefreshPasswordRsp{}, nil } func (s *server) Login(ctx context.Context, req *proto.LoginReq) (*proto.LoginRsp, error) { accessToken, refreshToken, err := s.usersService.Login(ctx, req.Email, req.Password) if err != nil { return &proto.LoginRsp{ Error: err.Error(), }, nil } return &proto.LoginRsp{ AccessToken: accessToken, RefreshToken: refreshToken, }, nil }