Skip to content

Commit

Permalink
Merge pull request #115 from varianter/countingyears
Browse files Browse the repository at this point in the history
Teller antall måneder
  • Loading branch information
haakoaho authored Nov 8, 2023
2 parents 57a21e3 + 2ff6b2b commit d0252dc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/ApplicationCore/Models/ProjectExperienceResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace ApplicationCore.Models;
public record ProjectExprienceResponse{
public required List<ProjectExperience> projects {get; init;}
public required int MonthsOfExperience {get; init;}
}
14 changes: 12 additions & 2 deletions src/ApplicationCore/Services/EmployeesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,24 @@ public async Task<Cv> GetCvForEmployee(string alias, string country)
return await _employeesRepository.GetEmployeeWithCv(alias, country);
}

public async Task<List<ProjectExperience>> GetProjectExperiencesForEmployee(string email,
public async Task<ProjectExprienceResponse> GetProjectExperiencesForEmployee(string email,
List<string> competencies)
{
return await _employeesRepository.GetProjectExperiencesByEmailAndCompetencies(email, competencies);
List<ProjectExperience> relevantProjects = await _employeesRepository.GetProjectExperiencesByEmailAndCompetencies(email, competencies);
return new ProjectExprienceResponse{
projects = relevantProjects,
MonthsOfExperience = relevantProjects.Select( pe => CalculateMonths(pe.FromDate, pe.ToDate)).Sum()
};
}

public async Task<List<string>> GetAllCompetencies(string? email = null)
{
return await _employeesRepository.GetAllCompetencies(email);
}
private static int CalculateMonths(DateOnly? from, DateOnly to){
if(from == null){
return 0;
}
return ((to.Year - from.Value.Year) * 12) + (to.Month - from.Value.Month) + 1;
}
}
2 changes: 1 addition & 1 deletion src/Web/Controllers/EmployeesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task<Cv> GetCvForEmployee ([FromQuery] string alias, [FromQuery] st
[OutputCache(Duration = 60)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<List<ProjectExperience>>> GetProjectsFromEmployee ([FromQuery] string alias, [FromQuery] string country, [FromQuery] List<string> competencies)
public async Task<ActionResult<ProjectExprienceResponse>> GetProjectsFromEmployee ([FromQuery] string alias, [FromQuery] string country, [FromQuery] List<string> competencies)
{
var employee = await _employeeService.GetByAliasAndCountry(alias, country);
if (employee == null)
Expand Down

0 comments on commit d0252dc

Please sign in to comment.