| @@ -14,6 +14,8 @@ namespace Diligent.WebAPI.Business.MappingProfiles | |||
| CreateMap<Ad, AdResponseDto>(); | |||
| CreateMap<Ad, AdDetailsResponseDto>(); | |||
| CreateMap<Ad, AdApplicantsViewDto>(); | |||
| CreateMap<Ad, AdResponseWithCountDto>() | |||
| .ForMember(dest => dest.Count, opt => opt.MapFrom(x => x.Applicants.Count)); | |||
| #endregion | |||
| } | |||
| } | |||
| @@ -28,7 +28,11 @@ | |||
| _logger.LogInformation($"Ads has been mapped and received to client: {result.Count} mapped ads"); | |||
| return result; | |||
| } | |||
| public async Task<List<AdResponseWithCountDto>> GetAllWithCountAsync() | |||
| { | |||
| var today = DateTime.Now; | |||
| return _mapper.Map<List<AdResponseWithCountDto>>(await _context.Ads.Include(x => x.Applicants).Where(x => x.ExpiredAt > today).ToListAsync()); | |||
| } | |||
| public async Task<AdResponseDto> GetByIdAsync(int id) | |||
| { | |||
| _logger.LogInformation($"Start searching Ad with id = {id}"); | |||
| @@ -4,6 +4,7 @@ namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| public interface IAdService | |||
| { | |||
| Task<List<AdResponseDto>> GetAllAsync(); | |||
| Task<List<AdResponseWithCountDto>> GetAllWithCountAsync(); | |||
| Task<AdResponseDto> GetByIdAsync(int id); | |||
| @@ -1,5 +1,6 @@ | |||
| | |||
| using Diligent.WebAPI.Contracts.DTOs.SelectionProcess; | |||
| using Diligent.WebAPI.Contracts.DTOs.Stats; | |||
| namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| { | |||
| @@ -7,5 +8,7 @@ namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| { | |||
| Task<List<SelectionProcessResposneDto>> GetAllAsync(); | |||
| Task<bool> FinishSelectionProcess(SelectionProcessCreateDto model); | |||
| Task<List<SelectionLevelInfoDto>> GetCountByLevels(List<string> statuses); | |||
| } | |||
| } | |||
| @@ -1,4 +1,6 @@ | |||
| namespace Diligent.WebAPI.Business.Services | |||
| using Diligent.WebAPI.Contracts.DTOs.Stats; | |||
| namespace Diligent.WebAPI.Business.Services | |||
| { | |||
| public class SelectionProcessService : ISelectionProcessService | |||
| { | |||
| @@ -63,5 +65,19 @@ | |||
| _logger.LogError($"Saved changes to db"); | |||
| return result; | |||
| } | |||
| public async Task<List<SelectionLevelInfoDto>> GetCountByLevels(List<string> statuses) | |||
| { | |||
| var res = await _context.SelectionLevels.Include(n => n.SelectionProcesses).ToListAsync(); | |||
| var resMapped = res.Select(n => new SelectionLevelInfoDto | |||
| { | |||
| Level = n.Name, | |||
| CountAll = n.SelectionProcesses.Count, | |||
| CountDone = n.SelectionProcesses.Where(n => statuses.Contains(n.Status)).Count() | |||
| }).ToList(); | |||
| return resMapped; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,18 @@ | |||
| using Diligent.WebAPI.Contracts.DTOs.Technology; | |||
| namespace Diligent.WebAPI.Contracts.DTOs.Ad | |||
| { | |||
| public class AdResponseWithCountDto | |||
| { | |||
| public int Id { get; set; } | |||
| public string Title { get; set; } | |||
| public int MinimumExperience { get; set; } | |||
| public DateTime CreatedAt { get; set; } | |||
| public DateTime ExpiredAt { get; set; } | |||
| public int Count { get; set; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| namespace Diligent.WebAPI.Contracts.DTOs.Stats | |||
| { | |||
| public class SelectionLevelInfoDto | |||
| { | |||
| public string Level { get; set; } | |||
| public int CountAll { get; set; } | |||
| public int CountDone { get; set; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,27 @@ | |||
| namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| { | |||
| [ApiVersion("1.0")] | |||
| [Route("v{version:apiVersion}/stats")] | |||
| [ApiController] | |||
| public class StatsController : ControllerBase | |||
| { | |||
| private readonly ISelectionProcessService _selectionProcessService; | |||
| private readonly IAdService _adService; | |||
| public StatsController(ISelectionProcessService selectionProcessService, IAdService adService) | |||
| { | |||
| _selectionProcessService = selectionProcessService; | |||
| _adService = adService; | |||
| } | |||
| [HttpGet] | |||
| public async Task<IActionResult> GetStats() | |||
| { | |||
| return Ok(new | |||
| { | |||
| Levels = await _selectionProcessService.GetCountByLevels(new List<string> { "Odrađen" }), | |||
| Ads = await _adService.GetAllWithCountAsync() | |||
| }); | |||
| } | |||
| } | |||
| } | |||