Compare commits
No commits in common. "8" and "main" have entirely different histories.
@ -15,13 +15,11 @@ public class User
|
|||||||
|
|
||||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
[MaxLength(255)] public string? AccessToken { get; set; }
|
[MaxLength(255)] public string? AccessToken { get; set; } = null;
|
||||||
[MaxLength(255)] public string? RefreshToken { get; set; }
|
[MaxLength(255)] public string? RefreshToken { get; set; } = null;
|
||||||
|
|
||||||
public long? ExpiresIn { get; set; } = null;
|
public bool Eula { get; set; } = false;
|
||||||
|
[MaxLength(255)] public string? CvUrl { get; set; } = null;
|
||||||
public bool Eula { get; set; }
|
|
||||||
[MaxLength(255)] public string? CvUrl { get; set; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: Негоже это маппинги в DAL ложить
|
//TODO: Негоже это маппинги в DAL ложить
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace JOBot.Backend.DTOs.HeadHunterApi;
|
|
||||||
|
|
||||||
public class ListOfResumeResponseDto
|
|
||||||
{
|
|
||||||
[JsonPropertyName("found")]
|
|
||||||
public bool Found { get; set; }
|
|
||||||
[JsonPropertyName("items")]
|
|
||||||
public List<Resume> Items { get; set; } = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Resume
|
|
||||||
{
|
|
||||||
[JsonPropertyName("can_publish_or_update")]
|
|
||||||
public bool CanPublishOrUpdate { get; set; }
|
|
||||||
[JsonPropertyName("title")]
|
|
||||||
public string Title { get; set; } = null!;
|
|
||||||
[JsonPropertyName("url")]
|
|
||||||
public string Url { get; set; } = null!;
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace JOBot.Backend.DTOs.HeadHunterApi;
|
namespace JOBot.Backend.DTOs.HeadHunterHook;
|
||||||
|
|
||||||
public record HeadHunterTokenResponseDto(
|
public record HeadHunterTokenResponseDto(
|
||||||
[property: JsonPropertyName("access_token")]
|
[property: JsonPropertyName("access_token")]
|
@ -25,9 +25,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Protobuf Include="..\Proto\*" GrpcServices="Server"></Protobuf>
|
<Protobuf Include="..\Proto\*" GrpcServices="Server"></Protobuf>
|
||||||
<Protobuf Update="..\Proto\resume.proto">
|
|
||||||
<Link>Proto\resume.proto</Link>
|
|
||||||
</Protobuf>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using JOBot.Backend.DAL.Context;
|
using JOBot.Backend.DAL.Context;
|
||||||
using JOBot.Backend.DAL.Models;
|
using JOBot.Backend.DTOs.HeadHunterHook;
|
||||||
using JOBot.Backend.DTOs.HeadHunterApi;
|
|
||||||
using JOBot.Backend.Infrastructure.Config;
|
using JOBot.Backend.Infrastructure.Config;
|
||||||
using JOBot.Infrastructure.Config;
|
using JOBot.Infrastructure.Config;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
@ -39,13 +38,6 @@ public class HeadHunterService(
|
|||||||
return string.Format(_config.Links.AuthLink, [_config.ClientId, GetRedirectUrl(userId)]);
|
return string.Format(_config.Links.AuthLink, [_config.ClientId, GetRedirectUrl(userId)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Auth user on HeadHunter API
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="userId"></param>
|
|
||||||
/// <param name="authorizationCode"></param>
|
|
||||||
/// <param name="error"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
public async Task<Status> AuthUser(int userId, string authorizationCode, string? error) //TODO: Разбить этот метод
|
public async Task<Status> AuthUser(int userId, string authorizationCode, string? error) //TODO: Разбить этот метод
|
||||||
{
|
{
|
||||||
logger.LogInformation($"Authorization for user {userId} in process...");
|
logger.LogInformation($"Authorization for user {userId} in process...");
|
||||||
@ -116,7 +108,6 @@ public class HeadHunterService(
|
|||||||
|
|
||||||
user.AccessToken = responseDto.AccessToken;
|
user.AccessToken = responseDto.AccessToken;
|
||||||
user.RefreshToken = responseDto.RefreshToken;
|
user.RefreshToken = responseDto.RefreshToken;
|
||||||
user.ExpiresIn = responseDto.ExpiresIn;
|
|
||||||
|
|
||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
@ -132,50 +123,6 @@ public class HeadHunterService(
|
|||||||
return Status.Success;
|
return Status.Success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Status> UpdateUserAccessToken(User user)
|
|
||||||
{
|
|
||||||
if (user.RefreshToken == null)
|
|
||||||
return Status.UserAuthRejectedError;
|
|
||||||
|
|
||||||
using var client = new HttpClient(); //TODO: Написать wrapper для работы с HH API
|
|
||||||
var form = new Dictionary<string, string>
|
|
||||||
{
|
|
||||||
{ "refresh_token", user.RefreshToken },
|
|
||||||
{ "grant_type", "refresh_token" }
|
|
||||||
};
|
|
||||||
client.BaseAddress = new UriBuilder(_config.Links.HeadHunterApiDomain)
|
|
||||||
{
|
|
||||||
Port = -1,
|
|
||||||
Scheme = "https"
|
|
||||||
}.Uri;
|
|
||||||
client.DefaultRequestHeaders.UserAgent.ParseAdd("Jobot BackEnd Service");
|
|
||||||
|
|
||||||
using var res = await client.SendAsync(
|
|
||||||
new HttpRequestMessage(
|
|
||||||
HttpMethod.Post,
|
|
||||||
_config.Links.HeadHunterTokenRoute)
|
|
||||||
{
|
|
||||||
Content = new FormUrlEncodedContent(form)
|
|
||||||
});
|
|
||||||
|
|
||||||
var responseDto =
|
|
||||||
JsonSerializer.Deserialize<HeadHunterTokenResponseDto>(await res.Content.ReadAsStringAsync());
|
|
||||||
|
|
||||||
if (responseDto == null)
|
|
||||||
{
|
|
||||||
logger.LogWarning(
|
|
||||||
$"User {user.Username ?? user.UserId.ToString()} access token accept completed with error " +
|
|
||||||
$"{nameof(Status.HeadHunterResponseDeserializationFailedError)}");
|
|
||||||
return Status.HeadHunterResponseDeserializationFailedError;
|
|
||||||
}
|
|
||||||
|
|
||||||
user.RefreshToken = responseDto.RefreshToken;
|
|
||||||
user.AccessToken = responseDto.AccessToken;
|
|
||||||
await dbContext.SaveChangesAsync();
|
|
||||||
|
|
||||||
return Status.Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetRedirectUrl(long userId)
|
private string GetRedirectUrl(long userId)
|
||||||
{
|
{
|
||||||
return new UriBuilder(_config.Links.HookDomain)
|
return new UriBuilder(_config.Links.HookDomain)
|
||||||
|
@ -1,68 +0,0 @@
|
|||||||
using System.Net.Http.Headers;
|
|
||||||
using System.Text.Json;
|
|
||||||
using JOBot.Backend.DAL.Context;
|
|
||||||
using JOBot.Backend.DTOs.HeadHunterApi;
|
|
||||||
using JOBot.Backend.Infrastructure.Config;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
|
|
||||||
namespace JOBot.Backend.Services;
|
|
||||||
|
|
||||||
public class ResumeService(
|
|
||||||
AppDbContext dbContext,
|
|
||||||
ILogger<ResumeService> logger,
|
|
||||||
IOptions<HeadHunterConfig> config,
|
|
||||||
HeadHunterService headHunterService)
|
|
||||||
{
|
|
||||||
public async Task<(Status Status, List<Resume>? Resume)> GetAvailableResumes(long userId)
|
|
||||||
{
|
|
||||||
var user = await dbContext.Users.FirstOrDefaultAsync(x => x.UserId == userId);
|
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
return new(Status.UserNotFound, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user.ExpiresIn.HasValue || new DateTime().AddSeconds(user.ExpiresIn.Value) > DateTime.Now)
|
|
||||||
{
|
|
||||||
var status = await headHunterService.UpdateUserAccessToken(user);
|
|
||||||
if (status != HeadHunterService.Status.Success)
|
|
||||||
{
|
|
||||||
logger.LogError($"User {userId} has expired access and update of it was unsuccessful: {status}");
|
|
||||||
return (Status.TokenExpired, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
using var client = new HttpClient(); //TODO: Написать wrapper для работы с HH API
|
|
||||||
client.BaseAddress = new UriBuilder(config.Value.Links.HeadHunterApiDomain)
|
|
||||||
{
|
|
||||||
Port = -1,
|
|
||||||
Scheme = "https"
|
|
||||||
}.Uri;
|
|
||||||
client.DefaultRequestHeaders.UserAgent.ParseAdd("Jobot BackEnd Service");
|
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", user.AccessToken);
|
|
||||||
|
|
||||||
using var res = await client.GetAsync("/resumes/mine");
|
|
||||||
|
|
||||||
if (!res.IsSuccessStatusCode)
|
|
||||||
{
|
|
||||||
logger.LogWarning(
|
|
||||||
$"User {user.Username ?? user.UserId.ToString()} resume list is unavailable by unsuccessful status code: {res.StatusCode}");
|
|
||||||
return new(Status.RequestError, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
var responseDto = JsonSerializer.Deserialize<ListOfResumeResponseDto>(await res.Content.ReadAsStringAsync());
|
|
||||||
if (responseDto == null)
|
|
||||||
return new(Status.Error, null);
|
|
||||||
|
|
||||||
return new(Status.Success, responseDto.Items);
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum Status
|
|
||||||
{
|
|
||||||
Success,
|
|
||||||
UserNotFound,
|
|
||||||
Error,
|
|
||||||
RequestError,
|
|
||||||
TokenExpired
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
using Grpc.Core;
|
|
||||||
using JOBot.Backend.DAL.Context;
|
|
||||||
using JOBot.Proto;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace JOBot.Backend.Services.gRPC;
|
|
||||||
|
|
||||||
public class ResumeService(AppDbContext dbContext, Backend.Services.ResumeService resumeService)
|
|
||||||
: Proto.Resume.ResumeBase
|
|
||||||
{
|
|
||||||
public override async Task<GetResumeResponse> GetResume(GetResumeRequest request, ServerCallContext context)
|
|
||||||
{
|
|
||||||
var user = await dbContext.Users.FirstOrDefaultAsync(x => x.UserId == request.UserId);
|
|
||||||
if (user == null)
|
|
||||||
throw new RpcException(new Status(StatusCode.NotFound, "User not found"));
|
|
||||||
|
|
||||||
return new GetResumeResponse { ResumeUrl = user.CvUrl };
|
|
||||||
}
|
|
||||||
|
|
||||||
public override async Task<GetAvailableResponse> GetAvailable(GetAvailableRequest request,
|
|
||||||
ServerCallContext context)
|
|
||||||
{
|
|
||||||
var response = await resumeService.GetAvailableResumes(request.UserId);
|
|
||||||
|
|
||||||
switch (response.Status)
|
|
||||||
{
|
|
||||||
case Services.ResumeService.Status.UserNotFound:
|
|
||||||
throw new RpcException(new Status(StatusCode.NotFound, "User not found"));
|
|
||||||
case Services.ResumeService.Status.Error:
|
|
||||||
throw new RpcException(new Status(StatusCode.Internal, "Unknown error"));
|
|
||||||
case Services.ResumeService.Status.Success:
|
|
||||||
{
|
|
||||||
var resp = new GetAvailableResponse();
|
|
||||||
resp.Resumes.AddRange(response.Resume!.ConvertAll(x => new ResumeDesc
|
|
||||||
{
|
|
||||||
Name = x.Title,
|
|
||||||
ResumeUrl = x.Url
|
|
||||||
}));
|
|
||||||
|
|
||||||
return resp;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
throw new RpcException(new Status(StatusCode.Unimplemented, "Unimplemented statement"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -32,9 +32,6 @@
|
|||||||
<None Update="appsettings.Example.json">
|
<None Update="appsettings.Example.json">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
<None Update="appsettings.json">
|
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
|
||||||
</None>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -61,6 +58,12 @@
|
|||||||
</EmbeddedResource>
|
</EmbeddedResource>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="appsettings.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\JOBot.Infrastructure\JOBot.Infrastructure.csproj" />
|
<ProjectReference Include="..\JOBot.Infrastructure\JOBot.Infrastructure.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
option csharp_namespace = "JOBot.Proto";
|
|
||||||
|
|
||||||
import "google/protobuf/wrappers.proto";
|
|
||||||
|
|
||||||
service Resume{
|
|
||||||
rpc GetResume(GetResumeRequest) returns (GetResumeResponse);
|
|
||||||
rpc GetAvailable(GetAvailableRequest) returns (GetAvailableResponse);
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetResumeRequest{
|
|
||||||
int64 user_id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetResumeResponse{
|
|
||||||
google.protobuf.StringValue resumeUrl = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetAvailableRequest{
|
|
||||||
int64 user_id = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message GetAvailableResponse{
|
|
||||||
repeated ResumeDesc resumes = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message ResumeDesc{
|
|
||||||
string resumeUrl = 1;
|
|
||||||
string name = 2;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user