chore: cleanup
This commit is contained in:
@@ -10,28 +10,36 @@ using RabbitMQ.Client;
|
||||
namespace JOBot.Backend.Services;
|
||||
|
||||
public class HeadHunterService(
|
||||
IChannel channel,
|
||||
ILogger<HeadHunterService> logger,
|
||||
IOptions<HeadHunterConfig> config,
|
||||
IChannel channel,
|
||||
ILogger<HeadHunterService> logger,
|
||||
IOptions<HeadHunterConfig> config,
|
||||
AppDbContext dbContext)
|
||||
{
|
||||
public enum Status
|
||||
{
|
||||
UserAuthRejectedError,
|
||||
HeadHunterAuthRejectedError,
|
||||
UserNotFoundError,
|
||||
HeadHunterResponseDeserializationFailedError,
|
||||
Success
|
||||
}
|
||||
|
||||
private readonly HeadHunterConfig _config = config.Value;
|
||||
|
||||
/// <summary>
|
||||
/// Generate HeadHunter oauth authorization link
|
||||
/// Generate HeadHunter oauth authorization link
|
||||
/// </summary>
|
||||
/// <param name="userId">Telegram UserId</param>
|
||||
/// <returns>Link for auth</returns>
|
||||
public string GenerateAuthLink(long userId)
|
||||
{
|
||||
|
||||
return string.Format(_config.Links.AuthLink, [_config.ClientId, GetRedirectUrl(userId)]);
|
||||
}
|
||||
|
||||
public async Task<Status> AuthUser(int userId, string authorizationCode, string? error)
|
||||
public async Task<Status> AuthUser(int userId, string authorizationCode, string? error) //TODO: Разбить этот метод
|
||||
{
|
||||
logger.LogInformation($"Authorization for user {userId} in process...");
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(error))
|
||||
{
|
||||
logger.LogWarning($"User {userId} auth completed with error {error}");
|
||||
@@ -69,7 +77,7 @@ public class HeadHunterService(
|
||||
logger.LogWarning($"{res.Content.ReadAsStringAsync().Result}");
|
||||
return Status.HeadHunterAuthRejectedError;
|
||||
}
|
||||
|
||||
|
||||
var responseDto = JsonSerializer.Deserialize<HeadHunterTokenResponseDto>(await res.Content.ReadAsStringAsync());
|
||||
|
||||
if (responseDto == null)
|
||||
@@ -78,7 +86,7 @@ public class HeadHunterService(
|
||||
$"{nameof(Status.HeadHunterResponseDeserializationFailedError)}");
|
||||
return Status.HeadHunterResponseDeserializationFailedError;
|
||||
}
|
||||
|
||||
|
||||
var user = await dbContext.Users.FirstOrDefaultAsync(x => x.UserId == userId);
|
||||
|
||||
if (user == null)
|
||||
@@ -86,20 +94,20 @@ public class HeadHunterService(
|
||||
logger.LogWarning($"User {userId} search completed with error {nameof(Status.UserNotFoundError)}");
|
||||
return Status.UserNotFoundError;
|
||||
}
|
||||
|
||||
|
||||
user.AccessToken = responseDto.AccessToken;
|
||||
user.RefreshToken = responseDto.RefreshToken;
|
||||
|
||||
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
|
||||
logger.LogInformation($"User {userId} auth completed!");
|
||||
|
||||
|
||||
await channel.BasicPublishAsync(
|
||||
string.Empty,
|
||||
RabbitQueues.AuthQueue,
|
||||
string.Empty,
|
||||
RabbitQueues.AuthQueue,
|
||||
Encoding.UTF8.GetBytes(userId.ToString()));
|
||||
|
||||
logger.LogInformation($"RabbitMQ event was created");
|
||||
|
||||
logger.LogInformation("RabbitMQ event was created");
|
||||
|
||||
return Status.Success;
|
||||
}
|
||||
@@ -114,13 +122,4 @@ public class HeadHunterService(
|
||||
Query = $"?userId={userId}"
|
||||
}.ToString();
|
||||
}
|
||||
|
||||
public enum Status
|
||||
{
|
||||
UserAuthRejectedError,
|
||||
HeadHunterAuthRejectedError,
|
||||
UserNotFoundError,
|
||||
HeadHunterResponseDeserializationFailedError,
|
||||
Success
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Grpc.Core;
|
||||
using JOBot.Backend.DAL.Context;
|
||||
using JOBot.Backend.DAL.Models;
|
||||
@@ -11,7 +10,7 @@ namespace JOBot.Backend.Services.gRPC;
|
||||
public class UserService(AppDbContext dbContext, HeadHunterService hhService) : Proto.User.UserBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Create user
|
||||
/// Create user
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="_"></param>
|
||||
@@ -32,7 +31,7 @@ public class UserService(AppDbContext dbContext, HeadHunterService hhService) :
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get user for client
|
||||
/// Get user for client
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="_"></param>
|
||||
@@ -46,7 +45,7 @@ public class UserService(AppDbContext dbContext, HeadHunterService hhService) :
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Accept EULA for user
|
||||
/// Accept EULA for user
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="_"></param>
|
||||
@@ -64,7 +63,7 @@ public class UserService(AppDbContext dbContext, HeadHunterService hhService) :
|
||||
}
|
||||
|
||||
public override Task<GetHeadHunterAuthHookResponse> GetHeadHunterAuthHook(
|
||||
GetHeadHunterAuthHookRequest request,
|
||||
GetHeadHunterAuthHookRequest request,
|
||||
ServerCallContext context)
|
||||
{
|
||||
return Task.Run(() => new GetHeadHunterAuthHookResponse
|
||||
@@ -74,7 +73,7 @@ public class UserService(AppDbContext dbContext, HeadHunterService hhService) :
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throw RPCException if user not found
|
||||
/// Throw RPCException if user not found
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <exception cref="RpcException"></exception>
|
||||
|
||||
Reference in New Issue
Block a user