Parcourir la source

Apply for an ad BE

pull/107/head
Ermin Bronja il y a 3 ans
Parent
révision
8fd96bce97

+ 58
- 1
Diligent.WebAPI.Business/Services/ApplicantService.cs Voir le fichier

namespace Diligent.WebAPI.Business.Services
using static Diligent.WebAPI.Data.Entities.Applicant;

namespace Diligent.WebAPI.Business.Services
{ {
public class ApplicantService : IApplicantService public class ApplicantService : IApplicantService
{ {
return result; 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 CreateApplicant(ApplicantCreateDto applicantCreateDto) //public async Task CreateApplicant(ApplicantCreateDto applicantCreateDto)
//{ //{
// var applicant = _mapper.Map<Applicant>(applicantCreateDto); // var applicant = _mapper.Map<Applicant>(applicantCreateDto);

+ 1
- 0
Diligent.WebAPI.Business/Services/Interfaces/IApplicantService.cs Voir le fichier

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 ApplyForAAd(ApplyForAdRequestDto request);
Task DeleteApplicant(int id); Task DeleteApplicant(int id);
//Task CreateApplicant(ApplicantCreateDto applicantCreateDto); //Task CreateApplicant(ApplicantCreateDto applicantCreateDto);
//Task UpdateApplicant(int id, ApplicantUpdateDto applicantUpdateDto); //Task UpdateApplicant(int id, ApplicantUpdateDto applicantUpdateDto);

+ 37
- 0
Diligent.WebAPI.Contracts/DTOs/Applicant/ApplyForAdRequestDto.cs Voir le fichier

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 Voir le fichier

return Ok(await _applicantService.GetApplicantWithSelectionProcessesById(id)); return Ok(await _applicantService.GetApplicantWithSelectionProcessesById(id));
} }


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

return Ok();
}
} }
} }

Chargement…
Annuler
Enregistrer