JOBot/JOBot.Backend/Services/ResumeService.cs

45 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}
}