| @@ -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 | |||
| @@ -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 | |||
| } | |||
| } | |||
| @@ -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); | |||
| } | |||
| } | |||
| @@ -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); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,8 @@ | |||
| namespace Diligent.WebAPI.Contracts.DTOs.Applicant | |||
| { | |||
| public class ApplicantScheduleViewDto | |||
| { | |||
| public string FirstName { get; set; } | |||
| public string LastName { get; set; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -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)); | |||
| } | |||
| } | |||
| @@ -32,6 +32,7 @@ | |||
| services.AddScoped<IAdService, AdService>(); | |||
| services.AddScoped<ITechnologyService, TechnologyService>(); | |||
| services.AddScoped<ICommentService, CommentService>(); | |||
| services.AddScoped<IScheduleService, ScheduleService>(); | |||
| } | |||
| /// <summary> | |||
| @@ -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() | |||
| { | |||
| @@ -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); | |||
| @@ -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); | |||
| } | |||
| } | |||
| } | |||
| @@ -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> | |||
| @@ -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] | |||
| @@ -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)); | |||
| } | |||
| } | |||
| } | |||