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:
@@ -3,26 +3,25 @@ using Microsoft.EntityFrameworkCore.Design;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
|
||||
namespace Infrastructure.Data
|
||||
namespace Infrastructure.Data;
|
||||
|
||||
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<HealthcareManagerDatabase>
|
||||
{
|
||||
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<HealthcareManagerDatabase>
|
||||
public HealthcareManagerDatabase CreateDbContext(string[] args)
|
||||
{
|
||||
public HealthcareManagerDatabase CreateDbContext(string[] args)
|
||||
{
|
||||
// Adjust the path to point to the API project directory
|
||||
var basePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\API"));
|
||||
// Adjust the path to point to the API project directory
|
||||
var basePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\API"));
|
||||
|
||||
IConfigurationRoot configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(basePath)
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
IConfigurationRoot configuration = new ConfigurationBuilder()
|
||||
.SetBasePath(basePath)
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
|
||||
var builder = new DbContextOptionsBuilder<HealthcareManagerDatabase>();
|
||||
var connectionString = configuration.GetConnectionString("HealthcareManagerDatabase");
|
||||
var builder = new DbContextOptionsBuilder<HealthcareManagerDatabase>();
|
||||
var connectionString = configuration.GetConnectionString("HealthcareManagerDatabase");
|
||||
|
||||
builder.UseNpgsql(connectionString); // Make sure this matches your database provider
|
||||
builder.UseNpgsql(connectionString); // Make sure this matches your database provider
|
||||
|
||||
return new HealthcareManagerDatabase(builder.Options);
|
||||
}
|
||||
return new HealthcareManagerDatabase(builder.Options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
using Core.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Infrastructure.Data
|
||||
namespace Infrastructure.Data;
|
||||
|
||||
public class HealthcareManagerDatabase : DbContext
|
||||
{
|
||||
public class HealthcareManagerDatabase : DbContext
|
||||
public HealthcareManagerDatabase(DbContextOptions<HealthcareManagerDatabase> options) : base(options) { }
|
||||
|
||||
public DbSet<Pacient> Pacients { get; set; }
|
||||
public DbSet<MedicalHistory> MedicalHistories { get; set; }
|
||||
public DbSet<Doctor> Doctors { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
public HealthcareManagerDatabase(DbContextOptions<HealthcareManagerDatabase> options) : base(options) { }
|
||||
|
||||
public DbSet<Pacient> Pacients { get; set; }
|
||||
public DbSet<MedicalHistory> MedicalHistories { get; set; }
|
||||
public DbSet<Doctor> Doctors { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.3" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
|
||||
|
||||
@@ -7,27 +7,26 @@ using Infrastructure.Services.MongoDB;
|
||||
using Application.Services.Database;
|
||||
using Infrastructure.Services.PostgreSQL;
|
||||
|
||||
namespace Infrastructure
|
||||
namespace Infrastructure;
|
||||
|
||||
public static class DependencyInjection
|
||||
{
|
||||
public static class DependencyInjection
|
||||
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
services.AddDbContext<HealthcareManagerDatabase>(options =>
|
||||
options.UseNpgsql(configuration.GetConnectionString("HealthcareManagerDatabase")));
|
||||
services.AddDbContext<HealthcareManagerDatabase>(options =>
|
||||
options.UseNpgsql(configuration.GetConnectionString("HealthcareManagerDatabase")));
|
||||
|
||||
|
||||
services.AddScoped<IPacientRepository, PacientRepository>();
|
||||
services.AddScoped<IDoctorRepository, DoctorRepository>();
|
||||
services.AddScoped<IMedicalHistoryRepository, MedicalHistoryRepository>();
|
||||
services.AddScoped<IPacientRepository, PacientRepository>();
|
||||
services.AddScoped<IDoctorRepository, DoctorRepository>();
|
||||
services.AddScoped<IMedicalHistoryRepository, MedicalHistoryRepository>();
|
||||
|
||||
var mongoDbConnection = configuration.GetConnectionString("MongoDBDatabase");
|
||||
var mongoDbConnection = configuration.GetConnectionString("MongoDBDatabase");
|
||||
|
||||
services.AddSingleton(serviceProvider => new MongoDbService(mongoDbConnection));
|
||||
services.AddSingleton(serviceProvider => new MongoDbService(mongoDbConnection));
|
||||
|
||||
// services.AddScoped<IEmailService, EmailService>();
|
||||
// services.AddScoped<IEmailService, EmailService>();
|
||||
|
||||
return services;
|
||||
}
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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