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 config) { public async Task<(Status Status, List? 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(await res.Content.ReadAsStringAsync()); if (responseDto == null) return new(Status.Error, null); return new(Status.Success, responseDto.Items); } public enum Status { Success, UserNotFound, Error } }