feat: implemented available resumes on Back-end
This commit is contained in:
45
JOBot.Backend/Services/ResumeService.cs
Normal file
45
JOBot.Backend/Services/ResumeService.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
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,
|
||||
IOptions<HeadHunterConfig> config)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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");
|
||||
|
||||
using var res = await client.GetAsync("/resumes/mine");
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user