api performance changes
This commit is contained in:
parent
21e02ab3ca
commit
b3cb7b351f
@ -46,5 +46,120 @@ namespace PortBlog.API.Controllers
|
||||
return StatusCode(500, "A problem happened while handling your request.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetHobbies/{candidateId}")]
|
||||
public async Task<ActionResult<AboutDto>> GetHobbies(int candidateId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!await _candidateRepository.CandidateExistAsync(candidateId))
|
||||
{
|
||||
_logger.LogInformation($"Candidate with id {candidateId} wasn't found when fetching about details.");
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var aboutDetails = await _resumeRepository.GetHobbiesAsync(candidateId);
|
||||
|
||||
return Ok(_mapper.Map<AboutDto>(aboutDetails));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical($"Exception while getting about details for the candidate with id {candidateId}.", ex);
|
||||
return StatusCode(500, "A problem happened while handling your request.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetCandidateWithSocialLinks/{candidateId}")]
|
||||
public async Task<ActionResult<CandidateSocialLinksDto>> GetContact(int candidateId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!await _candidateRepository.CandidateExistAsync(candidateId))
|
||||
{
|
||||
_logger.LogInformation($"Candidate with id {candidateId} wasn't found when fetching candidate with social links.");
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var contact = await _resumeRepository.GetCandidateWithSocialLinksAsync(candidateId);
|
||||
|
||||
return Ok(_mapper.Map<CandidateSocialLinksDto>(contact));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical($"Exception while getting contact for the candidate with social links with id {candidateId}.", ex);
|
||||
return StatusCode(500, "A problem happened while handling your request.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetResume/{candidateId}")]
|
||||
public async Task<ActionResult<ResumeDto>> GetResume(int candidateId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!await _candidateRepository.CandidateExistAsync(candidateId))
|
||||
{
|
||||
_logger.LogInformation($"Candidate with id {candidateId} wasn't found when fetching resume.");
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var resume = await _resumeRepository.GetResumeAsync(candidateId);
|
||||
|
||||
return Ok(_mapper.Map<ResumeDto>(resume));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical($"Exception while getting resume for the candidate with id {candidateId}.", ex);
|
||||
return StatusCode(500, "A problem happened while handling your request.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetProjects/{candidateId}")]
|
||||
public async Task<ActionResult<ProjectsDto>> GetProjects(int candidateId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!await _candidateRepository.CandidateExistAsync(candidateId))
|
||||
{
|
||||
_logger.LogInformation($"Candidate with id {candidateId} wasn't found when fetching projects.");
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var projects = await _resumeRepository.GetProjectsAsync(candidateId);
|
||||
|
||||
return Ok(_mapper.Map<ProjectsDto>(projects));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical($"Exception while getting projects for the candidate with id {candidateId}.", ex);
|
||||
return StatusCode(500, "A problem happened while handling your request.");
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet("GetBlog/{candidateId}")]
|
||||
public async Task<ActionResult<BlogDto>> GetBlog(int candidateId)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!await _candidateRepository.CandidateExistAsync(candidateId))
|
||||
{
|
||||
_logger.LogInformation($"Candidate with id {candidateId} wasn't found when fetching projects.");
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var blog = await _resumeRepository.GetBlogAsync(candidateId);
|
||||
|
||||
return Ok(_mapper.Map<BlogDto>(blog));
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogCritical($"Exception while getting projects for the candidate with id {candidateId}.", ex);
|
||||
return StatusCode(500, "A problem happened while handling your request.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace PortBlog.API.Entities
|
||||
{
|
||||
|
||||
9
PortBlog.API/Models/AboutDto.cs
Normal file
9
PortBlog.API/Models/AboutDto.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace PortBlog.API.Models
|
||||
{
|
||||
public class AboutDto
|
||||
{
|
||||
public string About { get; set; } = string.Empty;
|
||||
|
||||
public ICollection<HobbyDto> Hobbies { get; set; } = new List<HobbyDto>();
|
||||
}
|
||||
}
|
||||
@ -4,8 +4,6 @@ namespace PortBlog.API.Models
|
||||
{
|
||||
public class BlogDto
|
||||
{
|
||||
public int BlogId { get; set; }
|
||||
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
public string? Description { get; set; } = string.Empty;
|
||||
|
||||
11
PortBlog.API/Models/CandidateSocialLinksDto.cs
Normal file
11
PortBlog.API/Models/CandidateSocialLinksDto.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace PortBlog.API.Models
|
||||
{
|
||||
public class CandidateSocialLinksDto
|
||||
{
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
public CandidateDto? Candidate { get; set; }
|
||||
|
||||
public SocialLinksDto? SocialLinks { get; set; }
|
||||
}
|
||||
}
|
||||
15
PortBlog.API/Models/ProjectsDto.cs
Normal file
15
PortBlog.API/Models/ProjectsDto.cs
Normal file
@ -0,0 +1,15 @@
|
||||
namespace PortBlog.API.Models
|
||||
{
|
||||
public class ProjectsDto
|
||||
{
|
||||
public ICollection<ProjectDto> Projects { get; set; } = new List<ProjectDto>();
|
||||
|
||||
public ICollection<string> ProjectsCategories
|
||||
{
|
||||
get
|
||||
{
|
||||
return Projects.Select(p => p.Category).Distinct().ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -61,6 +61,9 @@ namespace PortBlog.API.Profiles
|
||||
src => src.MapFrom(src => src.Blog != null ? src.Blog.Posts : new List<Post>())
|
||||
);
|
||||
CreateMap<Resume, ResumeDto>();
|
||||
CreateMap<Resume, AboutDto>();
|
||||
CreateMap<Resume, CandidateSocialLinksDto>();
|
||||
CreateMap<Resume, ProjectsDto>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,6 +92,7 @@ if (app.Environment.IsDevelopment())
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
|
||||
app.UseStaticFiles(new StaticFileOptions()
|
||||
{
|
||||
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"Images")),
|
||||
|
||||
@ -5,5 +5,15 @@ namespace PortBlog.API.Repositories.Contracts
|
||||
public interface IResumeRepository
|
||||
{
|
||||
Task<Resume?> GetLatestResumeForCandidateAsync(int candidateId, bool includeOtherData = false);
|
||||
|
||||
Task<Resume?> GetHobbiesAsync(int candidateId);
|
||||
|
||||
Task<Resume?> GetResumeAsync(int candidateId);
|
||||
|
||||
Task<Resume?> GetCandidateWithSocialLinksAsync(int candidateId);
|
||||
|
||||
Task<Resume?> GetProjectsAsync(int candidateId);
|
||||
|
||||
Task<Blog?> GetBlogAsync(int candidate);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PortBlog.API.DbContexts;
|
||||
using PortBlog.API.Entities;
|
||||
using PortBlog.API.Models;
|
||||
using PortBlog.API.Repositories.Contracts;
|
||||
|
||||
namespace PortBlog.API.Repositories
|
||||
@ -35,5 +36,52 @@ namespace PortBlog.API.Repositories
|
||||
|
||||
return await _cvBlogContext.Resumes.Where(r => r.CandidateId == candidateId).OrderByDescending(r => r.Order).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<Resume?> GetHobbiesAsync(int candidateId)
|
||||
{
|
||||
return await _cvBlogContext.Resumes
|
||||
.Include(r => r.Hobbies)
|
||||
.Where(r => r.CandidateId == candidateId)
|
||||
.OrderByDescending(r => r.Order).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<Resume?> GetResumeAsync(int candidateId)
|
||||
{
|
||||
return await _cvBlogContext.Resumes
|
||||
.Include(r => r.Academics.OrderByDescending(a => a.StartYear))
|
||||
.Include(r => r.Experiences.OrderByDescending(e => e.StartDate))
|
||||
.Include(r => r.Skills)
|
||||
.Where(r => r.CandidateId == candidateId)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<Resume?> GetCandidateWithSocialLinksAsync(int candidateId)
|
||||
{
|
||||
return await _cvBlogContext.Resumes
|
||||
.Include(r => r.Candidate)
|
||||
.Include(r => r.SocialLinks)
|
||||
.Where(r => r.CandidateId == candidateId)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<Resume?> GetProjectsAsync(int candidateId)
|
||||
{
|
||||
return await _cvBlogContext.Resumes
|
||||
.Include(r => r.Projects)
|
||||
.Where(r => r.CandidateId == candidateId)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<Blog?> GetBlogAsync(int candidate)
|
||||
{
|
||||
var result = await _cvBlogContext.Resumes
|
||||
.Include(r => r.SocialLinks)
|
||||
.ThenInclude(s => s.Blog)
|
||||
.ThenInclude(b => b.Posts.OrderByDescending(p => p.Likes).Take(5))
|
||||
.Where(r => r.CandidateId == candidate)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
return result?.SocialLinks?.Blog;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user