Просмотр исходного кода

applicant details page

pull/70/head
Dzenis Hadzifejzovic 3 лет назад
Родитель
Сommit
5bc7dcae43

+ 10
- 0
Diligent.WebAPI.Business/Helper/HTMLHelper.cs Просмотреть файл

"</div>" + "</div>" +
"</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>";
}
} }
} }

+ 13
- 1
Diligent.WebAPI.Business/Services/CommentService.cs Просмотреть файл

{ {
public class CommentService : ICommentService public class CommentService : ICommentService
{ {
private readonly FrontEndSettings _frontEndSettings;
private readonly DatabaseContext _context; private readonly DatabaseContext _context;
private readonly IMapper _mapper; private readonly IMapper _mapper;
private readonly ILogger<CommentService> _logger; 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; _context = context;
_mapper = mapper; _mapper = mapper;
_logger = logger; _logger = logger;
_emailer = emailer;
} }
public async Task CreateComment(CommentCreateDto commentCreateDto) public async Task CreateComment(CommentCreateDto commentCreateDto)
{ {
_logger.LogInformation("Start creating comment"); _logger.LogInformation("Start creating comment");
var comment = _mapper.Map<Comment>(commentCreateDto); 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; comment.DateOfSending = DateTime.Now;
_logger.LogInformation($"Comment created successfully in {comment.DateOfSending}"); _logger.LogInformation($"Comment created successfully in {comment.DateOfSending}");



+ 1
- 1
Diligent.WebAPI.Business/Services/Interfaces/IApplicantService.cs Просмотреть файл

Task<List<AdApplicantsViewDto>> GetAllAdsApplicants(ApplicantFilterDto applicantFilterDto); Task<List<AdApplicantsViewDto>> GetAllAdsApplicants(ApplicantFilterDto applicantFilterDto);
Task<ApplicantViewDto> GetById(int id); Task<ApplicantViewDto> GetById(int id);
Task<ApplicantViewDto> GetApplicantWithSelectionProcessesById(int id); Task<ApplicantViewDto> GetApplicantWithSelectionProcessesById(int id);
//Task CreateApplicant(ApplicantCreateDto applicantCreateDto);
Task DeleteApplicant(int id); Task DeleteApplicant(int id);
//Task CreateApplicant(ApplicantCreateDto applicantCreateDto);
//Task UpdateApplicant(int id, ApplicantUpdateDto applicantUpdateDto); //Task UpdateApplicant(int id, ApplicantUpdateDto applicantUpdateDto);
} }
} }

+ 1
- 0
Diligent.WebAPI.Contracts/DTOs/Comment/CommentCreateDto.cs Просмотреть файл

public string Content { get; set; } public string Content { get; set; }
public int UserId { get; set; } public int UserId { get; set; }
public int ApplicantId { get; set; } public int ApplicantId { get; set; }
public List<string> UsersToNotify { get; set; } //email
} }
} }

+ 1
- 1
Diligent.WebAPI.Host/Controllers/V1/ApplicantsController.cs Просмотреть файл

Ok(await _applicantService.GetById(id)); Ok(await _applicantService.GetById(id));




//[Authorize]
[Authorize]
[HttpGet("adsApplicants")] [HttpGet("adsApplicants")]
public async Task<IActionResult> GetAllAdsApplicants([FromQuery]ApplicantFilterDto applicantFilterDto) => public async Task<IActionResult> GetAllAdsApplicants([FromQuery]ApplicantFilterDto applicantFilterDto) =>
Ok(await _applicantService.GetAllAdsApplicants(applicantFilterDto)); Ok(await _applicantService.GetAllAdsApplicants(applicantFilterDto));

+ 21
- 6
Diligent.WebAPI.Tests/Controllers/CommentsControllerTests.cs Просмотреть файл

namespace Diligent.WebAPI.Tests.Controllers
using Diligent.WebAPI.Contracts.DTOs.Comment;

namespace Diligent.WebAPI.Tests.Controllers
{ {
public class CommentsControllerTests public class CommentsControllerTests
{ {


} }


//[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);
}
} }
} }

+ 8
- 2
Diligent.WebAPI.Tests/Services/CommentServiceTests.cs Просмотреть файл

using AutoMapper; using AutoMapper;
using Diligent.WebAPI.Business.MappingProfiles; using Diligent.WebAPI.Business.MappingProfiles;
using Diligent.WebAPI.Business.Services; using Diligent.WebAPI.Business.Services;
using Diligent.WebAPI.Business.Settings;
using Diligent.WebAPI.Contracts.DTOs.Comment; using Diligent.WebAPI.Contracts.DTOs.Comment;
using Diligent.WebAPI.Data.Entities; using Diligent.WebAPI.Data.Entities;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;


namespace Diligent.WebAPI.Tests.Services namespace Diligent.WebAPI.Tests.Services
{ {
public async Task CreateComment_ShouldUpdatedListOfComments_Always() public async Task CreateComment_ShouldUpdatedListOfComments_Always()
{ {
var databaseContext = await Helpers<Comment>.GetDatabaseContext(_comments); 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 var commentCreateDto = new CommentCreateDto
{ {
ApplicantId = _applicants[0].ApplicantId, ApplicantId = _applicants[0].ApplicantId,
Content = "dsadasd", Content = "dsadasd",
UserId = _users[0].Id
UserId = _users[0].Id,
UsersToNotify = new List<string>()
}; };


await applicantService.CreateComment(commentCreateDto); await applicantService.CreateComment(commentCreateDto);

Загрузка…
Отмена
Сохранить