finalizare 1.0
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using Application.Services.Database.PostgreSQL;
|
||||
using Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Services.PostgreSQL;
|
||||
|
||||
public class AdminRepository(HealthcareManagerDatabase context)
|
||||
: BasePostgreSqlRepository<Admin>(context), IAdminRepository
|
||||
{
|
||||
public async Task<Admin?> FindByEmailAsync(string email, CancellationToken token)
|
||||
{
|
||||
return await Context.Admins.FirstOrDefaultAsync(d => d.Email == email, token);
|
||||
}
|
||||
|
||||
public async Task<bool> CredentialsMatch(string email, string password, CancellationToken token)
|
||||
{
|
||||
return await Context.Admins.AnyAsync(u => u.Email == email && u.Password == password, token);
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,38 @@
|
||||
using Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Services.PostgreSQL;
|
||||
|
||||
public class BasePostgreSQLRepository<T> where T : class
|
||||
public class BasePostgreSqlRepository<T>(HealthcareManagerDatabase context)
|
||||
where T : class
|
||||
{
|
||||
protected readonly HealthcareManagerDatabase _context;
|
||||
protected readonly HealthcareManagerDatabase Context = context;
|
||||
|
||||
public BasePostgreSQLRepository(HealthcareManagerDatabase context)
|
||||
public async Task<T?> GetByIdAsync(Guid id, CancellationToken token)
|
||||
{
|
||||
_context = context;
|
||||
return await Context.Set<T>().FindAsync(id, token);
|
||||
}
|
||||
|
||||
public async Task<T?> GetByIdAsync(Guid id)
|
||||
public async Task<IEnumerable<T>> GetAllAsync(CancellationToken token)
|
||||
{
|
||||
return await _context.Set<T>().FindAsync(id);
|
||||
return await Context.Set<T>().ToListAsync(token);
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<T>> GetAllAsync()
|
||||
public async Task AddAsync(T entity, CancellationToken token)
|
||||
{
|
||||
return await _context.Set<T>().ToListAsync();
|
||||
await Context.Set<T>().AddAsync(entity, token);
|
||||
await Context.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public async Task AddAsync(T entity)
|
||||
public async Task UpdateAsync(T entity, CancellationToken token)
|
||||
{
|
||||
await _context.Set<T>().AddAsync(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
Context.Set<T>().Attach(entity);
|
||||
Context.Entry(entity).State = EntityState.Modified;
|
||||
await Context.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(T entity)
|
||||
public async Task DeleteAsync(T entity, CancellationToken token)
|
||||
{
|
||||
_context.Set<T>().Attach(entity);
|
||||
_context.Entry(entity).State = EntityState.Modified;
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(T entity)
|
||||
{
|
||||
_context.Set<T>().Remove(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
Context.Set<T>().Remove(entity);
|
||||
await Context.SaveChangesAsync(token);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,19 @@
|
||||
using Application.Services.Database.PostgreSQL;
|
||||
using Core.Entities;
|
||||
using Infrastructure.Data;
|
||||
using Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Services.PostgreSQL;
|
||||
|
||||
public class DoctorRepository(HealthcareManagerDatabase context)
|
||||
: BasePostgreSQLRepository<Doctor>(context), IDoctorRepository
|
||||
: BasePostgreSqlRepository<Doctor>(context), IDoctorRepository
|
||||
{
|
||||
public async Task<Doctor?> FindByEmailAsync(string email)
|
||||
public async Task<Doctor?> FindByEmailAsync(string email, CancellationToken token)
|
||||
{
|
||||
return await _context.Doctors.FirstOrDefaultAsync(d => d.Email == email);
|
||||
return await Context.Doctors.FirstOrDefaultAsync(d => d.Email == email, token);
|
||||
}
|
||||
|
||||
public async Task<bool> CredentialsMatch(string email, string password)
|
||||
public async Task<bool> CredentialsMatch(string email, string password, CancellationToken token)
|
||||
{
|
||||
return await _context.Doctors.AnyAsync(u => u.Email == email && u.Password == password);
|
||||
return await Context.Doctors.AnyAsync(u => u.Email == email && u.Password == password, token);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,14 @@
|
||||
using Application.Services.Database.PostgreSQL;
|
||||
using Core.Entities;
|
||||
using Infrastructure.Data;
|
||||
using Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Services.PostgreSQL;
|
||||
|
||||
public class MedicalHistoryRepository : BasePostgreSQLRepository<MedicalHistory>, IMedicalHistoryRepository
|
||||
public class MedicalHistoryRepository(HealthcareManagerDatabase context)
|
||||
: BasePostgreSqlRepository<MedicalHistory>(context), IMedicalHistoryRepository
|
||||
{
|
||||
public MedicalHistoryRepository(HealthcareManagerDatabase context) : base(context)
|
||||
public async Task<MedicalHistory?> GetByPatientIdAsync(Guid patientId, CancellationToken token)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<MedicalHistory?> GetByUserIdAsync(Guid userId)
|
||||
{
|
||||
return await _context.MedicalHistories.FirstOrDefaultAsync(d => d.UserId == userId);
|
||||
return await Context.MedicalHistories.FirstOrDefaultAsync(d => d.UserId == patientId, token);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,19 @@
|
||||
using Application.Services.Database.PostgreSQL;
|
||||
using Core.Entities;
|
||||
using Infrastructure.Data;
|
||||
using Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Services.PostgreSQL;
|
||||
|
||||
public class PatientRepository(HealthcareManagerDatabase context)
|
||||
: BasePostgreSQLRepository<Patient>(context), IPatientRepository
|
||||
: BasePostgreSqlRepository<Patient>(context), IPatientRepository
|
||||
{
|
||||
public async Task<Patient?> FindByEmailAsync(string email)
|
||||
public async Task<Patient?> FindByEmailAsync(string email, CancellationToken token)
|
||||
{
|
||||
return await _context.Patients.FirstOrDefaultAsync(d => d.Email == email);
|
||||
return await Context.Patients.FirstOrDefaultAsync(d => d.Email == email, token);
|
||||
}
|
||||
|
||||
public async Task<bool> CredentialsMatch(string email, string password)
|
||||
public async Task<bool> CredentialsMatch(string email, string password, CancellationToken token)
|
||||
{
|
||||
return await _context.Patients.AnyAsync(u => u.Email == email && u.Password == password);
|
||||
return await Context.Patients.AnyAsync(u => u.Email == email && u.Password == password, token);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user