Sfoglia il codice sorgente

upload cv backend

pull/125/head
Dzenis Hadzifejzovic 3 anni fa
parent
commit
c066d4851d

+ 2
- 0
Diligent.WebAPI.Business/Diligent.WebAPI.Business.csproj Vedi File

@@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="AutoMapper" Version="11.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.14.1" />
<PackageReference Include="Bytescout.Spreadsheet" Version="4.6.0.2025" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.10" />
@@ -16,6 +17,7 @@
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="6.0.10" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="6.0.10" />
<PackageReference Include="RestSharp" Version="108.0.2-alpha.0.6" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
</ItemGroup>

<ItemGroup>

+ 57
- 7
Diligent.WebAPI.Business/Services/ApplicantService.cs Vedi File

@@ -1,4 +1,8 @@
using static Diligent.WebAPI.Data.Entities.Applicant;
using Azure.Storage.Blobs;
using Microsoft.Extensions.Configuration;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using static Diligent.WebAPI.Data.Entities.Applicant;

namespace Diligent.WebAPI.Business.Services
{
@@ -8,13 +12,16 @@ namespace Diligent.WebAPI.Business.Services
private readonly IMapper _mapper;
private readonly ILogger<ApplicantService> _logger;
private readonly IUserService _userService;
private readonly IConfiguration _configuration;

public ApplicantService(DatabaseContext context, IMapper mapper, ILogger<ApplicantService> logger, IUserService userService)
public ApplicantService(DatabaseContext context, IMapper mapper, ILogger<ApplicantService> logger,
IUserService userService,IConfiguration configuration)
{
_context = context;
_mapper = mapper;
_logger = logger;
_userService = userService;
_configuration = configuration;
}

public async Task<QueryResultDto<ApplicantViewDto>> GetFilteredApplicants(ApplicantFilterDto applicantFilterDto)
@@ -115,8 +122,22 @@ namespace Diligent.WebAPI.Business.Services
return result;
}

public async Task ApplyForAAd(ApplyForAdRequestDto request)
public async Task ApplyForAd(ApplyForAdRequestDto request)
{
string fileName = string.Format(@"{0}.pdf", DateTime.Now.Ticks);

string blobstorageconnection = _configuration.GetValue<string>("BlobConnectionString");
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(blobstorageconnection);
CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(
_configuration.GetValue<string>("BlobContainerName"));
CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName);

await using (var data = request.PdfFile.OpenReadStream())
{
await blockBlob.UploadFromStreamAsync(data);
}

_logger.LogInformation("Start applying for ad");
_logger.LogInformation("Find ad by id");
var ad = await _context.Ads.Where(x => x.Id == request.AdId).FirstOrDefaultAsync();
@@ -131,13 +152,13 @@ namespace Diligent.WebAPI.Business.Services
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
Applicant applicant = new()
{
FirstName = request.FirstName,
LastName = request.LastName,
Position = ad.Title,
DateOfApplication = DateTime.UtcNow,
CV = request.PdfFile,
CV = fileName,
Email = request.Email,
PhoneNumber = request.PhoneNumber,
GithubLink = request.GithubLink,
@@ -154,9 +175,9 @@ namespace Diligent.WebAPI.Business.Services
};

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

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


@@ -248,6 +269,35 @@ namespace Diligent.WebAPI.Business.Services
};
}

public async Task<string> GetCV(string fileName)
{
CloudBlockBlob blockBlob;
await using (MemoryStream memoryStream = new())
{
string blobstorageconnection = _configuration.GetValue<string>("BlobConnectionString");
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(blobstorageconnection);
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(_configuration.GetValue<string>("BlobContainerName"));
blockBlob = cloudBlobContainer.GetBlockBlobReference(fileName);
await blockBlob.DownloadToStreamAsync(memoryStream);
Stream blobStream = blockBlob.OpenReadAsync().Result;
return ConvertToBase64(blobStream);
}
}

private static string ConvertToBase64(Stream stream)
{
byte[] bytes;
using (var memoryStream = new MemoryStream())
{
stream.CopyTo(memoryStream);
bytes = memoryStream.ToArray();
}

string base64 = Convert.ToBase64String(bytes);
return base64;
}

//public async Task CreateApplicant(ApplicantCreateDto applicantCreateDto)
//{
// var applicant = _mapper.Map<Applicant>(applicantCreateDto);

+ 2
- 1
Diligent.WebAPI.Business/Services/Interfaces/IApplicantService.cs Vedi File

@@ -9,11 +9,12 @@ 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 ApplyForAd(ApplyForAdRequestDto request);
Task DeleteApplicant(int id);
Task<List<ApplicantOptionsDTO>> GetOptions();
Task<ServiceResponseDTO<object>> InitializeProcess(ApplicantProcessRequestDTO model);
Task ImportApplicant(List<ApplicantImportDto> request);
Task<string> GetCV(string fileName);
//Task CreateApplicant(ApplicantCreateDto applicantCreateDto);
//Task UpdateApplicant(int id, ApplicantUpdateDto applicantUpdateDto);
}

+ 3
- 2
Diligent.WebAPI.Contracts/DTOs/Applicant/ApplyForAdRequestDto.cs Vedi File

@@ -1,4 +1,5 @@
using System;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -32,6 +33,6 @@ namespace Diligent.WebAPI.Contracts.DTOs.Applicant

public string CoverLetter { get; set; }

public string PdfFile { get; set; }
public IFormFile PdfFile { get; set; }
}
}

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

@@ -57,11 +57,18 @@ namespace Diligent.WebAPI.Host.Controllers.V1
}

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

return Ok();
}

[HttpGet("get-CV")]
public async Task<IActionResult> GetCV(string fileName)
{
var res = await _applicantService.GetCV(fileName);
return Ok(res);
}
}
}

+ 2
- 0
Diligent.WebAPI.Host/appsettings.json Vedi File

@@ -45,6 +45,8 @@
"SmtpFrom": "noreply@hrcenter.net",
"SmtpFromName": "HRCenter Team"
},
"BlobConnectionString": "DefaultEndpointsProtocol=https;AccountName=brrbc49;AccountKey=P34mX1kJZcYOeDXpOC7EqbpTnu3Y2NYay3UV9iYMk7HkRTe1Wu/MsXVfuBheDbHid6+TOWAiw5qk+AStJw9Eww==;EndpointSuffix=core.windows.net",
"BlobContainerName": "hrcenter",
"FrontEnd": {
"BaseUrl": "https://test-hr-center.dilig.net"
}

Loading…
Annulla
Salva