From ab56bf3c205d7ba2cfbd67a2213410191a12bf9c Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Sun, 12 Jan 2025 12:16:24 +0330 Subject: [PATCH] Downgrade target frameworks and update dependencies - Downgraded target frameworks from net9.0 to net8.0 in multiple projects. - Updated package references to older versions across various projects. - Added and updated using directives in several files for better dependency management. - Modified `Student` entity to make `SectionId` nullable and updated related methods. - Introduced new migration files to reflect schema changes in the database. - Added new `ValidationException` and `ValidationBehavior` classes for improved validation handling. - Updated `launchUrl` in `launchSettings.json` to include `/swagger/v1`. - Reformatted constructor parameters in `Patient.cs` for better readability. - Removed `Sections` property from `University.cs`. - Changed `PatientId` and `Patient` properties in `MedicalHistory.cs` to internal. --- .../Production/appsettings.Production.json | 2 +- DocuMed.Api/Controllers/PatientController.cs | 6 +- DocuMed.Api/DocuMed.Api.csproj | 207 ++-- DocuMed.Api/Program.cs | 20 + DocuMed.Api/Properties/launchSettings.json | 2 +- DocuMed.Common/DocuMed.Common.csproj | 10 +- .../Models/Exception/ValidationException.cs | 20 + DocuMed.Core/CoreServices/AccountService.cs | 6 +- DocuMed.Core/DocuMed.Core.csproj | 86 +- DocuMed.Domain/DocuMed.Domain.csproj | 13 +- DocuMed.Domain/Dtos/SmallDtos/PatientSDto.cs | 4 +- DocuMed.Domain/Dtos/SmallDtos/StudentSDto.cs | 2 +- DocuMed.Domain/Entities/City/University.cs | 2 - .../Entities/MedicalHistory/MedicalHistory.cs | 4 +- DocuMed.Domain/Entities/Patients/Patient.cs | 6 +- .../Entities/Staffs/Student.Aggregate.cs | 7 +- DocuMed.Domain/Entities/Staffs/Student.cs | 5 +- DocuMed.Domain/Mappers/StudentMapper.g.cs | 6 +- .../DocuMed.Infrastructure.csproj | 56 +- DocuMed.PWA/DocuMed.PWA.csproj | 124 +- .../Behaviors/ValidationBehavior.cs | 30 + DocuMed.Repository/DocuMed.Repository.csproj | 15 +- .../UpdateMedicalHistoryCommandHandler.cs | 3 +- .../20250112081155_Init.Designer.cs | 1050 +++++++++++++++++ .../Migrations/20250112081155_Init.cs | 758 ++++++++++++ ..._UpdateStudentSetSectionIdNull.Designer.cs | 1048 ++++++++++++++++ ...112083704_UpdateStudentSetSectionIdNull.cs | 68 ++ ...250112083957_EditUniAndSection.Designer.cs | 1034 ++++++++++++++++ .../20250112083957_EditUniAndSection.cs | 56 + .../ApplicationContextModelSnapshot.cs | 1031 ++++++++++++++++ 30 files changed, 5405 insertions(+), 276 deletions(-) create mode 100644 DocuMed.Common/Models/Exception/ValidationException.cs create mode 100644 DocuMed.Repository/Behaviors/ValidationBehavior.cs create mode 100644 DocuMed.Repository/Migrations/20250112081155_Init.Designer.cs create mode 100644 DocuMed.Repository/Migrations/20250112081155_Init.cs create mode 100644 DocuMed.Repository/Migrations/20250112083704_UpdateStudentSetSectionIdNull.Designer.cs create mode 100644 DocuMed.Repository/Migrations/20250112083704_UpdateStudentSetSectionIdNull.cs create mode 100644 DocuMed.Repository/Migrations/20250112083957_EditUniAndSection.Designer.cs create mode 100644 DocuMed.Repository/Migrations/20250112083957_EditUniAndSection.cs create mode 100644 DocuMed.Repository/Migrations/ApplicationContextModelSnapshot.cs diff --git a/DocuMed.Api/AppSettings/Production/appsettings.Production.json b/DocuMed.Api/AppSettings/Production/appsettings.Production.json index d2e5976..9f11b6c 100644 --- a/DocuMed.Api/AppSettings/Production/appsettings.Production.json +++ b/DocuMed.Api/AppSettings/Production/appsettings.Production.json @@ -13,7 +13,7 @@ }, "SiteSettings": { "KaveNegarApiKey": "3735494B4143727A794346457461576A2B4B6668414973424E333561505A694B", - "BaseUrl": "http://localhost:32769", + "BaseUrl": "http://localhost:32780", "UserSetting": { "Username": "Root", "Email": "info@brizco.io", diff --git a/DocuMed.Api/Controllers/PatientController.cs b/DocuMed.Api/Controllers/PatientController.cs index 8f9166e..a94d046 100644 --- a/DocuMed.Api/Controllers/PatientController.cs +++ b/DocuMed.Api/Controllers/PatientController.cs @@ -1,4 +1,8 @@ -namespace DocuMed.Api.Controllers; +using DocuMed.Domain.CommandQueries.Queries; +using DocuMed.Domain.Models; +using MediatR; + +namespace DocuMed.Api.Controllers; public class PatientController : ICarterModule { diff --git a/DocuMed.Api/DocuMed.Api.csproj b/DocuMed.Api/DocuMed.Api.csproj index 0b5151c..9aacdcc 100644 --- a/DocuMed.Api/DocuMed.Api.csproj +++ b/DocuMed.Api/DocuMed.Api.csproj @@ -1,112 +1,111 @@ - - net9.0 - enable - enable - Linux - ..\docker-compose.dcproj - 1.3.2.1 - 1.3.2.1 - + + net8.0 + enable + enable + Linux + ..\docker-compose.dcproj + 1.3.2.1 + 1.3.2.1 + - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + diff --git a/DocuMed.Api/Program.cs b/DocuMed.Api/Program.cs index e1870af..bb269f6 100644 --- a/DocuMed.Api/Program.cs +++ b/DocuMed.Api/Program.cs @@ -1,4 +1,6 @@ using DocuMed.Api.WebFramework.MiddleWares; +using DocuMed.Repository.Behaviors; +using MediatR.Extensions.Autofac.DependencyInjection.Builder; var builder = WebApplication.CreateBuilder(args); builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory()); @@ -65,6 +67,24 @@ builder.Host.ConfigureContainer(builder => .AssignableTo() .AsImplementedInterfaces() .InstancePerLifetimeScope(); + + builder.RegisterMediatR(MediatRConfigurationBuilder + .Create(typeof(RepositoryConfig).Assembly) + .WithCustomPipelineBehavior(typeof(ValidationBehavior<,>)) + .WithAllOpenGenericHandlerTypesRegistered() + .Build()); + + builder.RegisterMediatR(MediatRConfigurationBuilder + .Create(typeof(CoreConfig).Assembly) + .WithCustomPipelineBehavior(typeof(ValidationBehavior<,>)) + .WithAllOpenGenericHandlerTypesRegistered() + .Build()); + + builder.RegisterMediatR(MediatRConfigurationBuilder + .Create(typeof(DomainConfig).Assembly) + .WithCustomPipelineBehavior(typeof(ValidationBehavior<,>)) + .WithAllOpenGenericHandlerTypesRegistered() + .Build()); }); var app = builder.Build(); diff --git a/DocuMed.Api/Properties/launchSettings.json b/DocuMed.Api/Properties/launchSettings.json index d544ef5..d908901 100644 --- a/DocuMed.Api/Properties/launchSettings.json +++ b/DocuMed.Api/Properties/launchSettings.json @@ -20,7 +20,7 @@ "Docker": { "commandName": "Docker", "launchBrowser": true, - "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", + "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger/v1", "environmentVariables": { "ASPNETCORE_URLS": "http://+:80" }, diff --git a/DocuMed.Common/DocuMed.Common.csproj b/DocuMed.Common/DocuMed.Common.csproj index 0826a13..a890827 100644 --- a/DocuMed.Common/DocuMed.Common.csproj +++ b/DocuMed.Common/DocuMed.Common.csproj @@ -1,7 +1,7 @@ - - net9.0 + + net8.0 10 enable @@ -24,7 +24,7 @@ - + @@ -33,4 +33,4 @@ - + \ No newline at end of file diff --git a/DocuMed.Common/Models/Exception/ValidationException.cs b/DocuMed.Common/Models/Exception/ValidationException.cs new file mode 100644 index 0000000..7286d7b --- /dev/null +++ b/DocuMed.Common/Models/Exception/ValidationException.cs @@ -0,0 +1,20 @@ +namespace DocuMed.Common.Models.Exception; + +public class ValidationException : System.Exception +{ + public ValidationException() : base("Validation has been failed") + { + + } + + public ValidationException(params ValidationError[] validationErrors) : base($"{string.Join(",", validationErrors.Select(v => v.ErrorMessage))}") + { + + } + + public ValidationException(List validationErrors) : base($"{string.Join(",", validationErrors.Select(v => v.ErrorMessage))}") + { + + } +} +public sealed record ValidationError(string PropertyName, string ErrorMessage); \ No newline at end of file diff --git a/DocuMed.Core/CoreServices/AccountService.cs b/DocuMed.Core/CoreServices/AccountService.cs index 2bf9f94..a4cacdb 100644 --- a/DocuMed.Core/CoreServices/AccountService.cs +++ b/DocuMed.Core/CoreServices/AccountService.cs @@ -114,7 +114,9 @@ public class AccountService( .FirstOrDefaultAsync(f => f.UserId == user.Id, cancellationToken); if (student == null) { - student = Student.Create(requestDto.UniversityId,requestDto.SectionId,user.Id); + student = Student.Create(requestDto.UniversityId, user.Id); + if (requestDto.SectionId != default) + student.SetSection(requestDto.SectionId); repositoryWrapper.SetRepository().Add(student); await repositoryWrapper.SaveChangesAsync(cancellationToken); } @@ -126,7 +128,7 @@ public class AccountService( return await CompleteLogin(user, cancellationToken); } - private async Task> CompleteLogin(ApplicationUser user, CancellationToken cancellationToken) + private async Task> CompleteLogin(ApplicationUser user, CancellationToken cancellationToken) { var token = await jwtService.Generate(user); var student = await repositoryWrapper.SetRepository().TableNoTracking diff --git a/DocuMed.Core/DocuMed.Core.csproj b/DocuMed.Core/DocuMed.Core.csproj index f00d758..ba3a179 100644 --- a/DocuMed.Core/DocuMed.Core.csproj +++ b/DocuMed.Core/DocuMed.Core.csproj @@ -1,10 +1,10 @@  - - net9.0 - enable - enable - + + net8.0 + enable + enable + @@ -12,47 +12,47 @@ - + - - - + + + - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DocuMed.Domain/DocuMed.Domain.csproj b/DocuMed.Domain/DocuMed.Domain.csproj index 82f2233..c16dd0e 100644 --- a/DocuMed.Domain/DocuMed.Domain.csproj +++ b/DocuMed.Domain/DocuMed.Domain.csproj @@ -1,22 +1,22 @@  - net9.0 - enable - enable - + net8.0 + enable + enable + - +