Sfoglia il codice sorgente

Merge branch 'feature/1582_applicant_details_page-b' of Neca/HRCenter into BE_dev

pull/42/head
safet.purkovic 3 anni fa
parent
commit
6a521229b7

+ 4
- 0
Diligent.WebAPI.Business/MappingProfiles/CommentMappingProfile.cs Vedi File

@@ -9,6 +9,10 @@ namespace Diligent.WebAPI.Business.MappingProfiles
#region Models to DTO
CreateMap<Comment, CommentViewDto>();
#endregion

#region DTO to Model
CreateMap<CommentCreateDto, Comment>();
#endregion
}
}
}

+ 2
- 1
Diligent.WebAPI.Business/MappingProfiles/TechnologyMappingProfile.cs Vedi File

@@ -7,7 +7,8 @@ namespace Diligent.WebAPI.Business.MappingProfiles
{
#region Model to DTO
CreateMap<Technology, TechnologyResponseDto>();
CreateMap<TechnologyApplicant, TechnologyResponseDto>();
//CreateMap<TechnologyApplicant, TechnologyResponseDto>(); -- ermin
CreateMap<TechnologyApplicant, TechnologyViewDto>();
#endregion
}
}

+ 5
- 2
Diligent.WebAPI.Business/Services/ApplicantService.cs Vedi File

@@ -15,17 +15,20 @@ namespace Diligent.WebAPI.Business.Services

public async Task<List<ApplicantViewDto>> GetAll()
{
var applicants = await _context.Applicants.ToListAsync();
var applicants = await _context.Applicants.Include(c => c.Ads).ToListAsync();
return _mapper.Map<List<ApplicantViewDto>>(applicants);
}

public async Task<ApplicantViewDto> GetById(int id)
{
var applicant = await _context.Applicants
.Include(x => x.Ads)
.ThenInclude(x => x.Technologies)
.Include(x => x.TechnologyApplicants)
.ThenInclude(x => x.Technology)
.Include(x => x.Comments)
.ThenInclude(t => t.User)
.FirstOrDefaultAsync(a => a.ApplicantId == id);
.FirstOrDefaultAsync(x => x.ApplicantId == id);

if (applicant is null)
throw new EntityNotFoundException("Applicant not found");

+ 26
- 0
Diligent.WebAPI.Business/Services/CommentService.cs Vedi File

@@ -0,0 +1,26 @@
using Diligent.WebAPI.Contracts.DTOs.Comment;

namespace Diligent.WebAPI.Business.Services
{
public class CommentService : ICommentService
{
private readonly DatabaseContext _context;
private readonly IMapper _mapper;

public CommentService(DatabaseContext context, IMapper mapper)
{
_context = context;
_mapper = mapper;
}
public async Task CreateComment(CommentCreateDto commentCreateDto)
{
var comment = _mapper.Map<Comment>(commentCreateDto);

comment.DateOfSending = DateTime.Now;

await _context.Comments.AddAsync(comment);

await _context.SaveChangesAsync();
}
}
}

+ 9
- 0
Diligent.WebAPI.Business/Services/Interfaces/ICommentService.cs Vedi File

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

namespace Diligent.WebAPI.Business.Services.Interfaces
{
public interface ICommentService
{
Task CreateComment(CommentCreateDto commentCreateDto);
}
}

+ 2
- 0
Diligent.WebAPI.Business/Services/Interfaces/ITechnologyService.cs Vedi File

@@ -4,7 +4,9 @@ namespace Diligent.WebAPI.Business.Services.Interfaces
public interface ITechnologyService
{
Task<List<TechnologyResponseDto>> GetAllAsync();
Task<List<TechnologyApplicantViewDto>> GetAllAsync2();

Task<TechnologyResponseDto> GetByIdAsync(int id);
Task<TechnologyApplicantViewDto> GetByIdAsync2(int id);
}
}

+ 14
- 0
Diligent.WebAPI.Business/Services/TechnologyService.cs Vedi File

@@ -20,6 +20,10 @@ namespace Diligent.WebAPI.Business.Services
public async Task<List<TechnologyResponseDto>> GetAllAsync() =>
_mapper.Map<List<TechnologyResponseDto>>(await _context.Technologies.ToListAsync());

public async Task<List<TechnologyApplicantViewDto>> GetAllAsync2() =>
_mapper.Map<List<TechnologyApplicantViewDto>>(await _context.Technologies.ToListAsync());

