Kaynağa Gözat

implemented statistices endpoint

pull/78/head
meris.ahmatovic 3 yıl önce
ebeveyn
işleme
43b49c01e1

+ 2
- 0
Diligent.WebAPI.Business/MappingProfiles/AdMappingProfile.cs Dosyayı Görüntüle

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

+ 5
- 1
Diligent.WebAPI.Business/Services/AdService.cs Dosyayı Görüntüle

@@ -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}");

+ 1
- 0
Diligent.WebAPI.Business/Services/Interfaces/IAdService.cs Dosyayı Görüntüle

@@ -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);


+ 3
- 0
Diligent.WebAPI.Business/Services/Interfaces/ISelectionProcessService.cs Dosyayı Görüntüle

@@ -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);

}
}

+ 17
- 1
Diligent.WebAPI.Business/Services/SelectionProcessService.cs Dosyayı Görüntüle

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

+ 18
- 0
Diligent.WebAPI.Contracts/DTOs/Ad/AdResponseWithCountDto.cs Dosyayı Görüntüle

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

+ 9
- 0
Diligent.WebAPI.Contracts/DTOs/Stats/SelectionLevelInfoDto.cs Dosyayı Görüntüle

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

+ 27
- 0
Diligent.WebAPI.Host/Controllers/V1/StatsController.cs Dosyayı Görüntüle

@@ -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()
});
}
}
}

Loading…
İptal
Kaydet