-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
…ses (#529)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
using Api.Common; | ||
using Core.Consultants; | ||
|
||
namespace Api.VacationsController; | ||
|
||
public static class VacationsValidator | ||
{ | ||
public static bool ValidateVacation(int consultantId, StorageService storageService, | ||
public static bool ValidateVacation(Consultant consultant, | ||
string orgUrlKey) | ||
{ | ||
return storageService.GetBaseConsultantById(consultantId)?.Department.Organization.UrlKey == | ||
orgUrlKey; | ||
return consultant.Department.Organization.UrlKey == orgUrlKey; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Core.Consultants; | ||
|
||
public interface IConsultantRepository | ||
{ | ||
/** | ||
* Get consultant, including common Department, Organization and Competense-data | ||
*/ | ||
Task<Consultant?> GetConsultantById(int id, CancellationToken ct); | ||
|
||
/** | ||
* Get consultant, including common Department, Organization and Competense-data | ||
*/ | ||
Task<Consultant?> GetConsultantByEmail(string orgUrlKey, string email, CancellationToken ct); | ||
|
||
Task<List<Consultant>> GetConsultantsInOrganizationByUrlKey(string urlKey, CancellationToken ct); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Core.Consultants; | ||
using Infrastructure.DatabaseContext; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Query; | ||
|
||
namespace Infrastructure.Repositories.Consultants; | ||
|
||
public class ConsultantDbRepository(ApplicationContext context) : IConsultantRepository | ||
{ | ||
public Task<Consultant?> GetConsultantById(int id, CancellationToken ct) | ||
{ | ||
return BaseConsultantQuery() | ||
.SingleOrDefaultAsync(c => c.Id == id, ct); | ||
} | ||
|
||
public async Task<Consultant?> GetConsultantByEmail(string orgUrlKey, string email, CancellationToken ct) | ||
{ | ||
var consultant = await BaseConsultantQuery() | ||
.SingleOrDefaultAsync(c => c.Email == email, ct); | ||
|
||
if (consultant is null || consultant.Department.Organization.UrlKey != orgUrlKey) return null; | ||
|
||
return consultant; | ||
} | ||
|
||
public Task<List<Consultant>> GetConsultantsInOrganizationByUrlKey(string urlKey, | ||
CancellationToken ct) | ||
{ | ||
return BaseConsultantQuery() | ||
.Where(c => c.Department.Organization.UrlKey == urlKey) | ||
.ToListAsync(ct); | ||
} | ||
|
||
|
||
/* | ||
* Ensures consistent Includes to keep expected base data present | ||
*/ | ||
private IIncludableQueryable<Consultant, Competence> BaseConsultantQuery() | ||
{ | ||
return context.Consultant | ||
Check warning on line 40 in backend/Infrastructure/Repositories/Consultants/ConsultantDbRepository.cs GitHub Actions / dotnet_core_project_tests (8.x.x)
Check warning on line 40 in backend/Infrastructure/Repositories/Consultants/ConsultantDbRepository.cs GitHub Actions / dotnet_core_project_tests (8.x.x)
Check warning on line 40 in backend/Infrastructure/Repositories/Consultants/ConsultantDbRepository.cs GitHub Actions / dotnet_core_project_tests (8.x.x)
|
||
.Include(c => c.Department) | ||
Check warning on line 41 in backend/Infrastructure/Repositories/Consultants/ConsultantDbRepository.cs GitHub Actions / dotnet_core_project_tests (8.x.x)
Check warning on line 41 in backend/Infrastructure/Repositories/Consultants/ConsultantDbRepository.cs GitHub Actions / dotnet_core_project_tests (8.x.x)
|
||
.ThenInclude(d => d.Organization) | ||
.Include(c => c.CompetenceConsultant) | ||
Check warning on line 43 in backend/Infrastructure/Repositories/Consultants/ConsultantDbRepository.cs GitHub Actions / dotnet_core_project_tests (8.x.x)
Check warning on line 43 in backend/Infrastructure/Repositories/Consultants/ConsultantDbRepository.cs GitHub Actions / dotnet_core_project_tests (8.x.x)
|
||
.ThenInclude(cc => cc.Competence); | ||
} | ||
} |