public async Task<TechnologyResponseDto> GetByIdAsync(int id)
{
var technology = await _context.Technologies.FindAsync(id);
@@ -29,5 +33,15 @@ namespace Diligent.WebAPI.Business.Services

return _mapper.Map<TechnologyResponseDto>(technology);
}

public async Task<TechnologyApplicantViewDto> GetByIdAsync2(int id)
{
var technology = await _context.Technologies.FindAsync(id);

if (technology is null)
throw new EntityNotFoundException("Technology not found");

return _mapper.Map<TechnologyApplicantViewDto>(technology);
}
}
}

+ 1
- 1
Diligent.WebAPI.Contracts/DTOs/Ad/AdDetailsResponseDto.cs Vedi File

@@ -34,7 +34,7 @@ namespace Diligent.WebAPI.Contracts.DTOs.Ad

private int CalculateTotalApplicants()
{
return Applicants.Count();
return Applicants.Count;
}
}
}

+ 4
- 2
Diligent.WebAPI.Contracts/DTOs/Applicant/ApplicantViewDto.cs Vedi File

@@ -1,4 +1,5 @@
using Diligent.WebAPI.Contracts.DTOs.Comment;
using Diligent.WebAPI.Contracts.DTOs.Ad;
using Diligent.WebAPI.Contracts.DTOs.Comment;
using Diligent.WebAPI.Contracts.DTOs.Technology;

namespace Diligent.WebAPI.Contracts.DTOs.Applicant
@@ -18,7 +19,8 @@ namespace Diligent.WebAPI.Contracts.DTOs.Applicant
public string BitBucketLink { get; set; }
public int Experience { get; set; }
public string ApplicationChannel { get; set; }
public List<TechnologyResponseDto> TechnologyApplicants { get; set; } = new();
public List<TechnologyViewDto> TechnologyApplicants { get; set; } = new();
public List<CommentViewDto> Comments { get; set; }
public List<AdResponseDto> Ads { get; set; }
}
}

+ 9
- 0
Diligent.WebAPI.Contracts/DTOs/Comment/CommentCreateDto.cs Vedi File

@@ -0,0 +1,9 @@
namespace Diligent.WebAPI.Contracts.DTOs.Comment
{
public class CommentCreateDto
{
public string Content { get; set; }
public int UserId { get; set; }
public int ApplicantId { get; set; }
}
}

+ 0
- 1
Diligent.WebAPI.Contracts/DTOs/Comment/CommentViewDto.cs Vedi File

@@ -4,7 +4,6 @@ namespace Diligent.WebAPI.Contracts.DTOs.Comment
{
public class CommentViewDto
{
public int Id { get; set; }
public string Content { get; set; }
public DateTime DateOfSending { get; set; }
public UserResponseDTO User { get; set; }

+ 7
- 0
Diligent.WebAPI.Contracts/DTOs/Technology/TechnologyApplicantViewDto.cs Vedi File

@@ -0,0 +1,7 @@
namespace Diligent.WebAPI.Contracts.DTOs.Technology
{
public class TechnologyApplicantViewDto
{
public TechnologyResponseDto Technology { get; set; }
}
}

+ 0
- 1
Diligent.WebAPI.Contracts/DTOs/Technology/TechnologyResponseDto.cs Vedi File

@@ -9,7 +9,6 @@ namespace Diligent.WebAPI.Contracts.DTOs.Technology
public class TechnologyResponseDto
{
public int TechnologyId { get; set; }

public string Name { get; set; }
}
}

+ 13
- 0
Diligent.WebAPI.Contracts/DTOs/Technology/TechnologyViewDto.cs Vedi File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Diligent.WebAPI.Contracts.DTOs.Technology
{
public class TechnologyViewDto
{
public TechnologyResponseDto Technology { get; set; }
}
}

+ 2
- 2
Diligent.WebAPI.Host/Controllers/V1/ApplicantsController.cs Vedi File

@@ -12,14 +12,14 @@
_applicantService = applicantService;
}

[Authorize]
//[Authorize]
[HttpGet]
public async Task<IActionResult> GetAll()
{
return Ok(await _applicantService.GetAll());
}

