Initial version

This commit is contained in:
2026-06-09 22:27:38 +02:00
parent 5afbf3b01c
commit 5ff2ac8941
57 changed files with 2343 additions and 98 deletions
@@ -0,0 +1,24 @@
using Microsoft.Extensions.Options;
using ProtoBuf.Grpc;
using EonaCat.gRPC.Api.Helpers;
using EonaCat.gRPC.Proto;
namespace EonaCat.gRPC.Api.Services;
public class AuthenticationHandler : IAuthenticationService
{
private readonly IOptions<AppSettings> _appSettings;
public AuthenticationHandler(IOptions<AppSettings> appSettings)
{
_appSettings = appSettings;
}
public Task<AuthenticationResponse> Authenticate(AuthenticationRequest request, CallContext context = default)
{
var authenticationResponse = JwtAuthenticationManager.Authenticate(_appSettings, request);
if (authenticationResponse == null)
throw new RpcException(new Status(StatusCode.Unauthenticated, "Invalid ProtoUserResponse Credentials"));
return Task.FromResult(authenticationResponse);
}
}
+38
View File
@@ -0,0 +1,38 @@
using EonaCat.gRPC.Core.Interfaces.Services;
using EonaCat.gRPC.Proto;
using EonaCat.Mapper;
namespace EonaCat.gRPC.Api.Services;
public class UserHandler : IProtoUserService
{
private readonly IUserService _userService;
public UserHandler(IUserService userService)
{
_userService = userService;
}
public async ValueTask<BaseResponse<string>> Create(UserCreateRequest userCreateRequest)
{
var user = CustomMapper.Map<UserCreateRequest, UserEntity>(userCreateRequest);
var response = await _userService.CreateUser(user);
return BaseResponse<string>.Created(response.ToString());
}
public async Task<BaseResponse<List<UserResponse>?>> GetAsync()
{
var users = await _userService.GetAsync();
var mapped = CustomMapper.Map<List<UserEntity>, List<UserResponse>>(users.ToList());
return BaseResponse<List<UserResponse>?>.Ok(mapped);
}
public async Task<BaseResponse<UserResponse?>> GetByIdAsync(string id)
{
if (string.IsNullOrEmpty(id) || !long.TryParse(id, out _))
return BaseResponse<UserResponse?>.Failed(null, message: "Invalid ID: It is either empty or not a valid long.");
var user = await _userService.GetAsync(Convert.ToInt64(id));
var mapped = CustomMapper.Map<UserEntity, UserResponse>(user);
return BaseResponse<UserResponse>.Ok(mapped);
}
}