diff --git a/src/ApplicationCore/Models/ProjectExperienceResponse.cs b/src/ApplicationCore/Models/ProjectExperienceResponse.cs new file mode 100644 index 0000000..8a4a827 --- /dev/null +++ b/src/ApplicationCore/Models/ProjectExperienceResponse.cs @@ -0,0 +1,5 @@ +namespace ApplicationCore.Models; +public record ProjectExprienceResponse{ + public required List projects {get; init;} + public required int MonthsOfExperience {get; init;} +} \ No newline at end of file diff --git a/src/ApplicationCore/Services/EmployeesService.cs b/src/ApplicationCore/Services/EmployeesService.cs index 5331ab3..8517d7a 100644 --- a/src/ApplicationCore/Services/EmployeesService.cs +++ b/src/ApplicationCore/Services/EmployeesService.cs @@ -105,14 +105,24 @@ public async Task GetCvForEmployee(string alias, string country) return await _employeesRepository.GetEmployeeWithCv(alias, country); } - public async Task> GetProjectExperiencesForEmployee(string email, + public async Task GetProjectExperiencesForEmployee(string email, List competencies) { - return await _employeesRepository.GetProjectExperiencesByEmailAndCompetencies(email, competencies); + List relevantProjects = await _employeesRepository.GetProjectExperiencesByEmailAndCompetencies(email, competencies); + return new ProjectExprienceResponse{ + projects = relevantProjects, + MonthsOfExperience = relevantProjects.Select( pe => CalculateMonths(pe.FromDate, pe.ToDate)).Sum() + }; } public async Task> 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; + } } \ No newline at end of file diff --git a/src/Web/Controllers/EmployeesController.cs b/src/Web/Controllers/EmployeesController.cs index 9f59d64..30d76c3 100644 --- a/src/Web/Controllers/EmployeesController.cs +++ b/src/Web/Controllers/EmployeesController.cs @@ -70,7 +70,7 @@ public async Task GetCvForEmployee ([FromQuery] string alias, [FromQuery] st [OutputCache(Duration = 60)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task>> GetProjectsFromEmployee ([FromQuery] string alias, [FromQuery] string country, [FromQuery] List competencies) + public async Task> GetProjectsFromEmployee ([FromQuery] string alias, [FromQuery] string country, [FromQuery] List competencies) { var employee = await _employeeService.GetByAliasAndCountry(alias, country); if (employee == null)