Kaynağa Gözat

Schedule backend implementation

pull/73/head
Dzenis Hadzifejzovic 3 yıl önce
ebeveyn
işleme
f372141f3a

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

@@ -9,6 +9,7 @@ namespace Diligent.WebAPI.Business.MappingProfiles
#region Models to DTOs
CreateMap<Applicant, ApplicantViewDto>();
CreateMap<Applicant, AdApplicantViewDto>();
CreateMap<Applicant, ApplicantScheduleViewDto>();
#endregion

#region DTOs to Models

+ 3
- 1
Diligent.WebAPI.Business/MappingProfiles/SelectionProcessMappingProfile.cs Dosyayı Görüntüle

@@ -1,4 +1,5 @@
using Diligent.WebAPI.Contracts.DTOs.SelectionProcess;
using Diligent.WebAPI.Contracts.DTOs.Schedule;
using Diligent.WebAPI.Contracts.DTOs.SelectionProcess;

namespace Diligent.WebAPI.Business.MappingProfiles
{
@@ -13,6 +14,7 @@ namespace Diligent.WebAPI.Business.MappingProfiles
#region Model to DTO
CreateMap<SelectionProcess, SelectionProcessResposneDto>();
CreateMap<SelectionProcess, SelectionProcessResposneWithoutApplicantDto>();
CreateMap<SelectionProcess, ScheduleViewDto>();
#endregion
}
}

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

@@ -0,0 +1,9 @@
using Diligent.WebAPI.Contracts.DTOs.Schedule;

namespace Diligent.WebAPI.Business.Services.Interfaces
{
public interface IScheduleService
{
Task<List<ScheduleViewDto>> GetScheduleForCertainPeriod(int month, int year);
}
}

+ 33
- 0
Diligent.WebAPI.Business/Services/ScheduleService.cs Dosyayı Görüntüle

@@ -0,0 +1,33 @@
using Diligent.WebAPI.Contracts.DTOs.Schedule;

namespace Diligent.WebAPI.Business.Services
{
public class ScheduleService : IScheduleService
{
private readonly DatabaseContext _context;
private readonly IMapper _mapper;
private readonly ILogger<ScheduleService> _logger;

public ScheduleService(DatabaseContext context, IMapper mapper,ILogger<ScheduleService> logger)
{
_context = context;
_mapper = mapper;
_logger = logger;
}
public async Task<List<ScheduleViewDto>> GetScheduleForCertainPeriod(int month, int year)
{
_logger.LogInformation("Start getting schedule for certain period");
_logger.LogInformation("Getting data from DB and filter");
var selectionProcessess = await _context.SelectionProcesses
.Include(c => c.Applicant)
.Include(c => c.SelectionLevel)
.Where(k => k.Date != null && k.Date.Value.Month == month && k.Date.Value.Year == year)
.ToListAsync();

_logger.LogInformation($"Got {selectionProcessess.Count} selection processes");

_logger.LogInformation($"Return schedule for certain period");
return _mapper.Map<List<ScheduleViewDto>>(selectionProcessess);
}
}
}

+ 8
- 0
Diligent.WebAPI.Contracts/DTOs/Applicant/ApplicantScheduleViewDto.cs Dosyayı Görüntüle

@@ -0,0 +1,8 @@
namespace Diligent.WebAPI.Contracts.DTOs.Applicant
{
public class ApplicantScheduleViewDto
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}

+ 14
- 0
Diligent.WebAPI.Contracts/DTOs/Schedule/ScheduleViewDto.cs Dosyayı Görüntüle

@@ -0,0 +1,14 @@
using Diligent.WebAPI.Contracts.DTOs.Applicant;
using Diligent.WebAPI.Contracts.DTOs.SelectionLevel;

namespace Diligent.WebAPI.Contracts.DTOs.Schedule
{
public class ScheduleViewDto
{
public DateTime? Date { get; set; }
public string? Link { get; set; }
public SelectionLevelResposneDto SelectionLevel { get; set; }
public ApplicantScheduleViewDto Applicant { get; set; }

}
}

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

@@ -0,0 +1,20 @@
namespace Diligent.WebAPI.Host.Controllers.V1
{
[ApiVersion("1.0")]
[Route("v{version:apiVersion}/schedule")]
[ApiController]
public class ScheduleController:ControllerBase
{
private readonly IScheduleService _scheduleService;

public ScheduleController(IScheduleService scheduleService)
{
_scheduleService = scheduleService;
}

[HttpGet]
public async Task<IActionResult> GetSchedule(int month,int year) =>
Ok(await _scheduleService.GetScheduleForCertainPeriod(month, year));
}
}

+ 1
- 0
Diligent.WebAPI.Host/Extensions/BusinessConfigurationExtension.cs Dosyayı Görüntüle

@@ -32,6 +32,7 @@
services.AddScoped<IAdService, AdService>();
services.AddScoped<ITechnologyService, TechnologyService>();
services.AddScoped<ICommentService, CommentService>();
services.AddScoped<IScheduleService, ScheduleService>();
}

/// <summary>

+ 1
- 1
Diligent.WebAPI.Tests/Controllers/ApplicantsControllerTests.cs Dosyayı Görüntüle

