Commit 2682fdbb authored by Almouhannad's avatar Almouhannad

(B) Add patients repo with specification

parent 400a6cbb
using Domain.Entities.People.Patients;
using Domain.Repositories.Base;
using Domain.Shared;
namespace Domain.Repositories;
public interface IPatientsRepository : IRepository<Patient>
{
#region Read operations FULL
public Task<Result<Patient>> GetByIdFullAsync(int id);
public Task<Result<ICollection<Patient>>> GetAllFullAsync(int id);
#endregion
}
......@@ -6,11 +6,11 @@ using Microsoft.EntityFrameworkCore;
using Persistence.Context;
using Persistence.Repositories.Base;
namespace Persistence.Repositories;
namespace Persistence.Repositories.Employees;
public class EmployeesRepository : Repositroy<Employee>, IEmployeesRepository
{
public EmployeesRepository(ClinicsDbContext context) : base(context) {}
public EmployeesRepository(ClinicsDbContext context) : base(context) { }
#region Create method
public override Task<Result<Employee>> CreateAsync(Employee entity)
......@@ -22,12 +22,12 @@ public class EmployeesRepository : Repositroy<Employee>, IEmployeesRepository
#endregion
#region Get by serial Number
public async Task<Result<Employee>> GetEmployeeBySerialNumberAsync (string serialNumber)
public async Task<Result<Employee>> GetEmployeeBySerialNumberAsync(string serialNumber)
{
var all = await _context.Set<Employee>().Where(employee => employee.SerialNumber == serialNumber).ToListAsync();
if (all.Count != 1)
return Result.Failure<Employee>(PersistenceErrors.NotFound);
return Result.Success<Employee>(all.First());
return Result.Success(all.First());
}
#endregion
}
......@@ -5,7 +5,7 @@ using Microsoft.EntityFrameworkCore;
using Persistence.Context;
using Persistence.Repositories.Base;
namespace Persistence.Repositories;
namespace Persistence.Repositories.Employees.Relations;
public class EmployeeFamilyMembersRepository : Repositroy<EmployeeFamilyMember>, IEmployeeFamilyMembersRepository
{
......
......@@ -5,12 +5,12 @@ using Microsoft.EntityFrameworkCore;
using Persistence.Context;
using Persistence.Repositories.Base;
namespace Persistence.Repositories;
namespace Persistence.Repositories.FamilyMembers;
public class FamilyMembersRepository : Repositroy<FamilyMember>, IFamilyMembersRepository
{
#region CTOR DI for context
public FamilyMembersRepository(ClinicsDbContext context) : base(context) {}
public FamilyMembersRepository(ClinicsDbContext context) : base(context) { }
#endregion
#region Create method
......
using Domain.Entities.People.Patients;
using Domain.Errors;
using Domain.Repositories;
using Domain.Shared;
using Microsoft.EntityFrameworkCore;
using Persistence.Context;
using Persistence.Repositories.Base;
using Persistence.Repositories.Patients.Specifications;
namespace Persistence.Repositories.Patients;
public class PatientsRepository : Repositroy<Patient>, IPatientsRepository
{
#region CTOR DI for context
public PatientsRepository(ClinicsDbContext context) : base(context)
{
}
#endregion
#region Read operations FULL
public async Task<Result<ICollection<Patient>>> GetAllFullAsync(int id)
{
var query = ApplySpecification(new FullSpecification(patient => true)); // Get all
try
{
var patients = await query.ToListAsync();
return Result.Success<ICollection<Patient>>(patients);
}
catch (Exception)
{
return Result.Failure<ICollection<Patient>>(PersistenceErrors.NotFound);
}
}
public async Task<Result<Patient>> GetByIdFullAsync(int id)
{
var query = ApplySpecification(new FullSpecification(patient => patient.Id == id)); // Get all
try
{
var patient = await query.FirstAsync();
return Result.Success<Patient>(patient);
}
catch (Exception)
{
return Result.Failure<Patient>(PersistenceErrors.NotFound);
}
}
#endregion
}
using Domain.Entities.People.Patients;
using Persistence.Repositories.Specifications.Base;
using System.Linq.Expressions;
namespace Persistence.Repositories.Patients.Specifications;
public class FullSpecification : Specification<Patient>
{
public FullSpecification(Expression<Func<Patient, bool>>? criteria) : base(criteria)
{
AddInclude(patient => patient.PersonalInfo);
AddInclude(patient => patient.Gender);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment