Skip to content

Commit

Permalink
Merge pull request #118 from varianter/cvcleanup
Browse files Browse the repository at this point in the history
Sletter rader ute av synk med CVPartner
  • Loading branch information
haakoaho authored Dec 5, 2023
2 parents 8559eb3 + f49b05a commit f4dcb83
Showing 1 changed file with 47 additions and 15 deletions.
62 changes: 47 additions & 15 deletions src/Infrastructure/Repositories/EmployeeRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,25 +153,57 @@ await _db.AddAsync(new EmployeeEntity
return employees.Select(employee => employee.ImageUrl);
}

public async Task AddOrUpdateCvInformation(List<Cv> cvs)
private async Task AddOrUpdateCvInformation(Cv cv)
{
foreach (Cv cv in cvs)
_logger.LogInformation("Starting cv processing of " + cv.Email);
var entity = await GetEmployeeWithCv(cv.Email);
if (entity == null)
{
_logger.LogInformation("Starting cv processing of " + cv.Email);
var entity = await GetEmployeeWithCv(cv.Email);
if (entity == null)
{
continue;
}

await AddPresentations(cv.Presentations, entity);
await AddWorkExperience(cv.WorkExperiences, entity);
await AddProjectExperience(cv.ProjectExperiences, entity);
await AddCertifications(cv.Certifiactions, entity);
await _db.SaveChangesAsync();
return;
}

await AddPresentations(cv.Presentations, entity);
await AddWorkExperience(cv.WorkExperiences, entity);
await AddProjectExperience(cv.ProjectExperiences, entity);
await AddCertifications(cv.Certifiactions, entity);
await _db.SaveChangesAsync();
}

private async Task DeleteCvDataOutOfSync()
{
DateTime cutOff = DateTime.Now.AddDays(-2);

var deleteProjects = _db.ProjectExperiences.Where(pe => pe.LastSynced < cutOff);
_db.ProjectExperiences.RemoveRange(deleteProjects);

var deleteWorkExperience = _db.WorkExperiences.Where(pe => pe.LastSynced < cutOff);
_db.WorkExperiences.RemoveRange(deleteWorkExperience);

var deleteCompetencies = _db.Competencies.Where(pe => pe.LastSynced < cutOff);
_db.Competencies.RemoveRange(deleteCompetencies);

var deleteRoles = _db.ProjectExperienceRoles.Where(pe => pe.LastSynced < cutOff);
_db.ProjectExperienceRoles.RemoveRange(deleteRoles);

var deleteCertifications = _db.Certifications.Where(pe => pe.LastSynced < cutOff);
_db.Certifications.RemoveRange(deleteCertifications);

var deletePresentations = _db.Presentations.Where(pe => pe.LastSynced < cutOff);
_db.Presentations.RemoveRange(deletePresentations);

await _db.SaveChangesAsync();
}

public async Task AddOrUpdateCvInformation(List<Cv> cvs)
{
foreach (var cv in cvs)
{
await AddOrUpdateCvInformation(cv);
}

await DeleteCvDataOutOfSync();
}

private async Task AddCertifications(List<Certification> certifications, EmployeeEntity entity)
{
foreach (Certification certification in certifications)
Expand Down Expand Up @@ -219,7 +251,7 @@ private async Task AddPresentations(List<Presentation> presentations, EmployeeEn
LastSynced = DateTime.Now,
Date = presentation.Date,
Title = presentation.Title,

};
await _db.AddAsync(presentationEntity);

Expand Down

0 comments on commit f4dcb83

Please sign in to comment.