@@ -8,7 +8,7 @@ namespace Diligent.WebAPI.Tests.Controllers
{
public class ApplicantsControllerTests
{
private IApplicantService _applicantService = Substitute.For<IApplicantService>();
private readonly IApplicantService _applicantService = Substitute.For<IApplicantService>();
private readonly ApplicantViewDto _applicant;
public ApplicantsControllerTests()
{

+ 2
- 8
Diligent.WebAPI.Tests/Controllers/CommentsControllerTests.cs Dosyayı Görüntüle

@@ -4,17 +4,12 @@ namespace Diligent.WebAPI.Tests.Controllers
{
public class CommentsControllerTests
{
private ICommentService _commentService = Substitute.For<ICommentService>();
public CommentsControllerTests()
{

}
private readonly ICommentService _commentService = Substitute.For<ICommentService>();

[Fact]
public async Task Addcomment_ShouldReturn_201Created_Always()
{
int count = 0;
_commentService.When(x => x.CreateComment(Arg.Any<CommentCreateDto>())).Do(x => { count++; });
_commentService.When(x => x.CreateComment(Arg.Any<CommentCreateDto>())).Do(x => { });
CommentsController commentsController = new(_commentService);

CommentCreateDto commentCreateDto = new()
@@ -22,7 +17,6 @@ namespace Diligent.WebAPI.Tests.Controllers
ApplicantId = 1000,
Content = "some text",
UserId = 1000,
UsersToNotify = new List<string>()
};
var result = await commentsController.AddComment(commentCreateDto);


+ 18
- 0
Diligent.WebAPI.Tests/Controllers/ScheduleControllerTests.cs Dosyayı Görüntüle

@@ -0,0 +1,18 @@
namespace Diligent.WebAPI.Tests.Controllers
{
public class ScheduleControllerTests
{
private IScheduleService _scheduleService = Substitute.For<IScheduleService>();

[Fact]
public async Task GetSchedule_ShouldReturn_200OK_Always()
{
_scheduleService.When(x => x.GetScheduleForCertainPeriod(Arg.Any<int>(), Arg.Any<int>())).Do(x => { });
ScheduleController scheduleController = new(_scheduleService);

var result = await scheduleController.GetSchedule(1000, 1000);

(result as OkObjectResult).StatusCode.Should().Be(200);
}
}
}

+ 3
- 3
Diligent.WebAPI.Tests/MockData.cs Dosyayı Görüntüle

@@ -34,9 +34,9 @@ namespace Diligent.WebAPI.Tests
TypeOfEmployment = Applicant.TypesOfEmployment.Intership,
SelectionProcesses = new List<SelectionProcess>
{
new SelectionProcess{ Id = 1, Status = "", Name = ""},
new SelectionProcess{ Id = 2, Status = "", Name = ""},
new SelectionProcess{ Id = 3, Status = "", Name = ""}
new SelectionProcess{ Status = "", Name = ""},
new SelectionProcess{ Status = "", Name = ""},
new SelectionProcess{ Status = "", Name = ""}
}
};
var applicants = new List<Applicant>

+ 0
- 6
Diligent.WebAPI.Tests/Services/ApplicantServiceTests.cs Dosyayı Görüntüle

@@ -1,15 +1,11 @@
using AutoMapper;
using Castle.Core.Logging;
using Diligent.WebAPI.Business.Extensions;
using Diligent.WebAPI.Business.MappingProfiles;
using Diligent.WebAPI.Business.Services;
using Diligent.WebAPI.Contracts.DTOs.Ad;
using Diligent.WebAPI.Contracts.DTOs.Applicant;
using Diligent.WebAPI.Contracts.Exceptions;
using Diligent.WebAPI.Data.Entities;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using static Diligent.WebAPI.Data.Entities.Applicant;

namespace Diligent.WebAPI.Tests.Services
{
@@ -17,7 +13,6 @@ namespace Diligent.WebAPI.Tests.Services
{
private readonly IMapper _mapper;
private ILogger<ApplicantService> _logger = Substitute.For<ILogger<ApplicantService>>();
private readonly HttpContext _httpContext;
private readonly List<Applicant> _applicants;
private readonly List<Ad> _ads;
public ApplicantServiceTests()
@@ -35,7 +30,6 @@ namespace Diligent.WebAPI.Tests.Services
new SelectionProcessMappingProfile()
}));
_mapper = new Mapper(configuration);
_httpContext = new DefaultHttpContext();
}

[Fact]

+ 38
- 0
Diligent.WebAPI.Tests/Services/ScheduleServiceTests.cs Dosyayı Görüntüle

@@ -0,0 +1,38 @@
using AutoMapper;
using Diligent.WebAPI.Business.MappingProfiles;
using Diligent.WebAPI.Business.Services;
using Diligent.WebAPI.Contracts.DTOs.Schedule;
using Diligent.WebAPI.Data.Entities;
using Microsoft.Extensions.Logging;

namespace Diligent.WebAPI.Tests.Services
{
public class ScheduleServiceTests
{
private readonly IMapper _mapper;
private ILogger<ScheduleService> _logger = Substitute.For<ILogger<ScheduleService>>();
public ScheduleServiceTests()
{
var configuration = new MapperConfiguration(cfg => cfg.AddProfiles(
new List<Profile>
{
new ApplicantMappingProfile(),
new SelectionProcessMappingProfile(),
new SelectionLevelMappingProfile()
}));
_mapper = new Mapper(configuration);
}

[Fact]
public async Task GetScheduleForCertainPeriod_ShouldReturnListOfSchedules_Always()
{
var selectionProcesses = MockData.GetListOfSelectionProcess();
var databaseContext = await Helpers<SelectionProcess>.GetDatabaseContext(selectionProcesses);
ScheduleService scheduleService = new(databaseContext, _mapper, _logger);

var result = await scheduleService.GetScheduleForCertainPeriod(DateTime.Now.Month, DateTime.Now.Year);

result.Should().BeEquivalentTo(_mapper.Map<List<ScheduleViewDto>>(selectionProcesses));
}
}
}

Loading…
İptal
Kaydet