| @@ -44,5 +44,15 @@ namespace Diligent.WebAPI.Business.Helper | |||
| "</div>" + | |||
| "</div>"; | |||
| } | |||
| public static string RenderTagPage(string url) | |||
| { | |||
| return "<div>" + | |||
| "<a style = \"color: white;text-decoration:none;background-color: #017397;cursor: pointer;font-size: 20px;border-radius: 5px;padding: 5px 15px;height: 25px;margin-top:10px;\" " + | |||
| $"href=\"{url}\">" + | |||
| "Click here to see the comment" + | |||
| "</a>" + | |||
| "</div>"; | |||
| } | |||
| } | |||
| } | |||
| @@ -2,21 +2,33 @@ | |||
| { | |||
| public class CommentService : ICommentService | |||
| { | |||
| private readonly FrontEndSettings _frontEndSettings; | |||
| private readonly DatabaseContext _context; | |||
| private readonly IMapper _mapper; | |||
| private readonly ILogger<CommentService> _logger; | |||
| private readonly IEmailer _emailer; | |||
| public CommentService(DatabaseContext context, IMapper mapper, ILogger<CommentService> logger) | |||
| public CommentService(IOptions<FrontEndSettings> frontEndSettings,DatabaseContext context, IMapper mapper, ILogger<CommentService> logger,IEmailer emailer) | |||
| { | |||
| _frontEndSettings = frontEndSettings.Value; | |||
| _context = context; | |||
| _mapper = mapper; | |||
| _logger = logger; | |||
| _emailer = emailer; | |||
| } | |||
| public async Task CreateComment(CommentCreateDto commentCreateDto) | |||
| { | |||
| _logger.LogInformation("Start creating comment"); | |||
| var comment = _mapper.Map<Comment>(commentCreateDto); | |||
| if(commentCreateDto.UsersToNotify.Count > 0) | |||
| { | |||
| _logger.LogInformation("Start sending emails"); | |||
| await _emailer.SendEmailAsync(commentCreateDto.UsersToNotify, "You're tagged in comment by another user", | |||
| HTMLHelper.RenderTagPage($"{_frontEndSettings.BaseUrl}/candidates/{commentCreateDto.ApplicantId}"), isHtml: true); | |||
| _logger.LogInformation("Emails send successfully"); | |||
| } | |||
| comment.DateOfSending = DateTime.Now; | |||
| _logger.LogInformation($"Comment created successfully in {comment.DateOfSending}"); | |||
| @@ -7,8 +7,8 @@ namespace Diligent.WebAPI.Business.Services.Interfaces | |||
| Task<List<AdApplicantsViewDto>> GetAllAdsApplicants(ApplicantFilterDto applicantFilterDto); | |||
| Task<ApplicantViewDto> GetById(int id); | |||
| Task<ApplicantViewDto> GetApplicantWithSelectionProcessesById(int id); | |||
| //Task CreateApplicant(ApplicantCreateDto applicantCreateDto); | |||
| Task DeleteApplicant(int id); | |||
| //Task CreateApplicant(ApplicantCreateDto applicantCreateDto); | |||
| //Task UpdateApplicant(int id, ApplicantUpdateDto applicantUpdateDto); | |||
| } | |||
| } | |||
| @@ -5,5 +5,6 @@ | |||
| public string Content { get; set; } | |||
| public int UserId { get; set; } | |||
| public int ApplicantId { get; set; } | |||
| public List<string> UsersToNotify { get; set; } //email | |||
| } | |||
| } | |||
| @@ -24,7 +24,7 @@ namespace Diligent.WebAPI.Host.Controllers.V1 | |||
| Ok(await _applicantService.GetById(id)); | |||
| //[Authorize] | |||
| [Authorize] | |||
| [HttpGet("adsApplicants")] | |||
| public async Task<IActionResult> GetAllAdsApplicants([FromQuery]ApplicantFilterDto applicantFilterDto) => | |||
| Ok(await _applicantService.GetAllAdsApplicants(applicantFilterDto)); | |||
| @@ -1,4 +1,6 @@ | |||
| namespace Diligent.WebAPI.Tests.Controllers | |||
| using Diligent.WebAPI.Contracts.DTOs.Comment; | |||
| namespace Diligent.WebAPI.Tests.Controllers | |||
| { | |||
| public class CommentsControllerTests | |||
| { | |||
| @@ -8,10 +10,23 @@ | |||
| } | |||
| //[Fact] | |||
| //public async AddComment_ShouldReturn_200_Created_Always() | |||
| //{ | |||
| // _commentService.Add | |||
| //} | |||
| [Fact] | |||
| public async Task Addcomment_ShouldReturn_201Created_Always() | |||
| { | |||
| int count = 0; | |||
| _commentService.When(x => x.CreateComment(Arg.Any<CommentCreateDto>())).Do(x => { count++; }); | |||
| CommentsController commentsController = new(_commentService); | |||
| CommentCreateDto commentCreateDto = new() | |||
| { | |||
| ApplicantId = 1000, | |||
| Content = "some text", | |||
| UserId = 1000, | |||
| UsersToNotify = new List<string>() | |||
| }; | |||
| var result = await commentsController.AddComment(commentCreateDto); | |||
| (result as StatusCodeResult).StatusCode.Should().Be(201); | |||
| } | |||
| } | |||
| } | |||
| @@ -1,10 +1,12 @@ | |||
| using AutoMapper; | |||
| using Diligent.WebAPI.Business.MappingProfiles; | |||
| using Diligent.WebAPI.Business.Services; | |||
| using Diligent.WebAPI.Business.Settings; | |||
| using Diligent.WebAPI.Contracts.DTOs.Comment; | |||
| using Diligent.WebAPI.Data.Entities; | |||
| using Microsoft.EntityFrameworkCore; | |||
| using Microsoft.Extensions.Logging; | |||
| using Microsoft.Extensions.Options; | |||
| namespace Diligent.WebAPI.Tests.Services | |||
| { | |||
| @@ -34,13 +36,17 @@ namespace Diligent.WebAPI.Tests.Services | |||
| public async Task CreateComment_ShouldUpdatedListOfComments_Always() | |||
| { | |||
| var databaseContext = await Helpers<Comment>.GetDatabaseContext(_comments); | |||
| CommentService applicantService = new(databaseContext, _mapper, _logger); | |||
| var frontSettings = Substitute.For<IOptions<FrontEndSettings>>(); | |||
| var mailer = Substitute.For<IEmailer>(); | |||
| CommentService applicantService = new(frontSettings,databaseContext, _mapper, _logger, mailer); | |||
| var commentCreateDto = new CommentCreateDto | |||
| { | |||
| ApplicantId = _applicants[0].ApplicantId, | |||
| Content = "dsadasd", | |||
| UserId = _users[0].Id | |||
| UserId = _users[0].Id, | |||
| UsersToNotify = new List<string>() | |||
| }; | |||
| await applicantService.CreateComment(commentCreateDto); | |||