浏览代码

Merge branch 'feature/1520_apply_for_an_ad_be' of Neca/HRCenter into BE_dev

pull/111/head
父节点
当前提交
206d98803e

+ 58
- 1
Diligent.WebAPI.Business/Services/ApplicantService.cs 查看文件

@@ -1,4 +1,6 @@
namespace Diligent.WebAPI.Business.Services
using static Diligent.WebAPI.Data.Entities.Applicant;

namespace Diligent.WebAPI.Business.Services
{
public class ApplicantService : IApplicantService
{
@@ -111,6 +113,61 @@
return result;
}

public async Task ApplyForAAd(ApplyForAdRequestDto request)
{
_logger.LogInformation("Start applying for ad");
_logger.LogInformation("Find ad by id");
var ad = await _context.Ads.Where(x => x.Id == request.AdId).FirstOrDefaultAsync();

if (ad == null)
{
_logger.LogError($"Ad with {request.AdId} not found");
throw new EntityNotFoundException("Ad not found in database");
}

_logger.LogInformation($"Find sent technologies from FE in database");
var technologies = await _context.Technologies.Where(x => request.TechnologiesIds.Contains(x.TechnologyId)).ToListAsync();

_logger.LogInformation($"Create applicant instance with sent data");
Applicant applicant = new Applicant
{
FirstName = request.FirstName,
LastName = request.LastName,
Position = ad.Title,
DateOfApplication = DateTime.UtcNow,
CV = request.PdfFile,
Email = request.Email,
PhoneNumber = request.PhoneNumber,
GithubLink = request.GithubLink,
LinkedlnLink = request.LinkedinLink,
BitBucketLink = request.BitBucketLink,
Experience = request.Experience,
//TypeOfEmployment = (EmploymentTypes)Enum.Parse(typeof(EmploymentTypes), ad.EmploymentType, true),
TypeOfEmployment = ad.EmploymentType == EmploymentTypes.Intership ? TypesOfEmployment.Intership : TypesOfEmployment.Posao,
Comments = new(),
Ads = new List<Ad> { ad },
SelectionProcesses = new(),
TechnologyApplicants = new(),
ApplicationChannel = "Putem sajta"
};

_logger.LogInformation($"Saving applicant in database");
await _context.AddAsync(applicant);

await _context.SaveChangesAsync();
_logger.LogInformation($"Applicant saved in database");


_logger.LogInformation($"Saving TechnologyApplicants in database");
for (int i = 0; i < technologies.Count; i++)
{
await _context.ApplicantTechnologies.AddAsync(new TechnologyApplicant { Applicant = applicant, ApplicantId = applicant.ApplicantId, Technology = technologies[i], TechnologyId = technologies[i].TechnologyId });
}

await _context.SaveChangesAsync();
_logger.LogInformation($"TechnologyApplicants saved in database");
}

public async Task<List<ApplicantOptionsDTO>> GetOptions()
{
var res = await _context.Applicants.ToListAsync();

+ 1
- 0
Diligent.WebAPI.Business/Services/Interfaces/IApplicantService.cs 查看文件

@@ -9,6 +9,7 @@ namespace Diligent.WebAPI.Business.Services.Interfaces
Task<List<AdApplicantsViewDto>> GetAllAdsApplicants(ApplicantFilterDto applicantFilterDto);
Task<ApplicantViewDto> GetById(int id);
Task<ApplicantViewDto> GetApplicantWithSelectionProcessesById(int id);
Task ApplyForAAd(ApplyForAdRequestDto request);
Task DeleteApplicant(int id);
Task<List<ApplicantOptionsDTO>> GetOptions();
Task<ServiceResponseDTO<object>> InitializeProcess(ApplicantProcessRequestDTO model);

+ 37
- 0
Diligent.WebAPI.Contracts/DTOs/Applicant/ApplyForAdRequestDto.cs 查看文件

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

namespace Diligent.WebAPI.Contracts.DTOs.Applicant
{
public class ApplyForAdRequestDto
{
public int AdId { get; set; }

public string FirstName { get; set; }

public string LastName { get; set; }

public DateTime DateOfBirth { get; set; }

public string PhoneNumber { get; set; }

public int[] TechnologiesIds { get; set; }

public int Experience { get; set; }

public string LinkedinLink { get; set; }

public string GithubLink { get; set; }

public string BitBucketLink { get; set; }

public string Email { get; set; }

public string CoverLetter { get; set; }

public string PdfFile { get; set; }
}
}

+ 7
- 0
Diligent.WebAPI.Host/Controllers/V1/ApplicantsController.cs 查看文件

@@ -56,5 +56,12 @@ namespace Diligent.WebAPI.Host.Controllers.V1
return Ok();
}

[HttpPost("apply-for-ad")]
public async Task<IActionResult> ApplyForAd([FromBody]ApplyForAdRequestDto request)
{
await _applicantService.ApplyForAAd(request);

return Ok();
}
}
}

正在加载...
取消
保存