This commit is contained in:
andrei-mihnea-cerbu
2024-04-08 00:03:24 +03:00
parent 2ccec617a5
commit b48d5ee19e
168 changed files with 2877 additions and 1146 deletions
@@ -2,7 +2,6 @@
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
namespace Infrastructure.Data;
public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<HealthcareManagerDatabase>
@@ -12,7 +11,7 @@ public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<Healthcare
// Adjust the path to point to the API project directory
var basePath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\API"));
IConfigurationRoot configuration = new ConfigurationBuilder()
var configuration = new ConfigurationBuilder()
.SetBasePath(basePath)
.AddJsonFile("appsettings.json")
.Build();
@@ -24,4 +23,4 @@ public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<Healthcare
return new HealthcareManagerDatabase(builder.Options);
}
}
}
@@ -5,9 +5,11 @@ namespace Infrastructure.Data;
public class HealthcareManagerDatabase : DbContext
{
public HealthcareManagerDatabase(DbContextOptions<HealthcareManagerDatabase> options) : base(options) { }
public HealthcareManagerDatabase(DbContextOptions<HealthcareManagerDatabase> options) : base(options)
{
}
public DbSet<Pacient> Pacients { get; set; }
public DbSet<Patient> Pacients { get; set; }
public DbSet<MedicalHistory> MedicalHistories { get; set; }
public DbSet<Doctor> Doctors { get; set; }
@@ -15,4 +17,4 @@ public class HealthcareManagerDatabase : DbContext
{
base.OnModelCreating(modelBuilder);
}
}
}
+22 -22
View File
@@ -1,28 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<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" />
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<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"/>
<PackageReference Include="MongoDB.Driver" Version="2.24.0"/>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.2"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Application\Application.csproj" />
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Application\Application.csproj"/>
<ProjectReference Include="..\Core\Core.csproj"/>
</ItemGroup>
</Project>
+16 -11
View File
@@ -1,32 +1,37 @@
using Microsoft.EntityFrameworkCore;
using Application.Services.Database;
using Application.Services.HashingAlgorithms;
using Infrastructure.Data;
using Infrastructure.Services.HashingAlgorithms;
using Infrastructure.Services.MongoDB;
using Infrastructure.Services.PostgreSQL;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Infrastructure.Data;
using Infrastructure.Services.MongoDB;
using Application.Services.Database;
using Infrastructure.Services.PostgreSQL;
namespace Infrastructure;
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.AddScoped<IPacientRepository, PacientRepository>();
//PostgreSQL Services
services.AddScoped<IPatientRepository, PatientRepository>();
services.AddScoped<IDoctorRepository, DoctorRepository>();
services.AddScoped<IMedicalHistoryRepository, MedicalHistoryRepository>();
// MongoDB Service
var mongoDbConnection = configuration.GetConnectionString("MongoDBDatabase");
services.AddSingleton<IMongoDbService>(serviceProvider => new MongoDbService(mongoDbConnection));
services.AddSingleton(serviceProvider => new MongoDbService(mongoDbConnection));
// Other Services
services.AddScoped<IHashingAlgorithms, HashingAlgorithms>();
// services.AddScoped<IEmailService, EmailService>();
return services;
}
}
}
-36
View File
@@ -1,36 +0,0 @@
using MongoDB.Driver;
namespace Infrastructure.Services.MongoDB
{
public class MongoDbService
{
private readonly IMongoDatabase _database;
public MongoDbService(string connectionString)
{
var url = new MongoUrl(connectionString);
var client = new MongoClient(url);
_database = client.GetDatabase(url.DatabaseName);
}
public IMongoCollection<T> GetCollection<T>(string collectionName)
{
return _database.GetCollection<T>(collectionName);
}
public async Task<List<T>> FindAsync<T>(string collectionName, List<(string FieldName, string Value)> criteria)
{
var collection = _database.GetCollection<T>(collectionName);
var filters = new List<FilterDefinition<T>>();
foreach (var (FieldName, Value) in criteria)
{
filters.Add(Builders<T>.Filter.Eq(FieldName, Value));
}
var combinedFilter = Builders<T>.Filter.And(filters);
return await collection.Find(combinedFilter).ToListAsync();
}
}
}
@@ -0,0 +1,19 @@
using System.Security.Cryptography;
using System.Text;
using Application.Services.HashingAlgorithms;
namespace Infrastructure.Services.HashingAlgorithms;
public class HashingAlgorithms : IHashingAlgorithms
{
public string? SHA256Algorithm(string? password)
{
if (password == null) return null;
using (var sha256 = SHA256.Create())
{
var bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(password));
return Convert.ToBase64String(bytes);
}
}
}
@@ -0,0 +1,53 @@
using Application.Services.Database;
using MongoDB.Driver;
namespace Infrastructure.Services.MongoDB;
public class MongoDbService : IMongoDbService
{
private readonly IMongoDatabase _database;
public MongoDbService(string connectionString)
{
var url = new MongoUrl(connectionString);
var client = new MongoClient(url);
_database = client.GetDatabase(url.DatabaseName);
}
public IMongoCollection<T> GetCollection<T>(string collectionName)
{
return _database.GetCollection<T>(collectionName);
}
public async Task<List<T>> FindAsync<T>(string collectionName, List<(string FieldName, string Value)> criteria)
{
var collection = _database.GetCollection<T>(collectionName);
var filters = new List<FilterDefinition<T>>();
foreach (var (FieldName, Value) in criteria) filters.Add(Builders<T>.Filter.Eq(FieldName, Value));
var combinedFilter = Builders<T>.Filter.And(filters);
return await collection.Find(combinedFilter).ToListAsync();
}
public async Task AddAsync<T>(string collectionName, T document)
{
var collection = _database.GetCollection<T>(collectionName);
await collection.InsertOneAsync(document);
}
public async Task ModifyAsync<T>(string collectionName, string keyField, string keyValue, T document)
{
var collection = _database.GetCollection<T>(collectionName);
var filter = Builders<T>.Filter.Eq(keyField, keyValue);
await collection.ReplaceOneAsync(filter, document, new ReplaceOptions { IsUpsert = true });
}
public async Task DeleteAsync<T>(string collectionName, string keyField, string keyValue)
{
var collection = _database.GetCollection<T>(collectionName);
var filter = Builders<T>.Filter.Eq(keyField, keyValue);
await collection.DeleteOneAsync(filter);
}
}
@@ -12,7 +12,7 @@ public class BasePostgreSQLRepository<T> where T : class
_context = context;
}
public async Task<T> GetByIdAsync(Guid id)
public async Task<T?> GetByIdAsync(Guid id)
{
return await _context.Set<T>().FindAsync(id);
}
@@ -40,4 +40,4 @@ public class BasePostgreSQLRepository<T> where T : class
_context.Set<T>().Remove(entity);
await _context.SaveChangesAsync();
}
}
}
@@ -5,8 +5,16 @@ using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Services.PostgreSQL;
public class DoctorRepository(HealthcareManagerDatabase context) : BasePostgreSQLRepository<Doctor>(context), IDoctorRepository
public class DoctorRepository(HealthcareManagerDatabase context)
: BasePostgreSQLRepository<Doctor>(context), IDoctorRepository
{
public async Task<Doctor?> FindByEmailAsync(string email)
=> await _context.Doctors.FirstOrDefaultAsync(d => d.Email == email);
}
public async Task<Doctor?> FindByEmailAsync(string email)
{
return await _context.Doctors.FirstOrDefaultAsync(d => d.Email == email);
}
public async Task<bool> CredentialsMatch(string email, string password)
{
return _context.Doctors.Any(u => u.Email == email && u.Password == password);
}
}
@@ -12,6 +12,7 @@ public class MedicalHistoryRepository : BasePostgreSQLRepository<MedicalHistory>
}
public async Task<MedicalHistory?> GetByUserIdAsync(Guid userId)
=> await _context.MedicalHistories.FirstOrDefaultAsync(d => d.UserId == userId);
}
{
return await _context.MedicalHistories.FirstOrDefaultAsync(d => d.UserId == userId);
}
}
@@ -1,12 +0,0 @@
using Application.Services.Database;
using Core.Entities;
using Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Services.PostgreSQL;
public class PacientRepository(HealthcareManagerDatabase context) : BasePostgreSQLRepository<Pacient>(context), IPacientRepository
{
public async Task<Pacient?> FindByEmailAsync(string email)
=> await _context.Pacients.FirstOrDefaultAsync(d => d.Email == email);
}
@@ -0,0 +1,15 @@
using Application.Services.Database;
using Core.Entities;
using Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace Infrastructure.Services.PostgreSQL;
public class PatientRepository(HealthcareManagerDatabase context)
: BasePostgreSQLRepository<Patient>(context), IPatientRepository
{
public async Task<Patient?> FindByEmailAsync(string email)
{
return await _context.Pacients.FirstOrDefaultAsync(d => d.Email == email);
}
}
Binary file not shown.
Binary file not shown.
@@ -12,6 +12,7 @@
"Core": "1.0.0",
"Microsoft.EntityFrameworkCore": "8.0.3",
"Microsoft.EntityFrameworkCore.Design": "8.0.3",
"Microsoft.EntityFrameworkCore.Relational": "8.0.3",
"Microsoft.Extensions.Configuration": "8.0.0",
"Microsoft.Extensions.Configuration.Json": "8.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "8.0.0",
@@ -806,7 +807,9 @@
},
"Application/1.0.0": {
"dependencies": {
"FluentValidation": "11.9.0"
"Core": "1.0.0",
"FluentValidation": "11.9.0",
"MongoDB.Driver": "2.24.0"
},
"runtime": {
"Application.dll": {}
@@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("Infrastructure")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+1206db932183801caeaefeb110af24b0147366c1")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2ccec617a59a712428e67340dc46bebefb152aca")]
[assembly: System.Reflection.AssemblyProductAttribute("Infrastructure")]
[assembly: System.Reflection.AssemblyTitleAttribute("Infrastructure")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
ea468b679ae500ce31444c1c9d05c28c3066f2016f4f30d94e2abc7ebcedf3b9
5c68101bdd997137e1cd8f3c58cb6d9e9b9d203289c90b0f6dca8b08cc72b5c9
@@ -1 +1 @@
5afb3ed7d16a2df0400eb200d8278f7eab743b937793203fe737f90a0ba6f42f
8ecca766b80ccc6e510e107ea1369b5001c45e66e3507ff5e47c4d13fae048e4
@@ -1 +1 @@
{"documents":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\*":"https://raw.githubusercontent.com/andrei-mihnea-cerbu/CC-FinalProj/1206db932183801caeaefeb110af24b0147366c1/*"}}
{"documents":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\*":"https://raw.githubusercontent.com/andrei-mihnea-cerbu/CC-FinalProj/2ccec617a59a712428e67340dc46bebefb152aca/*"}}
@@ -27,7 +27,11 @@
"frameworks": {
"net8.0": {
"targetAlias": "net8.0",
"projectReferences": {}
"projectReferences": {
"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Core\\Core.csproj": {
"projectPath": "C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Core\\Core.csproj"
}
}
}
},
"warningProperties": {
@@ -43,6 +47,10 @@
"FluentValidation": {
"target": "Package",
"version": "[11.9.0, )"
},
"MongoDB.Driver": {
"target": "Package",
"version": "[2.24.0, )"
}
},
"imports": [
@@ -179,6 +187,10 @@
"target": "Package",
"version": "[8.0.3, )"
},
"Microsoft.EntityFrameworkCore.Relational": {
"target": "Package",
"version": "[8.0.3, )"
},
"Microsoft.Extensions.Configuration": {
"target": "Package",
"version": "[8.0.0, )"
@@ -1310,7 +1310,9 @@
"type": "project",
"framework": ".NETCoreApp,Version=v8.0",
"dependencies": {
"FluentValidation": "11.9.0"
"Core": "1.0.0",
"FluentValidation": "11.9.0",
"MongoDB.Driver": "2.24.0"
},
"compile": {
"bin/placeholder/Application.dll": {}
@@ -3448,6 +3450,7 @@
"Core >= 1.0.0",
"Microsoft.EntityFrameworkCore >= 8.0.3",
"Microsoft.EntityFrameworkCore.Design >= 8.0.3",
"Microsoft.EntityFrameworkCore.Relational >= 8.0.3",
"Microsoft.Extensions.Configuration >= 8.0.0",
"Microsoft.Extensions.Configuration.Json >= 8.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions >= 8.0.0",
@@ -3511,6 +3514,10 @@
"target": "Package",
"version": "[8.0.3, )"
},
"Microsoft.EntityFrameworkCore.Relational": {
"target": "Package",
"version": "[8.0.3, )"
},
"Microsoft.Extensions.Configuration": {
"target": "Package",
"version": "[8.0.0, )"
@@ -1,6 +1,6 @@
{
"version": 2,
"dgSpecHash": "t1Lh/p64WBrnORW6635pkHOABwC1ZyTNJVZj9jg7WdG5XARaLlgRGmknylIsriNV03uXj4BqkWcEhJWh1UsLNg==",
"dgSpecHash": "iwi/5xNtgWqhK31wqOr9WG6iDQW0uTBS41AXw9EdTi0QL3UPkJdVquF7OuGqSc48sG+mLp/gC3DLdj3TQId54g==",
"success": true,
"projectFilePath": "C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Infrastructure\\Infrastructure.csproj",
"expectedPackageFiles": [
@@ -1 +1 @@
"restore":{"projectUniqueName":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Infrastructure\\Infrastructure.csproj","projectName":"Infrastructure","projectPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Infrastructure\\Infrastructure.csproj","outputPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Infrastructure\\obj\\","projectStyle":"PackageReference","originalTargetFrameworks":["net8.0"],"sources":{"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\":{},"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net8.0":{"targetAlias":"net8.0","projectReferences":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Application\\Application.csproj":{"projectPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Application\\Application.csproj"},"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Core\\Core.csproj":{"projectPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Core\\Core.csproj"}}}},"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net8.0":{"targetAlias":"net8.0","dependencies":{"Microsoft.EntityFrameworkCore":{"target":"Package","version":"[8.0.3, )"},"Microsoft.EntityFrameworkCore.Design":{"include":"Runtime, Build, Native, ContentFiles, Analyzers, BuildTransitive","suppressParent":"All","target":"Package","version":"[8.0.3, )"},"Microsoft.Extensions.Configuration":{"target":"Package","version":"[8.0.0, )"},"Microsoft.Extensions.Configuration.Json":{"target":"Package","version":"[8.0.0, )"},"Microsoft.Extensions.Options.ConfigurationExtensions":{"target":"Package","version":"[8.0.0, )"},"MongoDB.Driver":{"target":"Package","version":"[2.24.0, )"},"Npgsql.EntityFrameworkCore.PostgreSQL":{"target":"Package","version":"[8.0.2, )"}},"imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"C:\\Program Files\\dotnet\\sdk\\8.0.202/PortableRuntimeIdentifierGraph.json"}}
"restore":{"projectUniqueName":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Infrastructure\\Infrastructure.csproj","projectName":"Infrastructure","projectPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Infrastructure\\Infrastructure.csproj","outputPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Infrastructure\\obj\\","projectStyle":"PackageReference","originalTargetFrameworks":["net8.0"],"sources":{"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\":{},"https://api.nuget.org/v3/index.json":{}},"frameworks":{"net8.0":{"targetAlias":"net8.0","projectReferences":{"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Application\\Application.csproj":{"projectPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Application\\Application.csproj"},"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Core\\Core.csproj":{"projectPath":"C:\\Users\\Andrei Cerbu\\Documents\\FACULTATE\\CC-FinalProj\\backend\\Core\\Core.csproj"}}}},"warningProperties":{"warnAsError":["NU1605"]}}"frameworks":{"net8.0":{"targetAlias":"net8.0","dependencies":{"Microsoft.EntityFrameworkCore":{"target":"Package","version":"[8.0.3, )"},"Microsoft.EntityFrameworkCore.Design":{"include":"Runtime, Build, Native, ContentFiles, Analyzers, BuildTransitive","suppressParent":"All","target":"Package","version":"[8.0.3, )"},"Microsoft.EntityFrameworkCore.Relational":{"target":"Package","version":"[8.0.3, )"},"Microsoft.Extensions.Configuration":{"target":"Package","version":"[8.0.0, )"},"Microsoft.Extensions.Configuration.Json":{"target":"Package","version":"[8.0.0, )"},"Microsoft.Extensions.Options.ConfigurationExtensions":{"target":"Package","version":"[8.0.0, )"},"MongoDB.Driver":{"target":"Package","version":"[2.24.0, )"},"Npgsql.EntityFrameworkCore.PostgreSQL":{"target":"Package","version":"[8.0.2, )"}},"imports":["net461","net462","net47","net471","net472","net48","net481"],"assetTargetFallback":true,"warn":true,"frameworkReferences":{"Microsoft.NETCore.App":{"privateAssets":"all"}},"runtimeIdentifierGraphPath":"C:\\Program Files\\dotnet\\sdk\\8.0.202/PortableRuntimeIdentifierGraph.json"}}
@@ -1 +1 @@
17122552827017860
17125075152023106