Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

G rpc #40

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 80 additions & 2 deletions OnlineCinema.gRPC/Films/FilmsClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,84 @@
namespace OnlineCinema.gRPC.Films;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using FilmsService;
using Grpc.Net.Client;
using Microsoft.Extensions.Logging;

namespace OnlineCinema.gRPC.Films;

public class FilmsClient
{

private global::FilmsService.FilmsService.FilmsServiceClient Client { get; init; }
private ILogger<FilmsClient> _logger;
private readonly GrpcChannel Channel;

public FilmsClient(ILogger<FilmsClient> logger = null)
{
_logger = logger;

var httpHandler = new HttpClientHandler();

httpHandler.ServerCertificateCustomValidationCallback =
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

Channel = GrpcChannel.ForAddress("https://localhost:7280",
new GrpcChannelOptions { HttpHandler = httpHandler });

Client = new global::FilmsService.FilmsService.FilmsServiceClient(Channel);
}

public async Task<FilmResponse> GetFilmAsync(int id,
CancellationToken token = default)
{
var request = new TittleGetByIDRequest
{
Id = id
};
var responce = await Client.GetFilmAsync(request);
return responce;
}

public async Task<FilmsResponse> GetFilmByNameAsync(string name,
CancellationToken token = default)
{
var request = new TittleGetByNameRequest
{
Name = name
};
var response = await Client.GetFilmByNameAsync(request);

return response;
}

public async Task<FilmResponse> AddFilmAsync()
{
throw new NotImplementedException("тут какая-то шняга");
var request = new FilmRequest
{
FilmData = new Film
{

}
};

var response = await Client.AddFilmAsync(request);
return response;
}

public async Task<FilmResponse> UpdateFilmAsync()
{
throw new NotImplementedException("тут какая-то шняга");
var request = new FilmRequest
{
FilmData = new Film
{

}
};

var responce = await Client.UpdateFilmAsync(request);
return responce;
}
}
57 changes: 56 additions & 1 deletion OnlineCinema.gRPC/Users/UsersClient.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,61 @@
namespace OnlineCinema.gRPC.Users;
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Google.Protobuf;
using Grpc.Net.Client;
using Microsoft.Extensions.Logging;
using UserService.Messages;

namespace OnlineCinema.gRPC.Users;

public class UsersClient
{
private UserService.UserService.UserServiceClient Client { get; init; }
private ILogger<UsersClient> _logger;
private GrpcChannel Channel;

public UsersClient(ILogger<UsersClient> logger = null)
{
_logger = logger;

var httpHandler = new HttpClientHandler();

httpHandler.ServerCertificateCustomValidationCallback =
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

Channel = GrpcChannel.ForAddress("https://localhost:7280",
new GrpcChannelOptions { HttpHandler = httpHandler });

Client = new UserService.UserService.UserServiceClient(Channel);
}

public async Task<UserReply> AuthAsync(string username, byte[] password,
CancellationToken token = default)
{
var request = new AuthRequest
{
Username = username,
Password = ByteString.CopyFrom(password)
};
var response = await Client.AuthAsync(request);
return response;
}

public async Task<UserReply> RegisterAsync(string username, byte[] password,
CancellationToken token = default)
{
var request = new RegisterRequest
{
Username = username,
Password = ByteString.CopyFrom(password)
};
var response = await Client.RegisterAsync(request);
return response;
}

public async Task<UserReply> UpdateAsync()
{
throw new NotImplementedException("шнга");
}
}