[Authorize]
//[Authorize]
[HttpGet("{id}")]
public async Task<IActionResult> GetById(int id)
{

+ 24
- 0
Diligent.WebAPI.Host/Controllers/V1/CommentsController.cs Vedi File

@@ -0,0 +1,24 @@
using Diligent.WebAPI.Contracts.DTOs.Comment;

namespace Diligent.WebAPI.Host.Controllers.V1
{
[ApiVersion("1.0")]
[Route("v{version:apiVersion}/comments")]
[ApiController]
public class CommentsController : ControllerBase
{
private readonly ICommentService _commentService;

public CommentsController(ICommentService commentService)
{
_commentService = commentService;
}
[Authorize]
[HttpPost]
public async Task<IActionResult> AddComment(CommentCreateDto commentCreateDto)
{
await _commentService.CreateComment(commentCreateDto);
return StatusCode((int)HttpStatusCode.Created);
}
}
}

+ 1
- 0
Diligent.WebAPI.Host/Extensions/BusinessConfigurationExtension.cs Vedi File

@@ -27,6 +27,7 @@
services.AddScoped<IAuthenticationService, AuthenticationService>();
services.AddScoped<IAdService, AdService>();
services.AddScoped<ITechnologyService, TechnologyService>();
services.AddScoped<ICommentService, CommentService>();
}

/// <summary>

+ 3
- 3
Diligent.WebAPI.Tests/Helpers.cs Vedi File

@@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore;

namespace Diligent.WebAPI.Tests
{
public static class Helpers
public static class Helpers<T> where T : class
{
public static async Task<DatabaseContext> GetDatabaseContext(List<Applicant> applicants)
public static async Task<DatabaseContext> GetDatabaseContext(List<T> applicants)
{
var options = new DbContextOptionsBuilder<DatabaseContext>()
.UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())
@@ -15,7 +15,7 @@ namespace Diligent.WebAPI.Tests
databaseContext.Database.EnsureCreated();
if (!await databaseContext.Applicants.AnyAsync())
{
await databaseContext.Applicants.AddRangeAsync(applicants);
await databaseContext.Set<T>().AddRangeAsync(applicants);
await databaseContext.SaveChangesAsync();
}
return databaseContext;

+ 7
- 7
Diligent.WebAPI.Tests/Services/ApplicantServiceTests.cs Vedi File

@@ -47,7 +47,7 @@ namespace Diligent.WebAPI.Tests.Services
[Fact]
public async Task GetAll_ShouldReturnListOfApplicants_Always()
{
var databaseContext = await Helpers.GetDatabaseContext(_applicants);
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper);

var result = await applicantService.GetAll();
@@ -58,7 +58,7 @@ namespace Diligent.WebAPI.Tests.Services
[Fact]
public async Task GetById_ShouldReturnApplicant_WhenApplicantExist()
{
var databaseContext = await Helpers.GetDatabaseContext(_applicants);
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper);

var result = await applicantService.GetById(1);
@@ -69,7 +69,7 @@ namespace Diligent.WebAPI.Tests.Services
[Fact]
public async Task GetById_ShouldThrowEntityNotFooundException_WhenApplicantDontExist()
{
var databaseContext = await Helpers.GetDatabaseContext(_applicants);
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper);

await Assert.ThrowsAsync<EntityNotFoundException>(async () => await applicantService.GetById(1000));
@@ -78,7 +78,7 @@ namespace Diligent.WebAPI.Tests.Services
[Fact]
public async Task CreateApplicant_ShouldAddEntityIntoDatabase_Always()
{
var databaseContext = await Helpers.GetDatabaseContext(_applicants);
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper);

ApplicantCreateDto applicantCreateDto = new()
@@ -106,7 +106,7 @@ namespace Diligent.WebAPI.Tests.Services
[Fact]
public async Task DeleteApplicant_ShouldDeleteApplicant_WhenApplicantExist()
{
var databaseContext = await Helpers.GetDatabaseContext(_applicants);
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper);

await applicantService.DeleteApplicant(1);
@@ -118,7 +118,7 @@ namespace Diligent.WebAPI.Tests.Services
[Fact]
public async Task DeleteApplicant_ShouldThrowEntityNotFooundException_WhenApplicantDontExist()
{
var databaseContext = await Helpers.GetDatabaseContext(_applicants);
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper);

await Assert.ThrowsAsync<EntityNotFoundException>(async () => await applicantService.DeleteApplicant(1000));
@@ -127,7 +127,7 @@ namespace Diligent.WebAPI.Tests.Services
[Fact]
public async Task UpdateApplicant_ShouldUpdateApplicant_WhenApplicantExist()
{
var databaseContext = await Helpers.GetDatabaseContext(_applicants);
var databaseContext = await Helpers<Applicant>.GetDatabaseContext(_applicants);
ApplicantService applicantService = new(databaseContext, _mapper);

ApplicantUpdateDto applicantUpdateDto = new()

Loading…
Annulla
Salva