Backend Pacients, Doctors and MedicalHistory endpoints
- added for Pacients: POST: /register POST: /login POST: /reset_password PUT: /profile DELETE: /profile - added for Doctors: POST: /register POST: /login POST: /reset_password PUT: /profile DELETE: /profile - added for MedicalHistories: POST: /:id (only by pacient) - done GET: /:id (only by pacient) - done PUT: /:id (only by doctor) - done PUT /grand_access - TODO
This commit is contained in:
@@ -1,44 +1,43 @@
|
||||
using Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Services.PostgreSQL
|
||||
namespace Infrastructure.Services.PostgreSQL;
|
||||
|
||||
public class BasePostgreSQLRepository<T> where T : class
|
||||
{
|
||||
public class BasePostgreSQLRepository<T> where T : class
|
||||
protected readonly HealthcareManagerDatabase _context;
|
||||
|
||||
public BasePostgreSQLRepository(HealthcareManagerDatabase context)
|
||||
{
|
||||
protected readonly HealthcareManagerDatabase _context;
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public BasePostgreSQLRepository(HealthcareManagerDatabase context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
public async Task<T> GetByIdAsync(Guid id)
|
||||
{
|
||||
return await _context.Set<T>().FindAsync(id);
|
||||
}
|
||||
|
||||
public async Task<T> GetByIdAsync(Guid id)
|
||||
{
|
||||
return await _context.Set<T>().FindAsync(id);
|
||||
}
|
||||
public async Task<IEnumerable<T>> GetAllAsync()
|
||||
{
|
||||
return await _context.Set<T>().ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<T>> ListAllAsync()
|
||||
{
|
||||
return await _context.Set<T>().ToListAsync();
|
||||
}
|
||||
public async Task AddAsync(T entity)
|
||||
{
|
||||
await _context.Set<T>().AddAsync(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task AddAsync(T entity)
|
||||
{
|
||||
await _context.Set<T>().AddAsync(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
public async Task UpdateAsync(T entity)
|
||||
{
|
||||
_context.Set<T>().Attach(entity);
|
||||
_context.Entry(entity).State = EntityState.Modified;
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task Update(T entity)
|
||||
{
|
||||
_context.Set<T>().Attach(entity);
|
||||
_context.Entry(entity).State = EntityState.Modified;
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task Delete(T entity)
|
||||
{
|
||||
_context.Set<T>().Remove(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
public async Task DeleteAsync(T entity)
|
||||
{
|
||||
_context.Set<T>().Remove(entity);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,10 @@ using Core.Entities;
|
||||
using Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Services.PostgreSQL
|
||||
namespace Infrastructure.Services.PostgreSQL;
|
||||
|
||||
public class DoctorRepository(HealthcareManagerDatabase context) : BasePostgreSQLRepository<Doctor>(context), IDoctorRepository
|
||||
{
|
||||
public class DoctorRepository : BasePostgreSQLRepository<Doctor>, IDoctorRepository
|
||||
{
|
||||
public DoctorRepository(HealthcareManagerDatabase context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<bool> IsDoctorExisting(string email)
|
||||
{
|
||||
return await _context.Doctors.AnyAsync(d => d.Email == email);
|
||||
}
|
||||
|
||||
}
|
||||
public async Task<Doctor?> FindByEmailAsync(string email)
|
||||
=> await _context.Doctors.FirstOrDefaultAsync(d => d.Email == email);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
using Application.Services.Database;
|
||||
using Core.Entities;
|
||||
using Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Services.PostgreSQL
|
||||
namespace Infrastructure.Services.PostgreSQL;
|
||||
|
||||
public class MedicalHistoryRepository : BasePostgreSQLRepository<MedicalHistory>, IMedicalHistoryRepository
|
||||
{
|
||||
public class MedicalHistoryRepository : BasePostgreSQLRepository<MedicalHistory>, IMedicalHistoryRepository
|
||||
public MedicalHistoryRepository(HealthcareManagerDatabase context) : base(context)
|
||||
{
|
||||
public MedicalHistoryRepository(HealthcareManagerDatabase context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task<MedicalHistory?> GetByUserIdAsync(Guid userId)
|
||||
=> await _context.MedicalHistories.FirstOrDefaultAsync(d => d.UserId == userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
using Application.Services.Database;
|
||||
using Core.Entities;
|
||||
using Infrastructure.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Services.PostgreSQL
|
||||
namespace Infrastructure.Services.PostgreSQL;
|
||||
|
||||
public class PacientRepository(HealthcareManagerDatabase context) : BasePostgreSQLRepository<Pacient>(context), IPacientRepository
|
||||
{
|
||||
public class PacientRepository : BasePostgreSQLRepository<Pacient>, IPacientRepository
|
||||
{
|
||||
public PacientRepository(HealthcareManagerDatabase context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
public async Task<Pacient?> FindByEmailAsync(string email)
|
||||
=> await _context.Pacients.FirstOrDefaultAsync(d => d.Email == email);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user