From c82109918fe09714efacb65048915a2a190d7e22 Mon Sep 17 00:00:00 2001 From: Matvey Bunos Date: Sat, 16 Mar 2024 13:44:19 +0300 Subject: [PATCH 01/12] kek --- Directory.Packages.props | 17 ++++++++--- .../DoctorsHelp.Application.Contracts.csproj | 3 -- .../DoctorsHelp.Application.Models.csproj | 3 +- src/DoctorsHelp/DoctorsHelp.csproj | 8 +++-- src/DoctorsHelp/Program.cs | 25 ++++++++++++---- src/DoctorsHelp/Util/Profiles.cs | 8 +++++ .../Contexts/ApplicationDbContext.cs | 30 +++++++++++++++++++ ...torsHelp.Infrastructure.Persistence.csproj | 8 +++++ .../Extensions/ServiceCollectionExtensions.cs | 10 +++++++ 9 files changed, 95 insertions(+), 17 deletions(-) create mode 100644 src/DoctorsHelp/Util/Profiles.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Contexts/ApplicationDbContext.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index a9605f2..aa16be3 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -4,15 +4,24 @@ false - - - + + + + + + + + + + - + + + \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/DoctorsHelp.Application.Contracts.csproj b/src/Application/DoctorsHelp.Application.Contracts/DoctorsHelp.Application.Contracts.csproj index a613ac5..9ea7cb0 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/DoctorsHelp.Application.Contracts.csproj +++ b/src/Application/DoctorsHelp.Application.Contracts/DoctorsHelp.Application.Contracts.csproj @@ -4,7 +4,4 @@ - - - \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Models/DoctorsHelp.Application.Models.csproj b/src/Application/DoctorsHelp.Application.Models/DoctorsHelp.Application.Models.csproj index 35e3d84..6b512ec 100644 --- a/src/Application/DoctorsHelp.Application.Models/DoctorsHelp.Application.Models.csproj +++ b/src/Application/DoctorsHelp.Application.Models/DoctorsHelp.Application.Models.csproj @@ -1,2 +1 @@ - - + diff --git a/src/DoctorsHelp/DoctorsHelp.csproj b/src/DoctorsHelp/DoctorsHelp.csproj index f201af4..7d12243 100644 --- a/src/DoctorsHelp/DoctorsHelp.csproj +++ b/src/DoctorsHelp/DoctorsHelp.csproj @@ -1,15 +1,17 @@ - - + + - + + + diff --git a/src/DoctorsHelp/Program.cs b/src/DoctorsHelp/Program.cs index 7fe3860..4ecdae1 100644 --- a/src/DoctorsHelp/Program.cs +++ b/src/DoctorsHelp/Program.cs @@ -3,10 +3,14 @@ using DoctorsHelp.Application.Extensions; using DoctorsHelp.Infrastructure.Persistence.Extensions; using DoctorsHelp.Presentation.Http.Extensions; +using DoctorsHelp.Util; using Itmo.Dev.Platform.Common.Extensions; using Itmo.Dev.Platform.Logging.Extensions; using Microsoft.Extensions.Options; using Newtonsoft.Json; +using Testcontainers.PostgreSql; + +const Profiles currentProfile = Profiles.Local; WebApplicationBuilder builder = WebApplication.CreateBuilder(args); @@ -16,23 +20,34 @@ builder.Services.AddSingleton(sp => sp.GetRequiredService>().Value); builder.Services.AddApplication(); -builder.Services.AddInfrastructurePersistence(); + +if (currentProfile.Equals(Profiles.Local)) +{ + var postgres = new PostgreSqlBuilder() + .WithImage("postgres:15-alpine") + .Build(); + + await postgres.StartAsync(); + + builder.Configuration["Infrastructure:Persistence:Postgres:ConnectionString"] = postgres.GetConnectionString(); +} + +builder.Services.AddInfrastructurePersistence(builder.Configuration); builder.Services .AddControllers() .AddNewtonsoftJson() .AddPresentationHttp(); -builder.Services.AddSwaggerGen().AddEndpointsApiExplorer(); - +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); builder.Host.AddPlatformSerilog(builder.Configuration); builder.Services.AddUtcDateTimeProvider(); WebApplication app = builder.Build(); -app.UseRouting(); app.UseSwagger(); app.UseSwaggerUI(); - +app.UseRouting(); app.MapControllers(); await app.RunAsync(); \ No newline at end of file diff --git a/src/DoctorsHelp/Util/Profiles.cs b/src/DoctorsHelp/Util/Profiles.cs new file mode 100644 index 0000000..79dfd46 --- /dev/null +++ b/src/DoctorsHelp/Util/Profiles.cs @@ -0,0 +1,8 @@ +namespace DoctorsHelp.Util; + +public enum Profiles +{ + Local, + + Prod, +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Contexts/ApplicationDbContext.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Contexts/ApplicationDbContext.cs new file mode 100644 index 0000000..e52df6c --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Contexts/ApplicationDbContext.cs @@ -0,0 +1,30 @@ +using Infrastructure.Persistence.Models; +using Microsoft.EntityFrameworkCore; + +namespace DoctorsHelp.Infrastructure.Persistence.Contexts; + +public class ApplicationDbContext : DbContext +{ + public ApplicationDbContext() { } + + public ApplicationDbContext(DbContextOptions options) : base(options) { } + + required public DbSet Users { get; set; } + + required public DbSet Appointments { get; set; } + + required public DbSet Employees { get; set; } + + required public DbSet Reviews { get; set; } + + required public DbSet Schedules { get; set; } + + required public DbSet Specializations { get; set; } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.ApplyConfigurationsFromAssembly(typeof(ApplicationDbContext).Assembly); + + base.OnModelCreating(modelBuilder); + } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/DoctorsHelp.Infrastructure.Persistence.csproj b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/DoctorsHelp.Infrastructure.Persistence.csproj index 2aec2b3..e3a3b03 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/DoctorsHelp.Infrastructure.Persistence.csproj +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/DoctorsHelp.Infrastructure.Persistence.csproj @@ -9,4 +9,12 @@ + + + + + + + + \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Extensions/ServiceCollectionExtensions.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Extensions/ServiceCollectionExtensions.cs index dbad899..71bb668 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Extensions/ServiceCollectionExtensions.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Extensions/ServiceCollectionExtensions.cs @@ -1,8 +1,11 @@ using DoctorsHelp.Application.Abstractions.Persistence; +using DoctorsHelp.Infrastructure.Persistence.Contexts; using DoctorsHelp.Infrastructure.Persistence.Migrations; using DoctorsHelp.Infrastructure.Persistence.Plugins; using Itmo.Dev.Platform.Postgres.Extensions; using Itmo.Dev.Platform.Postgres.Plugins; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace DoctorsHelp.Infrastructure.Persistence.Extensions; @@ -22,4 +25,11 @@ public static IServiceCollection AddInfrastructurePersistence(this IServiceColle return collection; } + + public static IServiceCollection AddInfrastructurePersistence(this IServiceCollection collection, IConfiguration configuration) + { + collection.AddDbContext(options => + options.UseNpgsql(configuration.GetSection("Infrastructure:Persistence:Postgres:ConnectionString").Value)); + return collection; + } } \ No newline at end of file From 6bc604afb4c5531fddb24fb79e15473fed499131 Mon Sep 17 00:00:00 2001 From: AlexYrkn <61319606+AlexYrkn@users.noreply.github.com> Date: Sat, 16 Mar 2024 13:50:15 +0300 Subject: [PATCH 02/12] Models + repositories --- .../Models/AppointmentModel.cs | 20 +++++++ .../Models/EmployeeModel.cs | 18 ++++++ .../Models/ReviewModel.cs | 18 ++++++ .../Models/ScheduleModel.cs | 16 +++++ .../Models/SpecializationModel.cs | 10 ++++ .../Models/UserModel.cs | 20 +++++++ .../Repositories/AppointmentRepository.cs | 42 +++++++++++++ .../Repositories/EmployeeRepository.cs | 40 +++++++++++++ .../Repositories/RepositoryBase.cs | 60 +++++++++++++++++++ .../Repositories/ReviewRepository.cs | 42 +++++++++++++ .../Repositories/ScheduleRepository.cs | 40 +++++++++++++ .../Repositories/SpecializationRepository.cs | 36 +++++++++++ .../Repositories/UserRepository.cs | 46 ++++++++++++++ 13 files changed, 408 insertions(+) create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/AppointmentModel.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ReviewModel.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ScheduleModel.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/UserModel.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/AppointmentRepository.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ReviewRepository.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ScheduleRepository.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/UserRepository.cs diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/AppointmentModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/AppointmentModel.cs new file mode 100644 index 0000000..4d23d30 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/AppointmentModel.cs @@ -0,0 +1,20 @@ +namespace Infrastructure.Persistence.Models; + +public class AppointmentModel +{ + public int Id { get; set; } + + public Guid PatientId { get; set; } + + public int ScheduleId { get; set; } + + public DateTime CreatedAt { get; set; } + + public DateTime UpdatedAt { get; set; } + + public int Status { get; set; } + + public UserModel? Patient { get; set; } + + public ScheduleModel? Schedule { get; set; } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs new file mode 100644 index 0000000..28fd73f --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs @@ -0,0 +1,18 @@ +namespace Infrastructure.Persistence.Models; + +public class EmployeeModel +{ + public int Id { get; set; } + + public Guid UserId { get; set; } + + public int SpecializationId { get; set; } + + public string? Graduate { get; set; } + + public string? Experience { get; set; } + + public UserModel? User { get; set; } + + public SpecializationModel? Specialization { get; set; } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ReviewModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ReviewModel.cs new file mode 100644 index 0000000..ddc306a --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ReviewModel.cs @@ -0,0 +1,18 @@ +namespace Infrastructure.Persistence.Models; + +public class ReviewModel +{ + public int Id { get; set; } + + public int AppointmentId { get; set; } + + public int Grade { get; set; } + + public string? Comment { get; set; } + + public DateTime CreatedAt { get; set; } + + public DateTime UpdatedAt { get; set; } + + public AppointmentModel? Appointment { get; set; } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ScheduleModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ScheduleModel.cs new file mode 100644 index 0000000..358b56c --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ScheduleModel.cs @@ -0,0 +1,16 @@ +namespace Infrastructure.Persistence.Models; + +public class ScheduleModel +{ + public int Id { get; set; } + + public int EmployeeId { get; set; } + + public DateTime DateStart { get; set; } + + public DateTime DateEnd { get; set; } + + public int Status { get; set; } + + public EmployeeModel? Employee { get; set; } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs new file mode 100644 index 0000000..082baa8 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs @@ -0,0 +1,10 @@ +namespace Infrastructure.Persistence.Models; + +public class SpecializationModel +{ + public int Id { get; set; } + + public string? Name { get; set; } + + public string? Description { get; set; } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/UserModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/UserModel.cs new file mode 100644 index 0000000..49d36c9 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/UserModel.cs @@ -0,0 +1,20 @@ +namespace Infrastructure.Persistence.Models; + +public class UserModel +{ + public Guid Id { get; set; } + + public string? Name { get; set; } + + public string? Surname { get; set; } + + public string? Phone { get; set; } + + public string? Email { get; set; } + + public string? HashedPassword { get; set; } + + public DateOnly Birthdate { get; set; } + + public string? Role { get; set; } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/AppointmentRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/AppointmentRepository.cs new file mode 100644 index 0000000..86c9a3c --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/AppointmentRepository.cs @@ -0,0 +1,42 @@ +using DoctorsHelp.Application.Models; +using DoctorsHelp.Infrastructure.Persistence.Contexts; +using Infrastructure.Persistence.Models; +using Microsoft.EntityFrameworkCore; + +namespace DoctorsHelp.Infrastructure.Persistence.Repositories; + +public class AppointmentRepository : RepositoryBase +{ + public AppointmentRepository(ApplicationDbContext context) : base(context) + { + } + + protected override DbSet DbSet => ((ApplicationDbContext)Context).Appointments; + + protected override AppointmentModel MapFrom(Appointment entity) + { + return new AppointmentModel + { + Id = entity.Id, + PatientId = entity.Patient?.Id ?? Guid.Empty, + ScheduleId = entity.Schedule?.Id ?? 0, + CreatedAt = entity.CreatedAt, + UpdatedAt = entity.UpdatedAt, + Status = entity.Status, + }; + } + + protected override bool Equal(Appointment entity, AppointmentModel model) + { + return entity.Id == model.Id; + } + + protected override void UpdateModel(AppointmentModel model, Appointment entity) + { + model.PatientId = entity.Patient?.Id ?? Guid.Empty; + model.ScheduleId = entity.Schedule?.Id ?? 0; + model.CreatedAt = entity.CreatedAt; + model.UpdatedAt = entity.UpdatedAt; + model.Status = entity.Status; + } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs new file mode 100644 index 0000000..52509c2 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs @@ -0,0 +1,40 @@ +using DoctorsHelp.Application.Models; +using DoctorsHelp.Infrastructure.Persistence.Contexts; +using Infrastructure.Persistence.Models; +using Microsoft.EntityFrameworkCore; + +namespace DoctorsHelp.Infrastructure.Persistence.Repositories; + +public class EmployeeRepository : RepositoryBase +{ + public EmployeeRepository(ApplicationDbContext context) : base(context) + { + } + + protected override DbSet DbSet => ((ApplicationDbContext)Context).Employees; + + protected override EmployeeModel MapFrom(Employee entity) + { + return new EmployeeModel + { + Id = entity.Id, + UserId = entity.User?.Id ?? Guid.Empty, + SpecializationId = entity.Specialization, + Graduate = entity.Graduate, + Experience = entity.Experience, + }; + } + + protected override bool Equal(Employee entity, EmployeeModel model) + { + return entity.Id == model.Id; + } + + protected override void UpdateModel(EmployeeModel model, Employee entity) + { + model.UserId = entity.User?.Id ?? Guid.Empty; + model.SpecializationId = entity.Specialization; + model.Graduate = entity.Graduate; + model.Experience = entity.Experience; + } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs new file mode 100644 index 0000000..ce4a4d7 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs @@ -0,0 +1,60 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.ChangeTracking; + +namespace DoctorsHelp.Infrastructure.Persistence.Repositories; + +public abstract class RepositoryBase where TModel : class +{ + #pragma warning disable IDE0032 + private readonly DbContext _context; + + protected DbContext Context => _context; + + protected RepositoryBase(DbContext context) + { + this._context = context; + } + + protected abstract DbSet DbSet { get; } + + public void Add(TEntity entity) + { + TModel model = MapFrom(entity); + DbSet.Add(model); + } + + public void AddRange(IEnumerable entities) + { + IEnumerable models = entities.Select(MapFrom); + DbSet.AddRange(models); + } + + public void Update(TEntity entity) + { + EntityEntry entry = GetEntry(entity); + UpdateModel(entry.Entity, entity); + + entry.State = EntityState.Modified; + } + + public void Remove(TEntity entity) + { + EntityEntry entry = GetEntry(entity); + entry.State = entry.State is EntityState.Added ? EntityState.Detached : EntityState.Deleted; + } + + protected abstract TModel MapFrom(TEntity entity); + + protected abstract bool Equal(TEntity entity, TModel model); + + protected abstract void UpdateModel(TModel model, TEntity entity); + + private EntityEntry GetEntry(TEntity entity) + { + TModel? existing = DbSet.Local.FirstOrDefault(model => Equal(entity, model)); + + return existing is not null + ? _context.Entry(existing) + : DbSet.Attach(MapFrom(entity)); + } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ReviewRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ReviewRepository.cs new file mode 100644 index 0000000..d00786a --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ReviewRepository.cs @@ -0,0 +1,42 @@ +using DoctorsHelp.Application.Models; +using DoctorsHelp.Infrastructure.Persistence.Contexts; +using Infrastructure.Persistence.Models; +using Microsoft.EntityFrameworkCore; + +namespace DoctorsHelp.Infrastructure.Persistence.Repositories; + +public class ReviewRepository : RepositoryBase +{ + public ReviewRepository(ApplicationDbContext context) : base(context) + { + } + + protected override DbSet DbSet => ((ApplicationDbContext)Context).Reviews; + + protected override ReviewModel MapFrom(Review entity) + { + return new ReviewModel + { + Id = entity.Id, + AppointmentId = entity.Appointment?.Id ?? 0, + Grade = entity.Grade, + Comment = entity.Comment, + CreatedAt = entity.CreatedAt, + UpdatedAt = entity.UpdatedAt, + }; + } + + protected override bool Equal(Review entity, ReviewModel model) + { + return entity.Id == model.Id; + } + + protected override void UpdateModel(ReviewModel model, Review entity) + { + model.AppointmentId = entity.Appointment?.Id ?? 0; + model.Grade = entity.Grade; + model.Comment = entity.Comment; + model.CreatedAt = entity.CreatedAt; + model.UpdatedAt = entity.UpdatedAt; + } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ScheduleRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ScheduleRepository.cs new file mode 100644 index 0000000..8adec08 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ScheduleRepository.cs @@ -0,0 +1,40 @@ +using DoctorsHelp.Application.Models; +using DoctorsHelp.Infrastructure.Persistence.Contexts; +using Infrastructure.Persistence.Models; +using Microsoft.EntityFrameworkCore; + +namespace DoctorsHelp.Infrastructure.Persistence.Repositories; + +public class ScheduleRepository : RepositoryBase +{ + public ScheduleRepository(ApplicationDbContext context) : base(context) + { + } + + protected override DbSet DbSet => ((ApplicationDbContext)Context).Schedules; + + protected override ScheduleModel MapFrom(Schedule entity) + { + return new ScheduleModel + { + Id = entity.Id, + EmployeeId = entity.Employee?.Id ?? 0, + DateStart = entity.DateStart, + DateEnd = entity.DateEnd, + Status = entity.Status, + }; + } + + protected override bool Equal(Schedule entity, ScheduleModel model) + { + return entity.Id == model.Id; + } + + protected override void UpdateModel(ScheduleModel model, Schedule entity) + { + model.EmployeeId = entity.Employee?.Id ?? 0; + model.DateStart = entity.DateStart; + model.DateEnd = entity.DateEnd; + model.Status = entity.Status; + } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs new file mode 100644 index 0000000..9c0d55d --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs @@ -0,0 +1,36 @@ +using DoctorsHelp.Application.Models; +using DoctorsHelp.Infrastructure.Persistence.Contexts; +using Infrastructure.Persistence.Models; +using Microsoft.EntityFrameworkCore; + +namespace DoctorsHelp.Infrastructure.Persistence.Repositories; + +public class SpecializationRepository : RepositoryBase +{ + public SpecializationRepository(ApplicationDbContext context) : base(context) + { + } + + protected override DbSet DbSet => ((ApplicationDbContext)Context).Specializations; + + protected override SpecializationModel MapFrom(Specialization entity) + { + return new SpecializationModel + { + Id = entity.Id, + Name = entity.Name, + Description = entity.Description, + }; + } + + protected override bool Equal(Specialization entity, SpecializationModel model) + { + return entity.Id == model.Id; + } + + protected override void UpdateModel(SpecializationModel model, Specialization entity) + { + model.Name = entity.Name; + model.Description = entity.Description; + } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/UserRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/UserRepository.cs new file mode 100644 index 0000000..f40e82e --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/UserRepository.cs @@ -0,0 +1,46 @@ +using DoctorsHelp.Application.Models; +using DoctorsHelp.Infrastructure.Persistence.Contexts; +using Infrastructure.Persistence.Models; +using Microsoft.EntityFrameworkCore; + +namespace DoctorsHelp.Infrastructure.Persistence.Repositories; + +public class UserRepository : RepositoryBase +{ + public UserRepository(ApplicationDbContext context) : base(context) + { + } + + protected override DbSet DbSet => ((ApplicationDbContext)Context).Users; + + protected override UserModel MapFrom(User entity) + { + return new UserModel + { + Id = entity.Id, + Name = entity.Name, + Surname = entity.Surname, + Phone = entity.Phone, + Email = entity.Email, + HashedPassword = entity.HashedPassword, + Birthdate = entity.Birthdate, + Role = entity.Role, + }; + } + + protected override bool Equal(User entity, UserModel model) + { + return entity.Id == model.Id; + } + + protected override void UpdateModel(UserModel model, User entity) + { + model.Name = entity.Name; + model.Surname = entity.Surname; + model.Phone = entity.Phone; + model.Email = entity.Email; + model.HashedPassword = entity.HashedPassword; + model.Birthdate = entity.Birthdate; + model.Role = entity.Role; + } +} \ No newline at end of file From b9335630d0c1c56ca9872f2fb8396234a115afc5 Mon Sep 17 00:00:00 2001 From: AlexYrkn <61319606+AlexYrkn@users.noreply.github.com> Date: Sat, 16 Mar 2024 17:01:57 +0300 Subject: [PATCH 03/12] repo + models fixes --- .../Models/AppointmentModel.cs | 8 +++---- .../Models/EmployeeModel.cs | 4 ++-- .../Models/ReviewModel.cs | 8 +++---- .../Models/ScheduleModel.cs | 8 +++---- .../Models/SpecializationModel.cs | 2 +- .../Models/UserModel.cs | 4 ++-- .../Repositories/AppointmentRepository.cs | 19 ++++++++++++++- .../Repositories/EmployeeRepository.cs | 23 ++++++++++++++++--- .../Repositories/RepositoryBase.cs | 2 +- .../Repositories/ReviewRepository.cs | 19 ++++++++++++++- .../Repositories/ScheduleRepository.cs | 14 ++++++++++- .../Repositories/SpecializationRepository.cs | 19 ++++++++++++++- .../Repositories/UserRepository.cs | 19 ++++++++++++++- 13 files changed, 123 insertions(+), 26 deletions(-) diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/AppointmentModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/AppointmentModel.cs index 4d23d30..cda19da 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/AppointmentModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/AppointmentModel.cs @@ -2,17 +2,17 @@ namespace Infrastructure.Persistence.Models; public class AppointmentModel { - public int Id { get; set; } + public int? Id { get; set; } public Guid PatientId { get; set; } public int ScheduleId { get; set; } - public DateTime CreatedAt { get; set; } + public DateTime? CreatedAt { get; set; } - public DateTime UpdatedAt { get; set; } + public DateTime? UpdatedAt { get; set; } - public int Status { get; set; } + public int? Status { get; set; } public UserModel? Patient { get; set; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs index 28fd73f..634d9fd 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs @@ -2,11 +2,11 @@ namespace Infrastructure.Persistence.Models; public class EmployeeModel { - public int Id { get; set; } + public int? Id { get; set; } public Guid UserId { get; set; } - public int SpecializationId { get; set; } + public int? SpecializationId { get; set; } public string? Graduate { get; set; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ReviewModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ReviewModel.cs index ddc306a..08f3dfc 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ReviewModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ReviewModel.cs @@ -2,17 +2,17 @@ namespace Infrastructure.Persistence.Models; public class ReviewModel { - public int Id { get; set; } + public int? Id { get; set; } public int AppointmentId { get; set; } - public int Grade { get; set; } + public int? Grade { get; set; } public string? Comment { get; set; } - public DateTime CreatedAt { get; set; } + public DateTime? CreatedAt { get; set; } - public DateTime UpdatedAt { get; set; } + public DateTime? UpdatedAt { get; set; } public AppointmentModel? Appointment { get; set; } } \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ScheduleModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ScheduleModel.cs index 358b56c..5a432c3 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ScheduleModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ScheduleModel.cs @@ -2,15 +2,15 @@ namespace Infrastructure.Persistence.Models; public class ScheduleModel { - public int Id { get; set; } + public int? Id { get; set; } public int EmployeeId { get; set; } - public DateTime DateStart { get; set; } + public DateTime? DateStart { get; set; } - public DateTime DateEnd { get; set; } + public DateTime? DateEnd { get; set; } - public int Status { get; set; } + public int? Status { get; set; } public EmployeeModel? Employee { get; set; } } \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs index 082baa8..277cb44 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs @@ -2,7 +2,7 @@ namespace Infrastructure.Persistence.Models; public class SpecializationModel { - public int Id { get; set; } + public int? Id { get; set; } public string? Name { get; set; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/UserModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/UserModel.cs index 49d36c9..87ba2a9 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/UserModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/UserModel.cs @@ -2,7 +2,7 @@ namespace Infrastructure.Persistence.Models; public class UserModel { - public Guid Id { get; set; } + public Guid? Id { get; set; } public string? Name { get; set; } @@ -14,7 +14,7 @@ public class UserModel public string? HashedPassword { get; set; } - public DateOnly Birthdate { get; set; } + public DateOnly? Birthdate { get; set; } public string? Role { get; set; } } \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/AppointmentRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/AppointmentRepository.cs index 86c9a3c..5ade7f7 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/AppointmentRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/AppointmentRepository.cs @@ -1,16 +1,33 @@ using DoctorsHelp.Application.Models; using DoctorsHelp.Infrastructure.Persistence.Contexts; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; using Infrastructure.Persistence.Models; using Microsoft.EntityFrameworkCore; namespace DoctorsHelp.Infrastructure.Persistence.Repositories; -public class AppointmentRepository : RepositoryBase +public class AppointmentRepository : RepositoryBase, IAppointmentRepository { public AppointmentRepository(ApplicationDbContext context) : base(context) { } + public AppointmentModel GetAppointment(int id) + { + return GetEntry(new Appointment { Id = id }).Entity; + } + + public void UpdateAppointment(Appointment appointment) + { + Update(appointment); + } + + public bool Delete(Appointment appointment) + { + Remove(appointment); + return true; + } + protected override DbSet DbSet => ((ApplicationDbContext)Context).Appointments; protected override AppointmentModel MapFrom(Appointment entity) diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs index 52509c2..ab358e6 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs @@ -1,16 +1,33 @@ using DoctorsHelp.Application.Models; using DoctorsHelp.Infrastructure.Persistence.Contexts; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; using Infrastructure.Persistence.Models; using Microsoft.EntityFrameworkCore; namespace DoctorsHelp.Infrastructure.Persistence.Repositories; -public class EmployeeRepository : RepositoryBase +public class EmployeeRepository : RepositoryBase, IEmployeeRepository { public EmployeeRepository(ApplicationDbContext context) : base(context) { } + public EmployeeModel GetEmployee(int id) + { + return GetEntry(new Employee { Id = id }).Entity; + } + + public void UpdateEmployee(Employee employee) + { + Update(employee); + } + + public bool Delete(Employee employee) + { + Remove(employee); + return true; + } + protected override DbSet DbSet => ((ApplicationDbContext)Context).Employees; protected override EmployeeModel MapFrom(Employee entity) @@ -19,7 +36,7 @@ protected override EmployeeModel MapFrom(Employee entity) { Id = entity.Id, UserId = entity.User?.Id ?? Guid.Empty, - SpecializationId = entity.Specialization, + SpecializationId = entity.Specialization?.Id, Graduate = entity.Graduate, Experience = entity.Experience, }; @@ -33,7 +50,7 @@ protected override bool Equal(Employee entity, EmployeeModel model) protected override void UpdateModel(EmployeeModel model, Employee entity) { model.UserId = entity.User?.Id ?? Guid.Empty; - model.SpecializationId = entity.Specialization; + model.SpecializationId = entity.Specialization?.Id; model.Graduate = entity.Graduate; model.Experience = entity.Experience; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs index ce4a4d7..ee3fdae 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs @@ -49,7 +49,7 @@ public void Remove(TEntity entity) protected abstract void UpdateModel(TModel model, TEntity entity); - private EntityEntry GetEntry(TEntity entity) + protected EntityEntry GetEntry(TEntity entity) { TModel? existing = DbSet.Local.FirstOrDefault(model => Equal(entity, model)); diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ReviewRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ReviewRepository.cs index d00786a..71343bb 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ReviewRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ReviewRepository.cs @@ -1,16 +1,33 @@ using DoctorsHelp.Application.Models; using DoctorsHelp.Infrastructure.Persistence.Contexts; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; using Infrastructure.Persistence.Models; using Microsoft.EntityFrameworkCore; namespace DoctorsHelp.Infrastructure.Persistence.Repositories; -public class ReviewRepository : RepositoryBase +public class ReviewRepository : RepositoryBase, IReviewRepository { public ReviewRepository(ApplicationDbContext context) : base(context) { } + public ReviewModel GetReview(int id) + { + return GetEntry(new Review { Id = id }).Entity; + } + + public void UpdateReview(Review review) + { + Update(review); + } + + public bool Delete(Review review) + { + Remove(review); + return true; + } + protected override DbSet DbSet => ((ApplicationDbContext)Context).Reviews; protected override ReviewModel MapFrom(Review entity) diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ScheduleRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ScheduleRepository.cs index 8adec08..3e838dc 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ScheduleRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ScheduleRepository.cs @@ -1,16 +1,28 @@ using DoctorsHelp.Application.Models; using DoctorsHelp.Infrastructure.Persistence.Contexts; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; using Infrastructure.Persistence.Models; using Microsoft.EntityFrameworkCore; namespace DoctorsHelp.Infrastructure.Persistence.Repositories; -public class ScheduleRepository : RepositoryBase +public class ScheduleRepository : RepositoryBase, IScheduleRepository { public ScheduleRepository(ApplicationDbContext context) : base(context) { } + public ScheduleModel GetSchedule(int id) + { + return GetEntry(new Schedule { Id = id }).Entity; + } + + public bool Delete(Schedule schedule) + { + Remove(schedule); + return true; + } + protected override DbSet DbSet => ((ApplicationDbContext)Context).Schedules; protected override ScheduleModel MapFrom(Schedule entity) diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs index 9c0d55d..532a45c 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs @@ -1,16 +1,33 @@ using DoctorsHelp.Application.Models; using DoctorsHelp.Infrastructure.Persistence.Contexts; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; using Infrastructure.Persistence.Models; using Microsoft.EntityFrameworkCore; namespace DoctorsHelp.Infrastructure.Persistence.Repositories; -public class SpecializationRepository : RepositoryBase +public class SpecializationRepository : RepositoryBase, ISpecializationRepository { public SpecializationRepository(ApplicationDbContext context) : base(context) { } + public void UpdateSpecialization(Specialization specialization) + { + Update(specialization); + } + + public SpecializationModel GetSpecialization(int id) + { + return GetEntry(new Specialization { Id = id }).Entity; + } + + public bool Delete(Specialization specialization) + { + Remove(specialization); + return true; + } + protected override DbSet DbSet => ((ApplicationDbContext)Context).Specializations; protected override SpecializationModel MapFrom(Specialization entity) diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/UserRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/UserRepository.cs index f40e82e..0082838 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/UserRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/UserRepository.cs @@ -1,16 +1,33 @@ using DoctorsHelp.Application.Models; using DoctorsHelp.Infrastructure.Persistence.Contexts; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; using Infrastructure.Persistence.Models; using Microsoft.EntityFrameworkCore; namespace DoctorsHelp.Infrastructure.Persistence.Repositories; -public class UserRepository : RepositoryBase +public class UserRepository : RepositoryBase, IUserRepository { public UserRepository(ApplicationDbContext context) : base(context) { } + public UserModel GetUser(Guid id) + { + return GetEntry(new User { Id = id }).Entity; + } + + public void UpdateUser(User user) + { + Update(user); + } + + public bool Delete(User user) + { + Remove(user); + return true; + } + protected override DbSet DbSet => ((ApplicationDbContext)Context).Users; protected override UserModel MapFrom(User entity) From 6edf68ca0532341efb6c71f053882a018976fa27 Mon Sep 17 00:00:00 2001 From: AlexYrkn <61319606+AlexYrkn@users.noreply.github.com> Date: Sat, 16 Mar 2024 17:06:03 +0300 Subject: [PATCH 04/12] repos interfaces --- .../Interfaces/IAppointmentRepository.cs | 15 +++++++++++++++ .../Interfaces/IEmployeeRepository.cs | 15 +++++++++++++++ .../Interfaces/IReviewRepository.cs | 15 +++++++++++++++ .../Interfaces/IScheduleRepository.cs | 15 +++++++++++++++ .../Interfaces/ISpecializationRepository.cs | 15 +++++++++++++++ .../Interfaces/IUserRepository.cs | 15 +++++++++++++++ 6 files changed, 90 insertions(+) create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IAppointmentRepository.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IEmployeeRepository.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IReviewRepository.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IScheduleRepository.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/ISpecializationRepository.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IUserRepository.cs diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IAppointmentRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IAppointmentRepository.cs new file mode 100644 index 0000000..0d999cb --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IAppointmentRepository.cs @@ -0,0 +1,15 @@ +using DoctorsHelp.Application.Models; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Infrastructure.Persistence.Interfaces; + +public interface IAppointmentRepository +{ + void Add(Appointment appointment); + + AppointmentModel GetAppointment(int id); + + void UpdateAppointment(Appointment appointment); + + bool Delete(Appointment appointment); +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IEmployeeRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IEmployeeRepository.cs new file mode 100644 index 0000000..c066bbc --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IEmployeeRepository.cs @@ -0,0 +1,15 @@ +using DoctorsHelp.Application.Models; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Infrastructure.Persistence.Interfaces; + +public interface IEmployeeRepository +{ + void Add(Employee employee); + + EmployeeModel GetEmployee(int id); + + void UpdateEmployee(Employee employee); + + bool Delete(Employee employee); +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IReviewRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IReviewRepository.cs new file mode 100644 index 0000000..8314493 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IReviewRepository.cs @@ -0,0 +1,15 @@ +using DoctorsHelp.Application.Models; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Infrastructure.Persistence.Interfaces; + +public interface IReviewRepository +{ + void Add(Review review); + + ReviewModel GetReview(int id); + + void UpdateReview(Review review); + + bool Delete(Review review); +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IScheduleRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IScheduleRepository.cs new file mode 100644 index 0000000..1e6da01 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IScheduleRepository.cs @@ -0,0 +1,15 @@ +using DoctorsHelp.Application.Models; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Infrastructure.Persistence.Interfaces; + +public interface IScheduleRepository +{ + void Add(Schedule schedule); + + ScheduleModel GetSchedule(int id); + + void Update(Schedule schedule); + + bool Delete(Schedule schedule); +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/ISpecializationRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/ISpecializationRepository.cs new file mode 100644 index 0000000..02c66ef --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/ISpecializationRepository.cs @@ -0,0 +1,15 @@ +using DoctorsHelp.Application.Models; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Infrastructure.Persistence.Interfaces; + +public interface ISpecializationRepository +{ + void Add(Specialization specialization); + + SpecializationModel GetSpecialization(int id); + + void UpdateSpecialization(Specialization specialization); + + bool Delete(Specialization specialization); +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IUserRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IUserRepository.cs new file mode 100644 index 0000000..8921927 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IUserRepository.cs @@ -0,0 +1,15 @@ +using DoctorsHelp.Application.Models; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Infrastructure.Persistence.Interfaces; + +public interface IUserRepository +{ + void Add(User user); + + UserModel GetUser(Guid id); + + void UpdateUser(User user); + + bool Delete(User user); +} \ No newline at end of file From 37e24ca7d7c5b3b57d3d3d9e85e0051408ba8558 Mon Sep 17 00:00:00 2001 From: AlexYrkn <61319606+AlexYrkn@users.noreply.github.com> Date: Sat, 16 Mar 2024 17:10:21 +0300 Subject: [PATCH 05/12] models changes --- .../DoctorsHelp.Application.Models/Appointment.cs | 8 ++++---- .../DoctorsHelp.Application.Models/Employee.cs | 4 ++-- src/Application/DoctorsHelp.Application.Models/Review.cs | 8 ++++---- .../DoctorsHelp.Application.Models/Schedule.cs | 8 ++++---- .../DoctorsHelp.Application.Models/Specialization.cs | 2 +- src/Application/DoctorsHelp.Application.Models/User.cs | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Application/DoctorsHelp.Application.Models/Appointment.cs b/src/Application/DoctorsHelp.Application.Models/Appointment.cs index 3f2a153..b8acd80 100644 --- a/src/Application/DoctorsHelp.Application.Models/Appointment.cs +++ b/src/Application/DoctorsHelp.Application.Models/Appointment.cs @@ -2,15 +2,15 @@ public class Appointment { - public int Id { get; set; } + public int? Id { get; set; } public User? Patient { get; set; } public Schedule? Schedule { get; set; } - public DateTime CreatedAt { get; set; } + public DateTime? CreatedAt { get; set; } - public DateTime UpdatedAt { get; set; } + public DateTime? UpdatedAt { get; set; } - public int Status { get; set; } + public int? Status { get; set; } } \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Models/Employee.cs b/src/Application/DoctorsHelp.Application.Models/Employee.cs index 66440a8..a8219db 100644 --- a/src/Application/DoctorsHelp.Application.Models/Employee.cs +++ b/src/Application/DoctorsHelp.Application.Models/Employee.cs @@ -2,11 +2,11 @@ public class Employee { - public int Id { get; set; } + public int? Id { get; set; } public User? User { get; set; } - public int Specialization { get; set; } + public Specialization? Specialization { get; set; } public string? Graduate { get; set; } diff --git a/src/Application/DoctorsHelp.Application.Models/Review.cs b/src/Application/DoctorsHelp.Application.Models/Review.cs index a3e6769..57987e6 100644 --- a/src/Application/DoctorsHelp.Application.Models/Review.cs +++ b/src/Application/DoctorsHelp.Application.Models/Review.cs @@ -2,15 +2,15 @@ public class Review { - public int Id { get; set; } + public int? Id { get; set; } public Appointment? Appointment { get; set; } - public int Grade { get; set; } + public int? Grade { get; set; } public string? Comment { get; set; } - public DateTime CreatedAt { get; set; } + public DateTime? CreatedAt { get; set; } - public DateTime UpdatedAt { get; set; } + public DateTime? UpdatedAt { get; set; } } \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Models/Schedule.cs b/src/Application/DoctorsHelp.Application.Models/Schedule.cs index 2d04da3..6fa2aaa 100644 --- a/src/Application/DoctorsHelp.Application.Models/Schedule.cs +++ b/src/Application/DoctorsHelp.Application.Models/Schedule.cs @@ -2,13 +2,13 @@ public class Schedule { - public int Id { get; set; } + public int? Id { get; set; } public Employee? Employee { get; set; } - public DateTime DateStart { get; set; } + public DateTime? DateStart { get; set; } - public DateTime DateEnd { get; set; } + public DateTime? DateEnd { get; set; } - public int Status { get; set; } + public int? Status { get; set; } } \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Models/Specialization.cs b/src/Application/DoctorsHelp.Application.Models/Specialization.cs index 335b580..2c73aef 100644 --- a/src/Application/DoctorsHelp.Application.Models/Specialization.cs +++ b/src/Application/DoctorsHelp.Application.Models/Specialization.cs @@ -2,7 +2,7 @@ public class Specialization { - public int Id { get; set; } + public int? Id { get; set; } public string? Name { get; set; } diff --git a/src/Application/DoctorsHelp.Application.Models/User.cs b/src/Application/DoctorsHelp.Application.Models/User.cs index 2e5a3b2..127ce12 100644 --- a/src/Application/DoctorsHelp.Application.Models/User.cs +++ b/src/Application/DoctorsHelp.Application.Models/User.cs @@ -2,7 +2,7 @@ public class User { - public Guid Id { get; set; } + public Guid? Id { get; set; } public string? Name { get; set; } @@ -14,7 +14,7 @@ public class User public string? HashedPassword { get; set; } - public DateOnly Birthdate { get; set; } + public DateOnly? Birthdate { get; set; } public string? Role { get; set; } } \ No newline at end of file From 5452bd2ec9f581a100b056f18edfe518579599fb Mon Sep 17 00:00:00 2001 From: owarpero Date: Sat, 16 Mar 2024 17:13:39 +0300 Subject: [PATCH 06/12] feat: services --- .github/workflows/main.yml | 33 --------- .../DoctorsHelp.Application.Contracts.csproj | 1 + .../IAppointmentService.cs | 4 +- .../IEmployeeService.cs | 4 +- .../IReviewService.cs | 2 +- .../IScheduleService.cs | 6 +- .../ISpecializationService.cs | 2 +- .../IUserService.cs | 10 ++- .../Services/AppointmentService.cs | 70 ++++++++++++++++++ .../Services/EmployeeService.cs | 72 +++++++++++++++++++ .../Services/ReviewService.cs | 68 ++++++++++++++++++ .../Services/ScheduleService.cs | 67 +++++++++++++++++ .../Services/SpecializationService.cs | 60 ++++++++++++++++ .../Services/UserService.cs | 70 ++++++++++++++++++ .../Extensions/ServiceCollectionExtensions.cs | 10 ++- .../Converters/AppointmentConverter.cs | 20 ++++++ .../Converters/EmployeeConverter.cs | 19 +++++ .../Converters/ReviewConverter.cs | 20 ++++++ .../Converters/ScheduleConverter.cs | 19 +++++ .../Converters/SpecializationConverter.cs | 17 +++++ .../Converters/UserConverter.cs | 22 ++++++ 21 files changed, 546 insertions(+), 50 deletions(-) delete mode 100644 .github/workflows/main.yml create mode 100644 src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs create mode 100644 src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs create mode 100644 src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs create mode 100644 src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs create mode 100644 src/Application/DoctorsHelp.Application.Contracts/Services/SpecializationService.cs create mode 100644 src/Application/DoctorsHelp.Application.Contracts/Services/UserService.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/AppointmentConverter.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/EmployeeConverter.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/ReviewConverter.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/ScheduleConverter.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/SpecializationConverter.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/UserConverter.cs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml deleted file mode 100644 index 2e503d0..0000000 --- a/.github/workflows/main.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: Swagger to HTML - -on: - push: - branches: - - swaggerhub - -jobs: - generate-and-commit-html: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: '14' - - - name: Install Redoc CLI - run: npm install -g redoc-cli - - - name: Generate HTML from Swagger YAML - run: redoc-cli bundle swagger.yaml -o node-output/swagger.html - - - name: Commit and Push HTML - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add node-output/swagger.html - git commit -m "Generate HTML from Swagger YAML" || echo "No changes to commit" - git push origin HEAD:swaggerhub diff --git a/src/Application/DoctorsHelp.Application.Contracts/DoctorsHelp.Application.Contracts.csproj b/src/Application/DoctorsHelp.Application.Contracts/DoctorsHelp.Application.Contracts.csproj index 9ea7cb0..0efbdd7 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/DoctorsHelp.Application.Contracts.csproj +++ b/src/Application/DoctorsHelp.Application.Contracts/DoctorsHelp.Application.Contracts.csproj @@ -1,6 +1,7 @@ + diff --git a/src/Application/DoctorsHelp.Application.Contracts/IAppointmentService.cs b/src/Application/DoctorsHelp.Application.Contracts/IAppointmentService.cs index 6aacce2..a1fbfab 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IAppointmentService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IAppointmentService.cs @@ -6,9 +6,9 @@ public interface IAppointmentService { Appointment Create(User patient, Schedule schedule); - Appointment GetAppointment(int patientId); + Appointment? GetAppointment(int patientId); Appointment Update(int id, Dictionary data); bool Delete(int id); -} \ No newline at end of file +} diff --git a/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs b/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs index 1ea302c..2cd3089 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs @@ -6,9 +6,7 @@ public interface IEmployeeService { Employee Create(User user, Specialization specialization, string graduate, string experience); - Employee GetEmployee(); - - Employee GetById(int id); + Employee? GetEmployee(int employeeId); Employee Update(int id, Dictionary data); diff --git a/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs b/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs index a36b487..42fa23a 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs @@ -6,7 +6,7 @@ public interface IReviewService { Review Create(Appointment appointment, int grade, string comment); - Review GetReview(int appointmentId); + Review? GetReview(int reviewId); Review Update(int id, Dictionary data); diff --git a/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs b/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs index 9bc72e0..6dfd9c3 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs @@ -4,11 +4,11 @@ namespace DoctorsHelp.Application.Contracts; public interface IScheduleService { - Review Create(Employee employee, DateTime dateStart, DateTime dateEnd); + Schedule Create(Employee employee, DateTime dateStart, DateTime dateEnd); - Review GeSchedule(int employeeId); + Schedule? GetSchedule(int scheduleId); - Review Update(int id, Dictionary data); + Schedule Update(int id, Dictionary data); bool Delete(int id); } \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/ISpecializationService.cs b/src/Application/DoctorsHelp.Application.Contracts/ISpecializationService.cs index 9591000..dfc2a3d 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/ISpecializationService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/ISpecializationService.cs @@ -6,7 +6,7 @@ public interface ISpecializationService { Specialization Create(string name, string description); - Specialization GetSpecialization(int id); + Specialization? GetSpecialization(int id); Specialization Update(int id, Dictionary data); diff --git a/src/Application/DoctorsHelp.Application.Contracts/IUserService.cs b/src/Application/DoctorsHelp.Application.Contracts/IUserService.cs index 999f393..82cb0be 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IUserService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IUserService.cs @@ -4,13 +4,11 @@ namespace DoctorsHelp.Application.Contracts; public interface IUserService { - User Register(string name, string surname, string phone, string email, string password, DateTime birthdate); + User Register(string name, string surname, string phone, string email, string password, DateOnly birthdate); - User Login(string phone, string password); + User? GetUser(Guid id); - User GetUser(int id); + User UpdateUser(Guid id, Dictionary data); - User Update(int id, Dictionary data); - - bool Delete(int id); + bool DeleteUser(Guid id); } \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs new file mode 100644 index 0000000..1d58824 --- /dev/null +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs @@ -0,0 +1,70 @@ +using DoctorsHelp.Application.Models; +using DoctorsHelp.Infrastructure.Persistence.Converters; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; +using DoctorsHelp.Infrastructure.Persistence.Repositories; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Application.Contracts.Services; + +public class AppointmentService : IAppointmentService +{ + private readonly IAppointmentRepository _appointmentRepository; + + public AppointmentService(AppointmentRepository appointmentRepository) + { + _appointmentRepository = appointmentRepository; + } + + public Appointment Create(User patient, Schedule schedule) + { + var appointment = new Appointment + { + // Assuming Appointment has a constructor or properties for this + Patient = patient, + Schedule = schedule, + }; + _appointmentRepository.Add(appointment); + return appointment; + } + + public Appointment? GetAppointment(int patientId) + { + var appointmentModel = _appointmentRepository.GetAppointment(patientId); + + return AppointmentConverter.AppointmentModelToAppointment(appointmentModel); + } + + public Appointment Update(int id, Dictionary data) + { + AppointmentModel appointmentToUpdate = _appointmentRepository.GetAppointment(id); + + foreach (var entry in data) + { + switch (entry.Key) + { + case "PatientId": + Guid patientId; + if (Guid.TryParse(entry.Value, out patientId)) + appointmentToUpdate.PatientId = patientId; + break; + case "ScheduleId": + int scheduleId; + if (int.TryParse(entry.Value, out scheduleId)) + appointmentToUpdate.ScheduleId = scheduleId; + break; + case "Status": + int status; + if (int.TryParse(entry.Value, out status)) + appointmentToUpdate.Status = status; + break; + } + } + + return AppointmentConverter.AppointmentModelToAppointment(appointmentToUpdate); + } + + public bool Delete(int id) + { + return _appointmentRepository.Delete(new Appointment { Id = id, }); + } +} diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs new file mode 100644 index 0000000..14936db --- /dev/null +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs @@ -0,0 +1,72 @@ +using DoctorsHelp.Application.Models; +using DoctorsHelp.Infrastructure.Persistence.Converters; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; +using DoctorsHelp.Infrastructure.Persistence.Repositories; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Application.Contracts.Services; + +public class EmployeeService : IEmployeeService +{ + private readonly IEmployeeRepository _employeeRepository; + + public EmployeeService(EmployeeRepository appointmentRepository) + { + _employeeRepository = appointmentRepository; + } + + public Employee Create(User user, Specialization specialization, string graduate, string experience) + { + var employee = new Employee + { + User = user, + Specialization = specialization, + Graduate = graduate, + Experience = experience, + }; + _employeeRepository.Add(employee); + return employee; + } + + public Employee? GetEmployee(int employeeId) + { + var employeeModel = _employeeRepository.GetEmployee(employeeId); + + return EmployeeConverter.EmployeeModelToEmployee(employeeModel); + } + + public Employee Update(int id, Dictionary data) + { + EmployeeModel employeeToUpdate = _employeeRepository.GetEmployee(id); + + foreach (var entry in data) + { + switch (entry.Key) + { + case "UserId": + Guid userId; + if (Guid.TryParse(entry.Value, out userId)) + employeeToUpdate.UserId = userId; + break; + case "SpecializationId": + int specializationId; + if (int.TryParse(entry.Value, out specializationId)) + employeeToUpdate.SpecializationId = specializationId; + break; + case "Graduate": + employeeToUpdate.Graduate = entry.Value; + break; + case "Experience": + employeeToUpdate.Experience = entry.Value; + break; + } + } + + return EmployeeConverter.EmployeeModelToEmployee(employeeToUpdate); + } + + public bool Delete(int id) + { + return _employeeRepository.Delete(new Employee { Id = id, }); + } +} \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs new file mode 100644 index 0000000..d01421e --- /dev/null +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs @@ -0,0 +1,68 @@ +using DoctorsHelp.Application.Models; +using DoctorsHelp.Infrastructure.Persistence.Converters; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; +using DoctorsHelp.Infrastructure.Persistence.Repositories; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Application.Contracts.Services; + +public class ReviewService : IReviewService +{ + private readonly IReviewRepository _reviewRepository; + + public ReviewService(ReviewRepository reviewRepository) + { + _reviewRepository = reviewRepository; + } + + public Review Create(Appointment appointment, int grade, string comment) + { + var review = new Review + { + Appointment = appointment, + Grade = grade, + Comment = comment, + }; + _reviewRepository.Add(review); + return review; + } + + public Review? GetReview(int reviewId) + { + var reviewModel = _reviewRepository.GetReview(reviewId); + + return ReviewConverter.ReviewModelToReview(reviewModel); + } + + public Review Update(int id, Dictionary data) + { + ReviewModel reviewToUpdate = _reviewRepository.GetReview(id); + + foreach (var entry in data) + { + switch (entry.Key) + { + case "AppointmentId": + int appointmentId; + if (int.TryParse(entry.Value, out appointmentId)) + reviewToUpdate.AppointmentId = appointmentId; + break; + case "Rating": + int grade; + if (int.TryParse(entry.Value, out grade)) + reviewToUpdate.Grade = grade; + break; + case "Comment": + reviewToUpdate.Comment = entry.Value; + break; + } + } + + return ReviewConverter.ReviewModelToReview(reviewToUpdate); + } + + public bool Delete(int id) + { + return _reviewRepository.Delete(new Review { Id = id }); + } +} \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs new file mode 100644 index 0000000..4bdcaae --- /dev/null +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs @@ -0,0 +1,67 @@ +using DoctorsHelp.Application.Models; +using DoctorsHelp.Infrastructure.Persistence.Converters; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; +using DoctorsHelp.Infrastructure.Persistence.Repositories; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Application.Contracts.Services; + +public class ScheduleService : IScheduleService +{ + private readonly IScheduleRepository _scheduleRepository; + + public ScheduleService(ScheduleRepository scheduleRepository) + { + _scheduleRepository = scheduleRepository; + } + + public Schedule Create(Employee employee, DateTime dateStart, DateTime dateEnd) + { + var schedule = new Schedule + { + // Assuming Appointment has a constructor or properties for this + Employee = employee, + DateStart = dateStart, + DateEnd = dateEnd, + }; + _scheduleRepository.Add(schedule); + return schedule; + } + + public Schedule? GetSchedule(int scheduleId) + { + var scheduleModel = _scheduleRepository.GetSchedule(scheduleId); + + return ScheduleConverter.ScheduleModelToSchedule(scheduleModel); + } + + public Schedule Update(int id, Dictionary data) + { + ScheduleModel scheduleToUpdate = _scheduleRepository.GetSchedule(id); + + foreach (var entry in data) + { + switch (entry.Key) + { + case "EmployeeId": + int employeeId; + if (int.TryParse(entry.Value, out employeeId)) + scheduleToUpdate.EmployeeId = employeeId; + break; + case "DateStart": + scheduleToUpdate.DateStart = new DateTime(Convert.ToInt32(entry.Value)); + break; + case "DateEnd": + scheduleToUpdate.DateEnd = new DateTime(Convert.ToInt32(entry.Value)); + break; + } + } + + return ScheduleConverter.ScheduleModelToSchedule(scheduleToUpdate); + } + + public bool Delete(int id) + { + return _scheduleRepository.Delete(new Schedule { Id = id, }); + } +} \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/SpecializationService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/SpecializationService.cs new file mode 100644 index 0000000..60b8889 --- /dev/null +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/SpecializationService.cs @@ -0,0 +1,60 @@ +using DoctorsHelp.Application.Models; +using DoctorsHelp.Infrastructure.Persistence.Converters; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; +using DoctorsHelp.Infrastructure.Persistence.Repositories; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Application.Contracts.Services; + +public class SpecializationService : ISpecializationService +{ + private readonly ISpecializationRepository _specializationRepository; + + public SpecializationService(SpecializationRepository specializationRepository) + { + _specializationRepository = specializationRepository; + } + + public Specialization Create(string name, string description) + { + var specialization = new Specialization + { + Name = name, + Description = description, + }; + _specializationRepository.Add(specialization); + return specialization; + } + + public Specialization? GetSpecialization(int id) + { + var specializationModel = _specializationRepository.GetSpecialization(id); + + return SpecializationConverter.SpecializationModelToSpecialization(specializationModel); + } + + public Specialization Update(int id, Dictionary data) + { + SpecializationModel specializationToUpdate = _specializationRepository.GetSpecialization(id); + + foreach (var entry in data) + { + switch (entry.Key) + { + case "Name": + specializationToUpdate.Name = entry.Value; + break; + case "Description": + specializationToUpdate.Description = entry.Value; + break; + } + } + + return SpecializationConverter.SpecializationModelToSpecialization(specializationToUpdate); + } + + public bool Delete(int id) + { + return _specializationRepository.Delete(new Specialization { Id = id }); + } +} \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/UserService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/UserService.cs new file mode 100644 index 0000000..7bc6b26 --- /dev/null +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/UserService.cs @@ -0,0 +1,70 @@ +using DoctorsHelp.Application.Models; +using DoctorsHelp.Infrastructure.Persistence.Converters; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; +using DoctorsHelp.Infrastructure.Persistence.Repositories; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Application.Contracts.Services; + +public class UserService : IUserService +{ + private readonly IUserRepository _userRepository; + + public UserService(UserRepository userRepository) + { + _userRepository = userRepository; + } + + public User Register(string name, string surname, string phone, string email, string password, DateOnly birthdate) + { + var user = new User + { + Name = name, + Surname = surname, + HashedPassword = password, + Phone = phone, + Email = email, + Birthdate = birthdate, + }; + _userRepository.Add(user); + return user; + } + + public User? GetUser(Guid id) + { + var userModel = _userRepository.GetUser(id); + + return UserConverter.UserModelToUser(userModel); + } + + public User UpdateUser(Guid id, Dictionary data) + { + UserModel userToUpdate = _userRepository.GetUser(id); + + foreach (var entry in data) + { + switch (entry.Key) + { + case "Name": + userToUpdate.Name = entry.Value; + break; + case "Surname": + userToUpdate.Surname = entry.Value; + break; + case "Phone": + userToUpdate.Phone = entry.Value; + break; + case "Email": + userToUpdate.Email = entry.Value; + break; + } + } + + return UserConverter.UserModelToUser(userToUpdate); + } + + public bool DeleteUser(Guid id) + { + return _userRepository.Delete(new User { Id = id }); + } +} \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application/Extensions/ServiceCollectionExtensions.cs b/src/Application/DoctorsHelp.Application/Extensions/ServiceCollectionExtensions.cs index f0449dc..9940f3a 100644 --- a/src/Application/DoctorsHelp.Application/Extensions/ServiceCollectionExtensions.cs +++ b/src/Application/DoctorsHelp.Application/Extensions/ServiceCollectionExtensions.cs @@ -1,3 +1,6 @@ +using DoctorsHelp.Application.Contracts; +using DoctorsHelp.Application.Contracts.Services; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; using Microsoft.Extensions.DependencyInjection; namespace DoctorsHelp.Application.Extensions; @@ -6,7 +9,12 @@ public static class ServiceCollectionExtensions { public static IServiceCollection AddApplication(this IServiceCollection collection) { - // TODO: add services + collection.AddScoped(); + collection.AddScoped(); + collection.AddScoped(); + collection.AddScoped(); + collection.AddScoped(); + collection.AddScoped(); return collection; } } \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/AppointmentConverter.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/AppointmentConverter.cs new file mode 100644 index 0000000..a7f2cc1 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/AppointmentConverter.cs @@ -0,0 +1,20 @@ +using DoctorsHelp.Application.Models; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Infrastructure.Persistence.Converters; + +public class AppointmentConverter +{ + public static Appointment AppointmentModelToAppointment(AppointmentModel? appointmentModel) + { + return new Appointment + { + Id = appointmentModel?.Id, + Patient = UserConverter.UserModelToUser(appointmentModel?.Patient), + Schedule = ScheduleConverter.ScheduleModelToSchedule(appointmentModel?.Schedule), + CreatedAt = appointmentModel?.CreatedAt, + UpdatedAt = appointmentModel?.UpdatedAt, + Status = appointmentModel?.Status, + }; + } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/EmployeeConverter.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/EmployeeConverter.cs new file mode 100644 index 0000000..6821fc3 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/EmployeeConverter.cs @@ -0,0 +1,19 @@ +using DoctorsHelp.Application.Models; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Infrastructure.Persistence.Converters; + +public class EmployeeConverter +{ + public static Employee EmployeeModelToEmployee(EmployeeModel? employeeModel) + { + return new Employee + { + Id = employeeModel?.Id, + User = UserConverter.UserModelToUser(employeeModel?.User), + Specialization = SpecializationConverter.SpecializationModelToSpecialization(employeeModel?.Specialization), + Graduate = employeeModel?.Graduate, + Experience = employeeModel?.Experience, + }; + } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/ReviewConverter.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/ReviewConverter.cs new file mode 100644 index 0000000..d8eb167 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/ReviewConverter.cs @@ -0,0 +1,20 @@ +using DoctorsHelp.Application.Models; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Infrastructure.Persistence.Converters; + +public class ReviewConverter +{ + public static Review ReviewModelToReview(ReviewModel? reviewModel) + { + return new Review + { + Id = reviewModel?.Id, + Appointment = AppointmentConverter.AppointmentModelToAppointment(reviewModel?.Appointment), + Grade = reviewModel?.Grade, + Comment = reviewModel?.Comment, + CreatedAt = reviewModel?.CreatedAt, + UpdatedAt = reviewModel?.UpdatedAt, + }; + } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/ScheduleConverter.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/ScheduleConverter.cs new file mode 100644 index 0000000..eda27ad --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/ScheduleConverter.cs @@ -0,0 +1,19 @@ +using DoctorsHelp.Application.Models; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Infrastructure.Persistence.Converters; + +public class ScheduleConverter +{ + public static Schedule ScheduleModelToSchedule(ScheduleModel? scheduleModel) + { + return new Schedule + { + Id = scheduleModel?.Id, + Employee = EmployeeConverter.EmployeeModelToEmployee(scheduleModel?.Employee), + DateStart = scheduleModel?.DateStart, + DateEnd = scheduleModel?.DateEnd, + Status = scheduleModel?.Status, + }; + } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/SpecializationConverter.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/SpecializationConverter.cs new file mode 100644 index 0000000..d17a6ba --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/SpecializationConverter.cs @@ -0,0 +1,17 @@ +using DoctorsHelp.Application.Models; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Infrastructure.Persistence.Converters; + +public class SpecializationConverter +{ + public static Specialization SpecializationModelToSpecialization(SpecializationModel? specializationModel) + { + return new Specialization + { + Id = specializationModel?.Id, + Name = specializationModel?.Name, + Description = specializationModel?.Description, + }; + } +} \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/UserConverter.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/UserConverter.cs new file mode 100644 index 0000000..98b4a57 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/UserConverter.cs @@ -0,0 +1,22 @@ +using DoctorsHelp.Application.Models; +using Infrastructure.Persistence.Models; + +namespace DoctorsHelp.Infrastructure.Persistence.Converters; + +public class UserConverter +{ + public static User UserModelToUser(UserModel? userModel) + { + return new User + { + Id = userModel?.Id, + Name = userModel?.Name, + Surname = userModel?.Surname, + Phone = userModel?.Phone, + Email = userModel?.Email, + HashedPassword = userModel?.HashedPassword, + Birthdate = userModel?.Birthdate, + Role = userModel?.Role, + }; + } +} \ No newline at end of file From 474bf164bd126eee6eb702e6906d43752cd2537f Mon Sep 17 00:00:00 2001 From: mishakorni Date: Sat, 16 Mar 2024 17:20:10 +0300 Subject: [PATCH 07/12] migrations --- .../20240316100013_Initial.Designer.cs | 239 ++++++++++++++++++ .../Migrations/20240316100013_Initial.cs | 184 ++++++++++++++ .../ApplicationDbContextModelSnapshot.cs | 236 +++++++++++++++++ 3 files changed, 659 insertions(+) create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.Designer.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.cs create mode 100644 src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.Designer.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.Designer.cs new file mode 100644 index 0000000..24a26aa --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.Designer.cs @@ -0,0 +1,239 @@ +// +using System; +using DoctorsHelp.Infrastructure.Persistence.Contexts; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DoctorsHelp.Infrastructure.Persistence.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20240316100013_Initial")] + partial class Initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Appointment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("PatientId") + .HasColumnType("uuid"); + + b.Property("ScheduleId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("PatientId"); + + b.HasIndex("ScheduleId"); + + b.ToTable("Appointments"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Experience") + .HasColumnType("text"); + + b.Property("Graduate") + .HasColumnType("text"); + + b.Property("Specialization") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Review", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AppointmentId") + .HasColumnType("integer"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Grade") + .HasColumnType("integer"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("AppointmentId"); + + b.ToTable("Reviews"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Schedule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DateEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("DateStart") + .HasColumnType("timestamp with time zone"); + + b.Property("EmployeeId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("Schedules"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Specialization", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Specializations"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthdate") + .HasColumnType("date"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("HashedPassword") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Phone") + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("text"); + + b.Property("Surname") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Appointment", b => + { + b.HasOne("DoctorsHelp.Application.Models.User", "Patient") + .WithMany() + .HasForeignKey("PatientId"); + + b.HasOne("DoctorsHelp.Application.Models.Schedule", "Schedule") + .WithMany() + .HasForeignKey("ScheduleId"); + + b.Navigation("Patient"); + + b.Navigation("Schedule"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Employee", b => + { + b.HasOne("DoctorsHelp.Application.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Review", b => + { + b.HasOne("DoctorsHelp.Application.Models.Appointment", "Appointment") + .WithMany() + .HasForeignKey("AppointmentId"); + + b.Navigation("Appointment"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Schedule", b => + { + b.HasOne("DoctorsHelp.Application.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId"); + + b.Navigation("Employee"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.cs new file mode 100644 index 0000000..2013210 --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.cs @@ -0,0 +1,184 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DoctorsHelp.Infrastructure.Persistence.Migrations; + +/// +public partial class Initial : Migration +{ + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Specializations", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Name = table.Column(type: "text", nullable: true), + Description = table.Column(type: "text", nullable: true), + }, + constraints: table => + { + table.PrimaryKey("PK_Specializations", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "text", nullable: true), + Surname = table.Column(type: "text", nullable: true), + Phone = table.Column(type: "text", nullable: true), + Email = table.Column(type: "text", nullable: true), + HashedPassword = table.Column(type: "text", nullable: true), + Birthdate = table.Column(type: "date", nullable: false), + Role = table.Column(type: "text", nullable: true), + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Employees", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "uuid", nullable: true), + Specialization = table.Column(type: "integer", nullable: false), + Graduate = table.Column(type: "text", nullable: true), + Experience = table.Column(type: "text", nullable: true), + }, + constraints: table => + { + table.PrimaryKey("PK_Employees", x => x.Id); + table.ForeignKey( + name: "FK_Employees_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Schedules", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + EmployeeId = table.Column(type: "integer", nullable: true), + DateStart = table.Column(type: "timestamp with time zone", nullable: false), + DateEnd = table.Column(type: "timestamp with time zone", nullable: false), + Status = table.Column(type: "integer", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("PK_Schedules", x => x.Id); + table.ForeignKey( + name: "FK_Schedules_Employees_EmployeeId", + column: x => x.EmployeeId, + principalTable: "Employees", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Appointments", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + PatientId = table.Column(type: "uuid", nullable: true), + ScheduleId = table.Column(type: "integer", nullable: true), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), + Status = table.Column(type: "integer", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("PK_Appointments", x => x.Id); + table.ForeignKey( + name: "FK_Appointments_Schedules_ScheduleId", + column: x => x.ScheduleId, + principalTable: "Schedules", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_Appointments_Users_PatientId", + column: x => x.PatientId, + principalTable: "Users", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Reviews", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + AppointmentId = table.Column(type: "integer", nullable: true), + Grade = table.Column(type: "integer", nullable: false), + Comment = table.Column(type: "text", nullable: true), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), + UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), + }, + constraints: table => + { + table.PrimaryKey("PK_Reviews", x => x.Id); + table.ForeignKey( + name: "FK_Reviews_Appointments_AppointmentId", + column: x => x.AppointmentId, + principalTable: "Appointments", + principalColumn: "Id"); + }); + + migrationBuilder.CreateIndex( + name: "IX_Appointments_PatientId", + table: "Appointments", + column: "PatientId"); + + migrationBuilder.CreateIndex( + name: "IX_Appointments_ScheduleId", + table: "Appointments", + column: "ScheduleId"); + + migrationBuilder.CreateIndex( + name: "IX_Employees_UserId", + table: "Employees", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Reviews_AppointmentId", + table: "Reviews", + column: "AppointmentId"); + + migrationBuilder.CreateIndex( + name: "IX_Schedules_EmployeeId", + table: "Schedules", + column: "EmployeeId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Reviews"); + + migrationBuilder.DropTable( + name: "Specializations"); + + migrationBuilder.DropTable( + name: "Appointments"); + + migrationBuilder.DropTable( + name: "Schedules"); + + migrationBuilder.DropTable( + name: "Employees"); + + migrationBuilder.DropTable( + name: "Users"); + } +} diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs new file mode 100644 index 0000000..93cea9d --- /dev/null +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs @@ -0,0 +1,236 @@ +// +using System; +using DoctorsHelp.Infrastructure.Persistence.Contexts; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace DoctorsHelp.Infrastructure.Persistence.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + partial class ApplicationDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.10") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Appointment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("PatientId") + .HasColumnType("uuid"); + + b.Property("ScheduleId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("PatientId"); + + b.HasIndex("ScheduleId"); + + b.ToTable("Appointments"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Employee", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Experience") + .HasColumnType("text"); + + b.Property("Graduate") + .HasColumnType("text"); + + b.Property("Specialization") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Review", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AppointmentId") + .HasColumnType("integer"); + + b.Property("Comment") + .HasColumnType("text"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Grade") + .HasColumnType("integer"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("AppointmentId"); + + b.ToTable("Reviews"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Schedule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DateEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("DateStart") + .HasColumnType("timestamp with time zone"); + + b.Property("EmployeeId") + .HasColumnType("integer"); + + b.Property("Status") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("Schedules"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Specialization", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Description") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Specializations"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Birthdate") + .HasColumnType("date"); + + b.Property("Email") + .HasColumnType("text"); + + b.Property("HashedPassword") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Phone") + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("text"); + + b.Property("Surname") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Appointment", b => + { + b.HasOne("DoctorsHelp.Application.Models.User", "Patient") + .WithMany() + .HasForeignKey("PatientId"); + + b.HasOne("DoctorsHelp.Application.Models.Schedule", "Schedule") + .WithMany() + .HasForeignKey("ScheduleId"); + + b.Navigation("Patient"); + + b.Navigation("Schedule"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Employee", b => + { + b.HasOne("DoctorsHelp.Application.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Review", b => + { + b.HasOne("DoctorsHelp.Application.Models.Appointment", "Appointment") + .WithMany() + .HasForeignKey("AppointmentId"); + + b.Navigation("Appointment"); + }); + + modelBuilder.Entity("DoctorsHelp.Application.Models.Schedule", b => + { + b.HasOne("DoctorsHelp.Application.Models.Employee", "Employee") + .WithMany() + .HasForeignKey("EmployeeId"); + + b.Navigation("Employee"); + }); +#pragma warning restore 612, 618 + } + } +} From d46fc5cfd2102327ad4c2979955b4e1cbee5027e Mon Sep 17 00:00:00 2001 From: Aleksei Tiulenev Date: Sat, 16 Mar 2024 18:15:56 +0300 Subject: [PATCH 08/12] feat: controllers --- .../IReviewService.cs | 2 +- .../IScheduleService.cs | 2 +- .../IUserService.cs | 2 +- .../Services/ReviewService.cs | 2 +- .../Services/ScheduleService.cs | 2 +- .../Services/UserService.cs | 2 +- .../Extensions/ServiceCollectionExtensions.cs | 3 +- .../Controllers/AppointmentController.cs | 75 +++++++++++++++++ .../Controllers/EmployeeController.cs | 76 +++++++++++++++++ .../Controllers/ReviewController.cs | 76 +++++++++++++++++ .../Controllers/ScheduleController.cs | 81 +++++++++++++++++++ .../Controllers/SpecializationController.cs | 76 +++++++++++++++++ .../Controllers/UserController.cs | 80 ++++++++++++++++++ .../DoctorsHelp.Presentation.Http.csproj | 2 +- 14 files changed, 472 insertions(+), 9 deletions(-) create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Controllers/AppointmentController.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Controllers/EmployeeController.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ReviewController.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ScheduleController.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Controllers/SpecializationController.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs diff --git a/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs b/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs index 42fa23a..d150ccd 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs @@ -4,7 +4,7 @@ namespace DoctorsHelp.Application.Contracts; public interface IReviewService { - Review Create(Appointment appointment, int grade, string comment); + Review Create(Appointment appointment, int? grade, string comment); Review? GetReview(int reviewId); diff --git a/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs b/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs index 6dfd9c3..b53d083 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs @@ -4,7 +4,7 @@ namespace DoctorsHelp.Application.Contracts; public interface IScheduleService { - Schedule Create(Employee employee, DateTime dateStart, DateTime dateEnd); + Schedule Create(Employee employee, DateTime? dateStart, DateTime? dateEnd); Schedule? GetSchedule(int scheduleId); diff --git a/src/Application/DoctorsHelp.Application.Contracts/IUserService.cs b/src/Application/DoctorsHelp.Application.Contracts/IUserService.cs index 82cb0be..8bee8be 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IUserService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IUserService.cs @@ -4,7 +4,7 @@ namespace DoctorsHelp.Application.Contracts; public interface IUserService { - User Register(string name, string surname, string phone, string email, string password, DateOnly birthdate); + User Register(string name, string surname, string phone, string email, string password, DateOnly? birthdate); User? GetUser(Guid id); diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs index d01421e..0bf4028 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs @@ -15,7 +15,7 @@ public ReviewService(ReviewRepository reviewRepository) _reviewRepository = reviewRepository; } - public Review Create(Appointment appointment, int grade, string comment) + public Review Create(Appointment appointment, int? grade, string comment) { var review = new Review { diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs index 4bdcaae..1e2032f 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs @@ -15,7 +15,7 @@ public ScheduleService(ScheduleRepository scheduleRepository) _scheduleRepository = scheduleRepository; } - public Schedule Create(Employee employee, DateTime dateStart, DateTime dateEnd) + public Schedule Create(Employee employee, DateTime? dateStart, DateTime? dateEnd) { var schedule = new Schedule { diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/UserService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/UserService.cs index 7bc6b26..cd0fe69 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/UserService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/UserService.cs @@ -15,7 +15,7 @@ public UserService(UserRepository userRepository) _userRepository = userRepository; } - public User Register(string name, string surname, string phone, string email, string password, DateOnly birthdate) + public User Register(string name, string surname, string phone, string email, string password, DateOnly? birthdate) { var user = new User { diff --git a/src/Application/DoctorsHelp.Application/Extensions/ServiceCollectionExtensions.cs b/src/Application/DoctorsHelp.Application/Extensions/ServiceCollectionExtensions.cs index 9940f3a..7cefcf8 100644 --- a/src/Application/DoctorsHelp.Application/Extensions/ServiceCollectionExtensions.cs +++ b/src/Application/DoctorsHelp.Application/Extensions/ServiceCollectionExtensions.cs @@ -1,6 +1,5 @@ using DoctorsHelp.Application.Contracts; using DoctorsHelp.Application.Contracts.Services; -using DoctorsHelp.Infrastructure.Persistence.Interfaces; using Microsoft.Extensions.DependencyInjection; namespace DoctorsHelp.Application.Extensions; @@ -13,7 +12,7 @@ public static IServiceCollection AddApplication(this IServiceCollection collecti collection.AddScoped(); collection.AddScoped(); collection.AddScoped(); - collection.AddScoped(); + collection.AddScoped(); collection.AddScoped(); return collection; } diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/AppointmentController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/AppointmentController.cs new file mode 100644 index 0000000..364db4c --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/AppointmentController.cs @@ -0,0 +1,75 @@ +using DoctorsHelp.Application.Contracts; +using DoctorsHelp.Application.Models; +using Microsoft.AspNetCore.Mvc; + +namespace DoctorsHelp.Presentation.Http.Controllers; +[ApiController] +[Route("[controller]")] +public class AppointmentController : ControllerBase +{ + private readonly IAppointmentService _appointmentService; + + public AppointmentController(IAppointmentService appointmentService) + { + _appointmentService = appointmentService; + } + + [HttpGet("{id}")] + public ActionResult Get(int id) + { + var appointment = _appointmentService.GetAppointment(id); + if (appointment == null) + { + return NotFound(); + } + + return Ok(appointment); + } + + [HttpPost] + public ActionResult Post([FromBody] Appointment appointment) + { + if (appointment.Patient == null || appointment.Schedule == null) + { + return BadRequest("Patient and Schedule are required."); + } + + try + { + var createdAppointment = _appointmentService.Create(appointment.Patient, appointment.Schedule); + return CreatedAtAction(nameof(Get), new { id = createdAppointment.Id }, createdAppointment); + } + catch (Exception ex) + { + return StatusCode(500, "An error occurred while creating the appointment." + ex); + } + } + + [HttpPut("{id}")] + public ActionResult Update(int id, [FromBody] Dictionary data) + { + try + { + var updatedAppointment = _appointmentService.Update(id, data); + return Ok(updatedAppointment); + } + catch (KeyNotFoundException) + { + return NotFound(); + } + } + + [HttpDelete("{id}")] + public IActionResult Delete(int id) + { + var result = _appointmentService.Delete(id); + if (result) + { + return NoContent(); + } + else + { + return NotFound(); + } + } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/EmployeeController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/EmployeeController.cs new file mode 100644 index 0000000..16c01ff --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/EmployeeController.cs @@ -0,0 +1,76 @@ +using DoctorsHelp.Application.Contracts; +using DoctorsHelp.Application.Models; +using Microsoft.AspNetCore.Mvc; + +namespace DoctorsHelp.Presentation.Http.Controllers; + +[ApiController] +[Route("[controller]")] +public class EmployeeController : ControllerBase +{ + private readonly IEmployeeService _employeeService; + + public EmployeeController(IEmployeeService employeeService) + { + _employeeService = employeeService; + } + + [HttpGet("{id}")] + public ActionResult Get(int id) + { + var employee = _employeeService.GetEmployee(id); + if (employee == null) + { + return NotFound(); + } + + return Ok(employee); + } + + [HttpPost] + public ActionResult Post([FromBody] Employee employee) + { + if (employee.User == null || employee.Specialization == null || string.IsNullOrWhiteSpace(employee.Graduate) || string.IsNullOrWhiteSpace(employee.Experience)) + { + return BadRequest("User, Specialization, Graduate, and Experience are required."); + } + + try + { + var createdEmployee = _employeeService.Create(employee.User, employee.Specialization, employee.Graduate, employee.Experience); + return CreatedAtAction(nameof(Get), new { id = createdEmployee.Id }, createdEmployee); + } + catch (Exception ex) + { + return StatusCode(500, "An error occurred while creating the employee. " + ex.Message); + } + } + + [HttpPut("{id}")] + public ActionResult Update(int id, [FromBody] Dictionary data) + { + try + { + var updatedEmployee = _employeeService.Update(id, data); + return Ok(updatedEmployee); + } + catch (KeyNotFoundException) + { + return NotFound(); + } + } + + [HttpDelete("{id}")] + public IActionResult Delete(int id) + { + var result = _employeeService.Delete(id); + if (result) + { + return NoContent(); + } + else + { + return NotFound(); + } + } +} diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ReviewController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ReviewController.cs new file mode 100644 index 0000000..13d2fba --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ReviewController.cs @@ -0,0 +1,76 @@ +using DoctorsHelp.Application.Contracts; +using DoctorsHelp.Application.Models; +using Microsoft.AspNetCore.Mvc; + +namespace DoctorsHelp.Presentation.Http.Controllers; + +[ApiController] +[Route("[controller]")] +public class ReviewController : ControllerBase +{ + private readonly IReviewService _reviewService; + + public ReviewController(IReviewService reviewService) + { + _reviewService = reviewService; + } + + [HttpGet("{id}")] + public ActionResult Get(int id) + { + var review = _reviewService.GetReview(id); + if (review == null) + { + return NotFound(); + } + + return Ok(review); + } + + [HttpPost] + public ActionResult Post([FromBody] Review review) + { + if (review.Appointment == null || review.Grade < 1 || string.IsNullOrWhiteSpace(review.Comment) || review.Grade == null) + { + return BadRequest("Appointment, Grade, and Comment are required."); + } + + try + { + var createdReview = _reviewService.Create(review.Appointment, review.Grade, review.Comment); + return CreatedAtAction(nameof(Get), new { id = createdReview.Id }, createdReview); + } + catch (Exception ex) + { + return StatusCode(500, "An error occurred while creating the review. " + ex.Message); + } + } + + [HttpPut("{id}")] + public ActionResult Update(int id, [FromBody] Dictionary data) + { + try + { + var updatedReview = _reviewService.Update(id, data); + return Ok(updatedReview); + } + catch (KeyNotFoundException) + { + return NotFound(); + } + } + + [HttpDelete("{id}")] + public IActionResult Delete(int id) + { + var result = _reviewService.Delete(id); + if (result) + { + return NoContent(); + } + else + { + return NotFound(); + } + } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ScheduleController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ScheduleController.cs new file mode 100644 index 0000000..1f2ff89 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ScheduleController.cs @@ -0,0 +1,81 @@ +using DoctorsHelp.Application.Contracts; +using DoctorsHelp.Application.Models; +using Microsoft.AspNetCore.Mvc; + +namespace DoctorsHelp.Presentation.Http.Controllers; + +[ApiController] +[Route("[controller]")] +public class ScheduleController : ControllerBase +{ + private readonly IScheduleService _scheduleService; + + public ScheduleController(IScheduleService scheduleService) + { + _scheduleService = scheduleService; + } + + [HttpGet("{id}")] + public ActionResult Get(int id) + { + var schedule = _scheduleService.GetSchedule(id); + if (schedule == null) + { + return NotFound(); + } + + return Ok(schedule); + } + + [HttpPost] + public ActionResult Post([FromBody] Schedule schedule) + { + if (schedule.Employee == null || schedule.DateStart == default || schedule.DateEnd == default) + { + return BadRequest("Employee, DateStart, and DateEnd are required."); + } + + if (schedule.DateStart >= schedule.DateEnd) + { + return BadRequest("DateStart must be before DateEnd."); + } + + try + { + var createdSchedule = _scheduleService.Create(schedule.Employee, schedule.DateStart, schedule.DateEnd); + return CreatedAtAction(nameof(Get), new { id = createdSchedule.Id }, createdSchedule); + } + catch (Exception ex) + { + return StatusCode(500, "An error occurred while creating the schedule. " + ex.Message); + } + } + + [HttpPut("{id}")] + public ActionResult Update(int id, [FromBody] Dictionary data) + { + try + { + var updatedSchedule = _scheduleService.Update(id, data); + return Ok(updatedSchedule); + } + catch (KeyNotFoundException) + { + return NotFound(); + } + } + + [HttpDelete("{id}")] + public IActionResult Delete(int id) + { + var result = _scheduleService.Delete(id); + if (result) + { + return NoContent(); + } + else + { + return NotFound(); + } + } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/SpecializationController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/SpecializationController.cs new file mode 100644 index 0000000..d8aae17 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/SpecializationController.cs @@ -0,0 +1,76 @@ +using DoctorsHelp.Application.Contracts; +using DoctorsHelp.Application.Models; +using Microsoft.AspNetCore.Mvc; + +namespace DoctorsHelp.Presentation.Http.Controllers; + +[ApiController] +[Route("[controller]")] +public class SpecializationController : ControllerBase +{ + private readonly ISpecializationService _specializationService; + + public SpecializationController(ISpecializationService specializationService) + { + _specializationService = specializationService; + } + + [HttpGet("{id}")] + public ActionResult Get(int id) + { + var specialization = _specializationService.GetSpecialization(id); + if (specialization == null) + { + return NotFound(); + } + + return Ok(specialization); + } + + [HttpPost] + public ActionResult Post([FromBody] Specialization specialization) + { + if (specialization.Name == null || specialization.Description == null) + { + return BadRequest("Name and Description are required."); + } + + try + { + var createdSpecialization = _specializationService.Create(specialization.Name, specialization.Description); + return CreatedAtAction(nameof(Get), new { id = createdSpecialization.Id }, createdSpecialization); + } + catch (Exception ex) + { + return StatusCode(500, "An error occurred while creating the specialization." + ex); + } + } + + [HttpPut("{id}")] + public ActionResult Update(int id, [FromBody] Dictionary data) + { + try + { + var updatedSpecialization = _specializationService.Update(id, data); + return Ok(updatedSpecialization); + } + catch (KeyNotFoundException) + { + return NotFound(); + } + } + + [HttpDelete("{id}")] + public IActionResult Delete(int id) + { + var result = _specializationService.Delete(id); + if (result) + { + return NoContent(); + } + else + { + return NotFound(); + } + } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs new file mode 100644 index 0000000..0fb45d5 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs @@ -0,0 +1,80 @@ +using DoctorsHelp.Application.Contracts; +using DoctorsHelp.Application.Models; +using Microsoft.AspNetCore.Mvc; + +namespace DoctorsHelp.Presentation.Http.Controllers; + +[ApiController] +[Route("[controller]")] +public class UserController : ControllerBase +{ + private readonly IUserService _userService; + + public UserController(IUserService userService) + { + _userService = userService; + } + + [HttpGet("{id}")] + public ActionResult Get(Guid id) + { + var user = _userService.GetUser(id); + if (user == null) + { + return NotFound(); + } + + return Ok(user); + } + + [HttpPost("register")] + public ActionResult Register([FromBody] User userdata) + { + if (string.IsNullOrWhiteSpace(userdata.Name) || + string.IsNullOrWhiteSpace(userdata.Surname) || + string.IsNullOrWhiteSpace(userdata.Phone) || + string.IsNullOrWhiteSpace(userdata.Email) || + string.IsNullOrWhiteSpace(userdata.HashedPassword)) + { + return BadRequest("All fields are required."); + } + + try + { + var user = _userService.Register(userdata.Name, userdata.Surname, userdata.Phone, userdata.Email, userdata.HashedPassword, userdata.Birthdate); + return CreatedAtAction(nameof(Get), new { id = user.Id }, user); + } + catch (Exception ex) + { + return StatusCode(500, "An error occurred while registering the user. " + ex.Message); + } + } + + [HttpPut("{id}")] + public ActionResult Update(Guid id, [FromBody] Dictionary data) + { + try + { + var updatedUser = _userService.UpdateUser(id, data); + return Ok(updatedUser); + } + catch (KeyNotFoundException) + { + return NotFound(); + } + } + + [HttpDelete("{id}")] + public IActionResult Delete(Guid id) + { + var result = _userService.DeleteUser(id); + if (result) + { + return NoContent(); + } + else + { + return NotFound(); + } + } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/DoctorsHelp.Presentation.Http.csproj b/src/Presentation/DoctorsHelp.Presentation.Http/DoctorsHelp.Presentation.Http.csproj index 21d1366..b0f89eb 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/DoctorsHelp.Presentation.Http.csproj +++ b/src/Presentation/DoctorsHelp.Presentation.Http/DoctorsHelp.Presentation.Http.csproj @@ -5,7 +5,7 @@ - + \ No newline at end of file From a202efb81d29a1bf4610b02ffcda73a447065137 Mon Sep 17 00:00:00 2001 From: AlexYrkn <61319606+AlexYrkn@users.noreply.github.com> Date: Sat, 16 Mar 2024 19:18:10 +0300 Subject: [PATCH 09/12] post data swagger fixed --- .../IAppointmentService.cs | 2 +- .../IEmployeeService.cs | 2 +- .../IReviewService.cs | 2 +- .../IScheduleService.cs | 2 +- .../Services/AppointmentService.cs | 11 +++++++++-- .../Services/EmployeeService.cs | 11 +++++++++-- .../Services/ReviewService.cs | 8 ++++++-- .../Services/ScheduleService.cs | 8 ++++++-- src/DoctorsHelp/appsettings.Local.json | 12 ++++++++++++ src/DoctorsHelp/appsettings.json | 6 +++++- .../Controllers/AppointmentController.cs | 12 ++++-------- .../Controllers/EmployeeController.cs | 7 ++++--- .../Controllers/ReviewController.cs | 9 +++++---- .../Controllers/ScheduleController.cs | 11 ++++++----- .../Controllers/SpecializationController.cs | 7 ++++--- .../Controllers/UserController.cs | 15 ++++++++------- .../Requests/AppointmentPost.cs | 8 ++++++++ .../Requests/EmployeePost.cs | 12 ++++++++++++ .../Requests/ReviewPost.cs | 10 ++++++++++ .../Requests/SchedulePost.cs | 10 ++++++++++ .../Requests/SpecializationPost.cs | 8 ++++++++ .../Requests/UserPost.cs | 16 ++++++++++++++++ 22 files changed, 146 insertions(+), 43 deletions(-) create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Requests/AppointmentPost.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Requests/EmployeePost.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Requests/ReviewPost.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Requests/SchedulePost.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Requests/SpecializationPost.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Requests/UserPost.cs diff --git a/src/Application/DoctorsHelp.Application.Contracts/IAppointmentService.cs b/src/Application/DoctorsHelp.Application.Contracts/IAppointmentService.cs index a1fbfab..62dc2bd 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IAppointmentService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IAppointmentService.cs @@ -4,7 +4,7 @@ namespace DoctorsHelp.Application.Contracts; public interface IAppointmentService { - Appointment Create(User patient, Schedule schedule); + Appointment Create(Guid patientId, int scheduleId); Appointment? GetAppointment(int patientId); diff --git a/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs b/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs index 2cd3089..d20faa5 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs @@ -4,7 +4,7 @@ namespace DoctorsHelp.Application.Contracts; public interface IEmployeeService { - Employee Create(User user, Specialization specialization, string graduate, string experience); + Employee Create(Guid userId, int specializationId, string graduate, string experience); Employee? GetEmployee(int employeeId); diff --git a/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs b/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs index d150ccd..3d64b36 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs @@ -4,7 +4,7 @@ namespace DoctorsHelp.Application.Contracts; public interface IReviewService { - Review Create(Appointment appointment, int? grade, string comment); + Review Create(int appointmentId, int? grade, string comment); Review? GetReview(int reviewId); diff --git a/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs b/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs index b53d083..0a457cf 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs @@ -4,7 +4,7 @@ namespace DoctorsHelp.Application.Contracts; public interface IScheduleService { - Schedule Create(Employee employee, DateTime? dateStart, DateTime? dateEnd); + Schedule Create(int employeeId, DateTime? dateStart, DateTime? dateEnd); Schedule? GetSchedule(int scheduleId); diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs index 1d58824..e51837f 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs @@ -9,14 +9,21 @@ namespace DoctorsHelp.Application.Contracts.Services; public class AppointmentService : IAppointmentService { private readonly IAppointmentRepository _appointmentRepository; + private readonly IUserRepository _patientRepository; + private readonly IScheduleRepository _scheduleRepository; - public AppointmentService(AppointmentRepository appointmentRepository) + public AppointmentService(AppointmentRepository appointmentRepository, UserRepository userRepository, ScheduleRepository scheduleRepository) { _appointmentRepository = appointmentRepository; + _patientRepository = userRepository; + _scheduleRepository = scheduleRepository; } - public Appointment Create(User patient, Schedule schedule) + public Appointment Create(Guid patientId, int scheduleId) { + User patient = UserConverter.UserModelToUser(_patientRepository.GetUser(patientId)); + Schedule schedule = ScheduleConverter.ScheduleModelToSchedule(_scheduleRepository.GetSchedule(scheduleId)); + var appointment = new Appointment { // Assuming Appointment has a constructor or properties for this diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs index 14936db..004b8d7 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs @@ -9,14 +9,21 @@ namespace DoctorsHelp.Application.Contracts.Services; public class EmployeeService : IEmployeeService { private readonly IEmployeeRepository _employeeRepository; + private readonly IUserRepository _userRepository; + private readonly ISpecializationRepository _specializationRepository; - public EmployeeService(EmployeeRepository appointmentRepository) + public EmployeeService(EmployeeRepository appointmentRepository, UserRepository userRepository, SpecializationRepository specializationRepository) { _employeeRepository = appointmentRepository; + _userRepository = userRepository; + _specializationRepository = specializationRepository; } - public Employee Create(User user, Specialization specialization, string graduate, string experience) + public Employee Create(Guid userId, int specializationId, string graduate, string experience) { + User user = UserConverter.UserModelToUser(_userRepository.GetUser(userId)); + Specialization specialization = SpecializationConverter.SpecializationModelToSpecialization(_specializationRepository.GetSpecialization(specializationId)); + var employee = new Employee { User = user, diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs index 0bf4028..6da3f73 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs @@ -9,14 +9,18 @@ namespace DoctorsHelp.Application.Contracts.Services; public class ReviewService : IReviewService { private readonly IReviewRepository _reviewRepository; + private readonly IAppointmentRepository _appointmentRepository; - public ReviewService(ReviewRepository reviewRepository) + public ReviewService(ReviewRepository reviewRepository, AppointmentRepository appointmentRepository) { _reviewRepository = reviewRepository; + _appointmentRepository = appointmentRepository; } - public Review Create(Appointment appointment, int? grade, string comment) + public Review Create(int appointmentId, int? grade, string comment) { + Appointment appointment = AppointmentConverter.AppointmentModelToAppointment(_appointmentRepository.GetAppointment(appointmentId)); + var review = new Review { Appointment = appointment, diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs index 1e2032f..b3135ea 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs @@ -9,14 +9,18 @@ namespace DoctorsHelp.Application.Contracts.Services; public class ScheduleService : IScheduleService { private readonly IScheduleRepository _scheduleRepository; + private readonly IEmployeeRepository _employeeRepository; - public ScheduleService(ScheduleRepository scheduleRepository) + public ScheduleService(ScheduleRepository scheduleRepository, EmployeeRepository employeeRepository) { _scheduleRepository = scheduleRepository; + _employeeRepository = employeeRepository; } - public Schedule Create(Employee employee, DateTime? dateStart, DateTime? dateEnd) + public Schedule Create(int employeeId, DateTime? dateStart, DateTime? dateEnd) { + Employee employee = EmployeeConverter.EmployeeModelToEmployee(_employeeRepository.GetEmployee(employeeId)); + var schedule = new Schedule { // Assuming Appointment has a constructor or properties for this diff --git a/src/DoctorsHelp/appsettings.Local.json b/src/DoctorsHelp/appsettings.Local.json index a26180e..d4175a0 100644 --- a/src/DoctorsHelp/appsettings.Local.json +++ b/src/DoctorsHelp/appsettings.Local.json @@ -17,6 +17,18 @@ "Host": "localhost:9092" } }, + "Kestrel": { + "Endpoints": { + "gRPC": { + "Url": "http://*:3071", + "Protocols": "Http2" + }, + "http": { + "Url": "http://*:3070", + "Protocols": "Http1" + } + } + }, "Platform": { "Environment": "Local" }, diff --git a/src/DoctorsHelp/appsettings.json b/src/DoctorsHelp/appsettings.json index 46b1ad6..cd55282 100644 --- a/src/DoctorsHelp/appsettings.json +++ b/src/DoctorsHelp/appsettings.json @@ -30,8 +30,12 @@ "Kestrel": { "Endpoints": { "gRPC": { - "Url": "http://*:8070", + "Url": "http://*:3071", "Protocols": "Http2" + }, + "http": { + "Url": "http://*:3070", + "Protocols": "Http1" } } }, diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/AppointmentController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/AppointmentController.cs index 364db4c..1dcd99d 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/AppointmentController.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/AppointmentController.cs @@ -1,5 +1,6 @@ using DoctorsHelp.Application.Contracts; using DoctorsHelp.Application.Models; +using DoctorsHelp.Presentation.Http.Requests; using Microsoft.AspNetCore.Mvc; namespace DoctorsHelp.Presentation.Http.Controllers; @@ -27,16 +28,11 @@ public ActionResult Get(int id) } [HttpPost] - public ActionResult Post([FromBody] Appointment appointment) + public ActionResult Post([FromBody] AppointmentPost data) { - if (appointment.Patient == null || appointment.Schedule == null) - { - return BadRequest("Patient and Schedule are required."); - } - try { - var createdAppointment = _appointmentService.Create(appointment.Patient, appointment.Schedule); + var createdAppointment = _appointmentService.Create(data.PatientId, data.ScheduleId); return CreatedAtAction(nameof(Get), new { id = createdAppointment.Id }, createdAppointment); } catch (Exception ex) @@ -72,4 +68,4 @@ public IActionResult Delete(int id) return NotFound(); } } -} \ No newline at end of file +} diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/EmployeeController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/EmployeeController.cs index 16c01ff..51ec312 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/EmployeeController.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/EmployeeController.cs @@ -1,5 +1,6 @@ using DoctorsHelp.Application.Contracts; using DoctorsHelp.Application.Models; +using DoctorsHelp.Presentation.Http.Requests; using Microsoft.AspNetCore.Mvc; namespace DoctorsHelp.Presentation.Http.Controllers; @@ -28,16 +29,16 @@ public ActionResult Get(int id) } [HttpPost] - public ActionResult Post([FromBody] Employee employee) + public ActionResult Post([FromBody] EmployeePost data) { - if (employee.User == null || employee.Specialization == null || string.IsNullOrWhiteSpace(employee.Graduate) || string.IsNullOrWhiteSpace(employee.Experience)) + if (string.IsNullOrWhiteSpace(data.Graduate) || string.IsNullOrWhiteSpace(data.Experience)) { return BadRequest("User, Specialization, Graduate, and Experience are required."); } try { - var createdEmployee = _employeeService.Create(employee.User, employee.Specialization, employee.Graduate, employee.Experience); + var createdEmployee = _employeeService.Create(data.UserId, data.SpecializationId, data.Graduate, data.Experience); return CreatedAtAction(nameof(Get), new { id = createdEmployee.Id }, createdEmployee); } catch (Exception ex) diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ReviewController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ReviewController.cs index 13d2fba..f505756 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ReviewController.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ReviewController.cs @@ -1,5 +1,6 @@ using DoctorsHelp.Application.Contracts; using DoctorsHelp.Application.Models; +using DoctorsHelp.Presentation.Http.Requests; using Microsoft.AspNetCore.Mvc; namespace DoctorsHelp.Presentation.Http.Controllers; @@ -28,16 +29,16 @@ public ActionResult Get(int id) } [HttpPost] - public ActionResult Post([FromBody] Review review) + public ActionResult Post([FromBody] ReviewPost data) { - if (review.Appointment == null || review.Grade < 1 || string.IsNullOrWhiteSpace(review.Comment) || review.Grade == null) + if (data.Grade < 1 || string.IsNullOrWhiteSpace(data.Comment)) { return BadRequest("Appointment, Grade, and Comment are required."); } try { - var createdReview = _reviewService.Create(review.Appointment, review.Grade, review.Comment); + var createdReview = _reviewService.Create(data.AppointmentId, data.Grade, data.Comment); return CreatedAtAction(nameof(Get), new { id = createdReview.Id }, createdReview); } catch (Exception ex) @@ -73,4 +74,4 @@ public IActionResult Delete(int id) return NotFound(); } } -} \ No newline at end of file +} diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ScheduleController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ScheduleController.cs index 1f2ff89..6f25469 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ScheduleController.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ScheduleController.cs @@ -1,5 +1,6 @@ using DoctorsHelp.Application.Contracts; using DoctorsHelp.Application.Models; +using DoctorsHelp.Presentation.Http.Requests; using Microsoft.AspNetCore.Mvc; namespace DoctorsHelp.Presentation.Http.Controllers; @@ -28,21 +29,21 @@ public ActionResult Get(int id) } [HttpPost] - public ActionResult Post([FromBody] Schedule schedule) + public ActionResult Post([FromBody] SchedulePost data) { - if (schedule.Employee == null || schedule.DateStart == default || schedule.DateEnd == default) + if (data.DateStart == default || data.DateEnd == default) { return BadRequest("Employee, DateStart, and DateEnd are required."); } - if (schedule.DateStart >= schedule.DateEnd) + if (data.DateStart >= data.DateEnd) { return BadRequest("DateStart must be before DateEnd."); } try { - var createdSchedule = _scheduleService.Create(schedule.Employee, schedule.DateStart, schedule.DateEnd); + var createdSchedule = _scheduleService.Create(data.EmployeeId, data.DateStart, data.DateEnd); return CreatedAtAction(nameof(Get), new { id = createdSchedule.Id }, createdSchedule); } catch (Exception ex) @@ -78,4 +79,4 @@ public IActionResult Delete(int id) return NotFound(); } } -} \ No newline at end of file +} diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/SpecializationController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/SpecializationController.cs index d8aae17..bf36cd4 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/SpecializationController.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/SpecializationController.cs @@ -1,5 +1,6 @@ using DoctorsHelp.Application.Contracts; using DoctorsHelp.Application.Models; +using DoctorsHelp.Presentation.Http.Requests; using Microsoft.AspNetCore.Mvc; namespace DoctorsHelp.Presentation.Http.Controllers; @@ -28,16 +29,16 @@ public ActionResult Get(int id) } [HttpPost] - public ActionResult Post([FromBody] Specialization specialization) + public ActionResult Post([FromBody] SpecializationPost data) { - if (specialization.Name == null || specialization.Description == null) + if (data.Name == null || data.Description == null) { return BadRequest("Name and Description are required."); } try { - var createdSpecialization = _specializationService.Create(specialization.Name, specialization.Description); + var createdSpecialization = _specializationService.Create(data.Name, data.Description); return CreatedAtAction(nameof(Get), new { id = createdSpecialization.Id }, createdSpecialization); } catch (Exception ex) diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs index 0fb45d5..4224753 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs @@ -1,5 +1,6 @@ using DoctorsHelp.Application.Contracts; using DoctorsHelp.Application.Models; +using DoctorsHelp.Presentation.Http.Requests; using Microsoft.AspNetCore.Mvc; namespace DoctorsHelp.Presentation.Http.Controllers; @@ -28,20 +29,20 @@ public ActionResult Get(Guid id) } [HttpPost("register")] - public ActionResult Register([FromBody] User userdata) + public ActionResult Register([FromBody] UserPost data) { - if (string.IsNullOrWhiteSpace(userdata.Name) || - string.IsNullOrWhiteSpace(userdata.Surname) || - string.IsNullOrWhiteSpace(userdata.Phone) || - string.IsNullOrWhiteSpace(userdata.Email) || - string.IsNullOrWhiteSpace(userdata.HashedPassword)) + if (string.IsNullOrWhiteSpace(data.Name) || + string.IsNullOrWhiteSpace(data.Surname) || + string.IsNullOrWhiteSpace(data.Phone) || + string.IsNullOrWhiteSpace(data.Email) || + string.IsNullOrWhiteSpace(data.Password)) { return BadRequest("All fields are required."); } try { - var user = _userService.Register(userdata.Name, userdata.Surname, userdata.Phone, userdata.Email, userdata.HashedPassword, userdata.Birthdate); + var user = _userService.Register(data.Name, data.Surname, data.Phone, data.Email, data.Password, data.Birthdate); return CreatedAtAction(nameof(Get), new { id = user.Id }, user); } catch (Exception ex) diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Requests/AppointmentPost.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/AppointmentPost.cs new file mode 100644 index 0000000..a039709 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/AppointmentPost.cs @@ -0,0 +1,8 @@ +namespace DoctorsHelp.Presentation.Http.Requests; + +public class AppointmentPost +{ + public Guid PatientId { get; set; } + + public int ScheduleId { get; set; } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Requests/EmployeePost.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/EmployeePost.cs new file mode 100644 index 0000000..ec39450 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/EmployeePost.cs @@ -0,0 +1,12 @@ +namespace DoctorsHelp.Presentation.Http.Requests; + +public class EmployeePost +{ + public Guid UserId { get; set; } + + public int SpecializationId { get; set; } + + public string? Graduate { get; set; } + + public string? Experience { get; set; } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Requests/ReviewPost.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/ReviewPost.cs new file mode 100644 index 0000000..432f679 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/ReviewPost.cs @@ -0,0 +1,10 @@ +namespace DoctorsHelp.Presentation.Http.Requests; + +public class ReviewPost +{ + public int AppointmentId { get; set; } + + public int Grade { get; set; } + + public string? Comment { get; set; } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Requests/SchedulePost.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/SchedulePost.cs new file mode 100644 index 0000000..76b7e45 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/SchedulePost.cs @@ -0,0 +1,10 @@ +namespace DoctorsHelp.Presentation.Http.Requests; + +public class SchedulePost +{ + public int EmployeeId { get; set; } + + public DateTime? DateStart { get; set; } + + public DateTime? DateEnd { get; set; } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Requests/SpecializationPost.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/SpecializationPost.cs new file mode 100644 index 0000000..92f5848 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/SpecializationPost.cs @@ -0,0 +1,8 @@ +namespace DoctorsHelp.Presentation.Http.Requests; + +public class SpecializationPost +{ + public string? Name { get; set; } + + public string? Description { get; set; } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Requests/UserPost.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/UserPost.cs new file mode 100644 index 0000000..8eeb26b --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/UserPost.cs @@ -0,0 +1,16 @@ +namespace DoctorsHelp.Presentation.Http.Requests; + +public class UserPost +{ + public string? Name { get; set; } + + public string? Surname { get; set; } + + public string? Phone { get; set; } + + public string? Email { get; set; } + + public string? Password { get; set; } + + public DateOnly Birthdate { get; set; } +} \ No newline at end of file From 05ee8d142c76309457482b8650c07194461808bd Mon Sep 17 00:00:00 2001 From: owarpero Date: Sat, 6 Apr 2024 01:56:56 +0300 Subject: [PATCH 10/12] fix: 500 --- .editorconfig | 569 ++++++++++++++++++ .../IEmployeeService.cs | 2 +- .../ISpecializationService.cs | 6 +- .../Services/AppointmentService.cs | 3 +- .../Services/EmployeeService.cs | 6 +- .../Services/SpecializationService.cs | 12 +- .../Specialization.cs | 2 +- .../Extensions/ServiceCollectionExtensions.cs | 36 +- .../Interfaces/ISpecializationRepository.cs | 4 +- .../Models/EmployeeModel.cs | 2 +- .../Models/SpecializationModel.cs | 2 +- .../Repositories/SpecializationRepository.cs | 7 +- .../Controllers/SpecializationController.cs | 8 +- .../Requests/EmployeePost.cs | 2 +- 14 files changed, 612 insertions(+), 49 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..46b858b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,569 @@ +# https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/language-rules + +[*.{cs,vb}] +tab_width = 4 +indent_size = 4 +end_of_line = crlf + +dotnet_diagnostic.ide0001.severity = warning +dotnet_diagnostic.ide0002.severity = warning + +# IDE0003 and IDE0009 +dotnet_diagnostic.sa0001.severity = none +dotnet_diagnostic.ide0003.severity = warning +dotnet_diagnostic.ide0009.severity = warning +dotnet_style_qualification_for_field = false:warning +dotnet_style_qualification_for_property = false:warning +dotnet_style_qualification_for_method = false:warning +dotnet_style_qualification_for_event = false:warning + +dotnet_diagnostic.SA1010.severity = none + +dotnet_diagnostic.ide0004.severity = warning +dotnet_diagnostic.ide0005.severity = warning + +# IDE0007 and IDE0008 +dotnet_diagnostic.ide0007.severity = warning +dotnet_diagnostic.ide0008.severity = warning +csharp_style_var_when_type_is_apparent = true:warning +csharp_style_var_for_built_in_types = false:silent +csharp_style_var_elsewhere = false:silent + +# IDE0010 +dotnet_diagnostic.ide0010.severity = suggestion + +# IDE0011 +dotnet_diagnostic.ide0011.severity = warning +csharp_prefer_braces = when_multiline:warning + +# IDE0016 +dotnet_diagnostic.ide0016.severity = warning +csharp_style_throw_expression = true:warning + +# IDE0017 +dotnet_diagnostic.ide0017.severity = suggestion +dotnet_style_object_initializer = true:suggestion + +# IDE0018 +dotnet_diagnostic.ide0018.severity = suggestion +csharp_style_inlined_variable_declaration = true:suggestion + +# IDE0019 +dotnet_diagnostic.ide0019.severity = warning +csharp_style_pattern_matching_over_as_with_null_check = true:warning + +# IDE0020 and IDE0038 +dotnet_diagnostic.ide0020.severity = warning +dotnet_diagnostic.ide0038.severity = warning +csharp_style_pattern_matching_over_is_with_cast_check = true:warning + +# IDE0021 +dotnet_diagnostic.ide0021.severity = warning +csharp_style_expression_bodied_constructors = false:warning + +# IDE0022 +dotnet_diagnostic.ide0022.severity = suggestion +csharp_style_expression_bodied_methods = false:suggestion + +# IDE0023 and IDE0024 +dotnet_diagnostic.ide0023.severity = suggestion +dotnet_diagnostic.ide0024.severity = suggestion +csharp_style_expression_bodied_operators = when_on_single_line:suggestion + +# IDE0025 +dotnet_diagnostic.ide0025.severity = warning +csharp_style_expression_bodied_properties = when_on_single_line:warning + +# IDE0026 +dotnet_diagnostic.ide0026.severity = suggestion +csharp_style_expression_bodied_indexers = when_on_single_line:suggestion + +# IDE0027 +dotnet_diagnostic.ide0027.severity = suggestion +csharp_style_expression_bodied_accessors = when_on_single_line:suggestion + +# IDE0028 +dotnet_diagnostic.ide0028.severity = suggestion +dotnet_style_collection_initializer = true:suggestion + +# IDE0029 and IDE0030 +dotnet_diagnostic.ide0029.severity = suggestion +dotnet_diagnostic.ide0030.severity = suggestion +dotnet_style_coalesce_expression = true:suggestion + +# IDE0031 +dotnet_diagnostic.ide0031.severity = suggestion +dotnet_style_null_propagation = true:suggestion + +# IDE0032 +dotnet_diagnostic.ide0032.severity = warning +dotnet_style_prefer_auto_properties = true:warning + +# IDE0033 +dotnet_diagnostic.ide0033.severity = warning +dotnet_style_explicit_tuple_names = true:warning + +# IDE0034 +dotnet_diagnostic.ide0034.severity = warning +csharp_prefer_simple_default_expression = true:warning + +# IDE0035 +dotnet_diagnostic.ide0035.severity = warning + +# IDE0036 +dotnet_diagnostic.ide0036.severity = warning +csharp_preferred_modifier_order = public, private, protected, internal, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async + +# IDE0037 +dotnet_diagnostic.ide0037.severity = warning +dotnet_style_prefer_inferred_tuple_names = true:warning +dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning + +# IDE0039 +dotnet_diagnostic.ide0039.severity = suggestion +csharp_style_prefer_local_over_anonymous_function = true:suggestion + +# IDE0040 +dotnet_diagnostic.ide0040.severity = warning +dotnet_style_require_accessibility_modifiers = always:warning + +# IDE0041 +dotnet_diagnostic.ide0041.severity = warning +dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning + +# IDE0042 +dotnet_diagnostic.ide0042.severity = suggestion +csharp_style_deconstructed_variable_declaration = true:suggestion + +# IDE0044 +dotnet_diagnostic.ide0044.severity = warning +dotnet_style_readonly_field = true:warning + +# IDE0045 +dotnet_diagnostic.ide0045.severity = suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion + +# IDE0046 +dotnet_diagnostic.ide0046.severity = suggestion +dotnet_style_prefer_conditional_expression_over_return = true:suggestion + +# IDE0047 and IDE0048 +dotnet_diagnostic.ide0047.severity = warning +dotnet_diagnostic.ide0048.severity = warning +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning +dotnet_style_parentheses_in_other_operators = never_if_unnecessary:warning + +# IDE0049 +dotnet_diagnostic.ide0049.severity = warning +dotnet_style_predefined_type_for_locals_parameters_members = true:warning +dotnet_style_predefined_type_for_member_access = true:warning + +# IDE0050-52 +dotnet_diagnostic.ide0050.severity = warning +dotnet_diagnostic.ide0051.severity = warning +dotnet_diagnostic.ide0052.severity = warning + +# IDE0053 +dotnet_diagnostic.ide0053.severity = suggestion +csharp_style_expression_bodied_lambdas = true:suggestion + +# IDE0054 and IDE0074 +dotnet_diagnostic.ide0054.severity = suggestion +dotnet_diagnostic.ide0074.severity = suggestion +dotnet_style_prefer_compound_assignment = true:suggestion + +# IDE0055 +dotnet_sort_system_directives_first = false +dotnet_separate_import_directive_groups = false +dotnet_style_namespace_match_folder = true:warning +csharp_new_line_before_open_brace = all +csharp_new_line_before_else = true +csharp_new_line_before_catch = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_object_initializers = false +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_between_query_expression_clauses = true +csharp_indent_case_contents = true +csharp_indent_switch_labels = true +csharp_indent_labels = no_change +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents_when_block = false +csharp_space_after_cast = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_between_parentheses = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_around_binary_operators = before_and_after +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_after_comma = true +csharp_space_before_comma = false +csharp_space_after_dot = false +csharp_space_before_dot = false +csharp_space_after_semicolon_in_for_statement = true +csharp_space_before_semicolon_in_for_statement = false +csharp_space_around_declaration_statements = false +csharp_space_before_open_square_brackets = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_square_brackets = false +csharp_preserve_single_line_statements = true +csharp_preserve_single_line_blocks = true + +# IDE0056 +dotnet_diagnostic.ide0056.severity = warning +csharp_style_prefer_index_operator = false:warning + +# IDE0057 +dotnet_diagnostic.ide0057.severity = warning +csharp_style_prefer_range_operator = false:warning + +# IDE0058, IDE0059, IDE0060 +dotnet_diagnostic.ide0058.severity = none +dotnet_diagnostic.ide0059.severity = none +dotnet_diagnostic.ide0060.severity = none +csharp_style_unused_value_expression_statement_preference = discard_variable:none +csharp_style_unused_value_assignment_preference = discard_variable:none +dotnet_code_quality_unused_parameters = all:none + + +# IDE0061 +dotnet_diagnostic.ide0061.severity = suggestion +csharp_style_expression_bodied_local_functions = false:suggestion + +# IDE0062 +dotnet_diagnostic.ide0062.severity = suggestion +csharp_prefer_static_local_function = true:suggestion + +# IDE0063 +dotnet_diagnostic.ide0063.severity = warning +csharp_prefer_simple_using_statement = true:warning + +# IDE0064 +dotnet_diagnostic.ide0064.severity = warning +dotnet_diagnostic.ide0064.severity = none + +# IDE0065 +dotnet_diagnostic.ide0065.severity = warning +csharp_using_directive_placement = outside_namespace:warning + +# IDE0066 +dotnet_diagnostic.ide0066.severity = warning +csharp_style_prefer_switch_expression = true:warning + +# IDE0070 +dotnet_diagnostic.ide0070.severity = warning + +# IDE0071 +dotnet_diagnostic.ide0071.severity = none +dotnet_style_prefer_simplified_interpolation = true:suggestion + +# IDE0072 +dotnet_diagnostic.ide0072.severity = warning + +# IDE0073 +file_header_template = unset + +# IDE0075 +dotnet_diagnostic.ide0075.severity = suggestion +dotnet_style_prefer_simplified_boolean_expressions = true:suggestion + +# IDE0078 +# dotnet_diagnostic.IDE0078.severity = warning +# csharp_style_prefer_pattern_matching = true:suggestion +csharp_style_prefer_pattern_matching = true:none + +# IDE0082 +dotnet_diagnostic.ide0082.severity = warning + +# IDE0083 +dotnet_diagnostic.ide0083.severity = warning +csharp_style_prefer_not_pattern = true:warning + +# IDE0090 +dotnet_diagnostic.ide0090.severity = warning +csharp_style_implicit_object_creation_when_type_is_apparent = false:warning + +# IDE0100 +dotnet_diagnostic.ide0100.severity = warning + +# IDE0110 +dotnet_diagnostic.ide0110.severity = warning + +# IDE0150 +dotnet_diagnostic.ide0150.severity = warning +csharp_style_prefer_null_check_over_type_check = false:warning + +# IDE0160 and IDE0161 +dotnet_diagnostic.ide0161.severity = warning +csharp_style_namespace_declarations = file_scoped:warning + +# IDE0170 +dotnet_diagnostic.ide0170.severity = none +csharp_style_prefer_extended_property_pattern = true:none + +# IDE0180 +dotnet_diagnostic.ide0180.severity = suggestion +csharp_style_prefer_tuple_swap = false:suggestion + +# IDE1005 +dotnet_diagnostic.ide1005.severity = suggestion +csharp_style_conditional_delegate_call = true:suggestion + +dotnet_diagnostic.ca1000.severity = none +dotnet_diagnostic.ca1001.severity = warning +dotnet_diagnostic.ca1002.severity = warning +dotnet_diagnostic.ca1003.severity = none +dotnet_diagnostic.ca1005.severity = none +dotnet_diagnostic.ca1008.severity = none +dotnet_diagnostic.ca1010.severity = warning +dotnet_diagnostic.ca1012.severity = warning +dotnet_diagnostic.ca1014.severity = none +dotnet_diagnostic.ca1016.severity = none +dotnet_diagnostic.ca1017.severity = none +dotnet_diagnostic.ca1018.severity = warning +dotnet_diagnostic.ca1019.severity = warning +dotnet_diagnostic.ca1021.severity = warning +dotnet_diagnostic.ca1024.severity = suggestion +dotnet_diagnostic.ca1027.severity = none +dotnet_diagnostic.ca1028.severity = warning +dotnet_diagnostic.ca1030.severity = none +dotnet_diagnostic.ca1031.severity = none +dotnet_diagnostic.ca1032.severity = none +dotnet_diagnostic.ca1033.severity = none +dotnet_diagnostic.ca1034.severity = none +dotnet_diagnostic.ca1036.severity = silent +dotnet_diagnostic.ca1040.severity = none +dotnet_diagnostic.ca1041.severity = suggestion +dotnet_diagnostic.ca1043.severity = none +dotnet_diagnostic.ca1044.severity = warning +dotnet_diagnostic.ca1045.severity = warning +dotnet_diagnostic.ca1046.severity = suggestion +dotnet_diagnostic.ca1047.severity = warning +dotnet_diagnostic.ca1050.severity = warning +dotnet_diagnostic.ca1051.severity = warning +dotnet_diagnostic.ca1052.severity = none +dotnet_diagnostic.ca1053.severity = none +dotnet_diagnostic.ca1054.severity = suggestion +dotnet_diagnostic.ca1055.severity = suggestion +dotnet_diagnostic.ca1056.severity = suggestion +dotnet_diagnostic.ca1058.severity = warning +dotnet_diagnostic.ca1060.severity = none +dotnet_diagnostic.ca1061.severity = warning +dotnet_diagnostic.ca1062.severity = none +dotnet_diagnostic.ca1063.severity = none +dotnet_diagnostic.ca1064.severity = warning +dotnet_diagnostic.ca1065.severity = warning +dotnet_diagnostic.ca1067.severity = warning +dotnet_diagnostic.ca1068.severity = suggestion +dotnet_diagnostic.ca1069.severity = warning +dotnet_diagnostic.ca1079.severity = warning +dotnet_diagnostic.ca1200.severity = none +dotnet_diagnostic.ca1303.severity = none +dotnet_diagnostic.ca1304.severity = none +dotnet_diagnostic.ca1305.severity = none +dotnet_diagnostic.ca1307.severity = warning +dotnet_diagnostic.ca1308.severity = suggestion +dotnet_diagnostic.ca1309.severity = suggestion +dotnet_diagnostic.ca1310.severity = suggestion +dotnet_diagnostic.ca1401.severity = warning +dotnet_diagnostic.ca1416.severity = warning +dotnet_diagnostic.ca1417.severity = warning +dotnet_diagnostic.ca1418.severity = warning +dotnet_diagnostic.ca1419.severity = warning +dotnet_diagnostic.ca1501.severity = warning +dotnet_diagnostic.ca1502.severity = warning +dotnet_diagnostic.ca1505.severity = warning +dotnet_diagnostic.ca1506.severity = warning +dotnet_diagnostic.ca1507.severity = suggestion +dotnet_diagnostic.ca1508.severity = warning +# dotnet_diagnostic.CA1509.severity = none +dotnet_diagnostic.ca1700.severity = none +dotnet_diagnostic.ca1707.severity = warning +dotnet_diagnostic.ca1708.severity = none +dotnet_diagnostic.ca1710.severity = none +dotnet_diagnostic.ca1711.severity = none +dotnet_diagnostic.ca1712.severity = none +dotnet_diagnostic.ca1713.severity = none +dotnet_diagnostic.ca1714.severity = suggestion +dotnet_diagnostic.ca1715.severity = warning +dotnet_diagnostic.ca1716.severity = warning +dotnet_diagnostic.ca1717.severity = none +dotnet_diagnostic.ca1720.severity = warning +dotnet_diagnostic.ca1721.severity = warning +dotnet_diagnostic.ca1724.severity = warning +dotnet_diagnostic.ca1725.severity = warning +dotnet_diagnostic.ca1727.severity = none +dotnet_diagnostic.ca1801.severity = warning +dotnet_diagnostic.ca1802.severity = warning +dotnet_diagnostic.ca1805.severity = none +dotnet_diagnostic.ca1806.severity = none +dotnet_diagnostic.ca1810.severity = none +dotnet_diagnostic.ca1812.severity = none +# dotnet_diagnostic.CA1812.severity = warning +dotnet_diagnostic.ca1813.severity = warning +dotnet_diagnostic.ca1814.severity = warning +dotnet_diagnostic.ca1815.severity = suggestion +dotnet_diagnostic.ca1816.severity = none +dotnet_diagnostic.ca1819.severity = none +dotnet_diagnostic.ca1820.severity = warning +dotnet_diagnostic.ca1821.severity = warning +dotnet_diagnostic.ca1822.severity = none +dotnet_diagnostic.ca1823.severity = warning +dotnet_diagnostic.ca1824.severity = none +dotnet_diagnostic.ca1825.severity = warning +dotnet_diagnostic.ca1826.severity = none +dotnet_diagnostic.ca1827.severity = warning +dotnet_diagnostic.ca1828.severity = warning +dotnet_diagnostic.ca1829.severity = warning +dotnet_diagnostic.ca1830.severity = suggestion +dotnet_diagnostic.ca1831.severity = suggestion +dotnet_diagnostic.ca1832.severity = suggestion +dotnet_diagnostic.ca1833.severity = suggestion +dotnet_diagnostic.ca1834.severity = suggestion +dotnet_diagnostic.ca1835.severity = suggestion +dotnet_diagnostic.ca1836.severity = warning +dotnet_diagnostic.ca1837.severity = warning +dotnet_diagnostic.ca1838.severity = warning +dotnet_diagnostic.ca1841.severity = none +dotnet_diagnostic.ca1842.severity = none +dotnet_diagnostic.ca1843.severity = none +dotnet_diagnostic.ca1844.severity = warning +dotnet_diagnostic.ca1845.severity = suggestion +dotnet_diagnostic.ca1846.severity = suggestion +dotnet_diagnostic.ca1847.severity = suggestion +dotnet_diagnostic.ca1848.severity = none +dotnet_diagnostic.ca1849.severity = suggestion +dotnet_diagnostic.ca1850.severity = suggestion +dotnet_diagnostic.ca1851.severity = warning +dotnet_diagnostic.ca1854.severity = suggestion +dotnet_diagnostic.ca2000.severity = suggestion +# dotnet_diagnostic.CA2000.severity = warning +dotnet_diagnostic.ca2002.severity = none +dotnet_diagnostic.ca2008.severity = none +dotnet_diagnostic.ca2009.severity = warning +dotnet_diagnostic.ca2011.severity = warning +dotnet_diagnostic.ca2012.severity = warning +dotnet_diagnostic.ca2013.severity = warning +dotnet_diagnostic.ca2014.severity = warning +dotnet_diagnostic.ca2015.severity = warning +dotnet_diagnostic.ca2016.severity = suggestion +dotnet_diagnostic.ca2017.severity = warning +dotnet_diagnostic.ca2018.severity = warning +dotnet_diagnostic.ca2100.severity = warning +dotnet_diagnostic.ca2101.severity = none +dotnet_diagnostic.ca2201.severity = suggestion +# dotnet_diagnostic.CA2201.severity = warning +dotnet_diagnostic.ca2207.severity = warning +dotnet_diagnostic.ca2208.severity = warning +dotnet_diagnostic.ca2211.severity = suggestion +dotnet_diagnostic.ca2213.severity = warning +dotnet_diagnostic.ca2214.severity = suggestion +dotnet_diagnostic.ca2215.severity = warning +dotnet_diagnostic.ca2216.severity = none +dotnet_diagnostic.ca2217.severity = none +dotnet_diagnostic.ca2218.severity = warning +dotnet_diagnostic.ca2219.severity = warning +dotnet_diagnostic.ca2224.severity = warning +dotnet_diagnostic.ca2225.severity = none +dotnet_diagnostic.ca2226.severity = suggestion +dotnet_diagnostic.ca2227.severity = warning +dotnet_diagnostic.ca2229.severity = none +dotnet_diagnostic.ca2231.severity = suggestion +dotnet_diagnostic.ca2234.severity = silent +dotnet_diagnostic.ca2235.severity = none +dotnet_diagnostic.ca2237.severity = none +dotnet_diagnostic.ca2241.severity = warning +dotnet_diagnostic.ca2242.severity = warning +dotnet_diagnostic.ca2243.severity = warning +dotnet_diagnostic.ca2244.severity = warning +dotnet_diagnostic.ca2245.severity = warning +dotnet_diagnostic.ca2246.severity = warning +dotnet_diagnostic.ca2247.severity = warning +dotnet_diagnostic.ca2248.severity = warning +dotnet_diagnostic.ca2249.severity = warning +dotnet_diagnostic.ca2250.severity = warning +dotnet_diagnostic.ca2251.severity = warning +dotnet_diagnostic.ca2252.severity = none +dotnet_diagnostic.ca2253.severity = warning +dotnet_diagnostic.ca2254.severity = none +dotnet_diagnostic.ca2255.severity = none +dotnet_diagnostic.ca2256.severity = none +dotnet_diagnostic.ca2257.severity = none +dotnet_diagnostic.ca2258.severity = none + +# IDE1006 +dotnet_diagnostic.ide1006.severity = warning + +# camel_case_style - Define the camelCase style +dotnet_naming_style.camel_case_style.capitalization = camel_case +# pascal_case_style - Define the PascalCase style +dotnet_naming_style.pascal_case_style.capitalization = pascal_case +# first_upper_style - The first character must start with an upper-case character +dotnet_naming_style.first_upper_style.capitalization = first_word_upper +# prefix_interface_with_i_style - Interfaces must be PascalCase and the first character of an interface must be an 'I' +dotnet_naming_style.prefix_interface_with_i_style.capitalization = pascal_case +dotnet_naming_style.prefix_interface_with_i_style.required_prefix = I +# prefix_type_parameters_with_t_style - Generic Type Parameters must be PascalCase and the first character must be a 'T' +dotnet_naming_style.prefix_type_parameters_with_t_style.capitalization = pascal_case +dotnet_naming_style.prefix_type_parameters_with_t_style.required_prefix = T +# disallowed_style - Anything that has this style applied is marked as disallowed +dotnet_naming_style.disallowed_style.capitalization = pascal_case +dotnet_naming_style.disallowed_style.required_prefix = ____RULE_VIOLATION____ +dotnet_naming_style.disallowed_style.required_suffix = ____RULE_VIOLATION____ +dotnet_naming_style.internal_error_style.capitalization = pascal_case +dotnet_naming_style.internal_error_style.required_prefix = ____INTERNAL_ERROR____ +dotnet_naming_style.internal_error_style.required_suffix = ____INTERNAL_ERROR____ + +dotnet_naming_symbols.public_protected_constant_fields_group.applicable_accessibilities = public, protected, protected_internal +dotnet_naming_symbols.public_protected_constant_fields_group.required_modifiers = const +dotnet_naming_symbols.public_protected_constant_fields_group.applicable_kinds = field +dotnet_naming_rule.public_protected_constant_fields_must_be_pascal_case_rule.symbols = public_protected_constant_fields_group +dotnet_naming_rule.public_protected_constant_fields_must_be_pascal_case_rule.style = pascal_case_style +dotnet_naming_rule.public_protected_constant_fields_must_be_pascal_case_rule.severity = warning + +dotnet_naming_symbols.public_protected_static_readonly_fields_group.applicable_accessibilities = public, protected, protected_internal +dotnet_naming_symbols.public_protected_static_readonly_fields_group.required_modifiers = static, readonly +dotnet_naming_symbols.public_protected_static_readonly_fields_group.applicable_kinds = field +dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.symbols = public_protected_static_readonly_fields_group +dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.style = pascal_case_style +dotnet_naming_rule.public_protected_static_readonly_fields_must_be_pascal_case_rule.severity = warning + +dotnet_naming_symbols.other_public_protected_fields_group.applicable_accessibilities = public, protected, protected_internal +dotnet_naming_symbols.other_public_protected_fields_group.applicable_kinds = field +dotnet_naming_rule.other_public_protected_fields_disallowed_rule.symbols = other_public_protected_fields_group +dotnet_naming_rule.other_public_protected_fields_disallowed_rule.style = disallowed_style +dotnet_naming_rule.other_public_protected_fields_disallowed_rule.severity = error + +# Other + +dotnet_style_operator_placement_when_wrapping = beginning_of_line + + +# Not verified + +csharp_style_prefer_method_group_conversion = true:silent +csharp_style_prefer_top_level_statements = true:silent +csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent +csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent +csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent +dotnet_style_allow_multiple_blank_lines_experimental = true:silent +dotnet_style_allow_statement_immediately_after_block_experimental = true:silent +# IDE0230 +csharp_style_prefer_utf8_string_literals = true:suggestion + +# ReSharper +resharper_csharp_empty_block_style = together_same_line + +csharp_wrap_arguments_style = chop_if_long +csharp_wrap_chained_method_calls = chop_if_long + +# ReSharper properties +resharper_csharp_wrap_after_declaration_lpar = true +resharper_csharp_wrap_parameters_style = chop_if_long \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs b/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs index d20faa5..5ec82de 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs @@ -4,7 +4,7 @@ namespace DoctorsHelp.Application.Contracts; public interface IEmployeeService { - Employee Create(Guid userId, int specializationId, string graduate, string experience); + Employee Create(Guid userId, Guid specializationId, string graduate, string experience); Employee? GetEmployee(int employeeId); diff --git a/src/Application/DoctorsHelp.Application.Contracts/ISpecializationService.cs b/src/Application/DoctorsHelp.Application.Contracts/ISpecializationService.cs index dfc2a3d..8a22e7e 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/ISpecializationService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/ISpecializationService.cs @@ -6,9 +6,9 @@ public interface ISpecializationService { Specialization Create(string name, string description); - Specialization? GetSpecialization(int id); + Specialization? GetSpecialization(Guid id); - Specialization Update(int id, Dictionary data); + Specialization Update(Guid id, Dictionary data); - bool Delete(int id); + bool Delete(Guid id); } \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs index e51837f..cdc664d 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs @@ -1,7 +1,6 @@ using DoctorsHelp.Application.Models; using DoctorsHelp.Infrastructure.Persistence.Converters; using DoctorsHelp.Infrastructure.Persistence.Interfaces; -using DoctorsHelp.Infrastructure.Persistence.Repositories; using Infrastructure.Persistence.Models; namespace DoctorsHelp.Application.Contracts.Services; @@ -12,7 +11,7 @@ public class AppointmentService : IAppointmentService private readonly IUserRepository _patientRepository; private readonly IScheduleRepository _scheduleRepository; - public AppointmentService(AppointmentRepository appointmentRepository, UserRepository userRepository, ScheduleRepository scheduleRepository) + public AppointmentService(IAppointmentRepository appointmentRepository, IUserRepository userRepository, IScheduleRepository scheduleRepository) { _appointmentRepository = appointmentRepository; _patientRepository = userRepository; diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs index 004b8d7..8eaa2cc 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs @@ -19,7 +19,7 @@ public EmployeeService(EmployeeRepository appointmentRepository, UserRepository _specializationRepository = specializationRepository; } - public Employee Create(Guid userId, int specializationId, string graduate, string experience) + public Employee Create(Guid userId, Guid specializationId, string graduate, string experience) { User user = UserConverter.UserModelToUser(_userRepository.GetUser(userId)); Specialization specialization = SpecializationConverter.SpecializationModelToSpecialization(_specializationRepository.GetSpecialization(specializationId)); @@ -56,8 +56,8 @@ public Employee Update(int id, Dictionary data) employeeToUpdate.UserId = userId; break; case "SpecializationId": - int specializationId; - if (int.TryParse(entry.Value, out specializationId)) + Guid specializationId; + if (Guid.TryParse(entry.Value, out specializationId)) employeeToUpdate.SpecializationId = specializationId; break; case "Graduate": diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/SpecializationService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/SpecializationService.cs index 60b8889..996d1d1 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/SpecializationService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/SpecializationService.cs @@ -1,7 +1,6 @@ using DoctorsHelp.Application.Models; using DoctorsHelp.Infrastructure.Persistence.Converters; using DoctorsHelp.Infrastructure.Persistence.Interfaces; -using DoctorsHelp.Infrastructure.Persistence.Repositories; using Infrastructure.Persistence.Models; namespace DoctorsHelp.Application.Contracts.Services; @@ -10,7 +9,7 @@ public class SpecializationService : ISpecializationService { private readonly ISpecializationRepository _specializationRepository; - public SpecializationService(SpecializationRepository specializationRepository) + public SpecializationService(ISpecializationRepository specializationRepository) { _specializationRepository = specializationRepository; } @@ -19,21 +18,22 @@ public Specialization Create(string name, string description) { var specialization = new Specialization { + Id = Guid.NewGuid(), Name = name, Description = description, }; - _specializationRepository.Add(specialization); + _specializationRepository.AddSpecialization(specialization); return specialization; } - public Specialization? GetSpecialization(int id) + public Specialization? GetSpecialization(Guid id) { var specializationModel = _specializationRepository.GetSpecialization(id); return SpecializationConverter.SpecializationModelToSpecialization(specializationModel); } - public Specialization Update(int id, Dictionary data) + public Specialization Update(Guid id, Dictionary data) { SpecializationModel specializationToUpdate = _specializationRepository.GetSpecialization(id); @@ -53,7 +53,7 @@ public Specialization Update(int id, Dictionary data) return SpecializationConverter.SpecializationModelToSpecialization(specializationToUpdate); } - public bool Delete(int id) + public bool Delete(Guid id) { return _specializationRepository.Delete(new Specialization { Id = id }); } diff --git a/src/Application/DoctorsHelp.Application.Models/Specialization.cs b/src/Application/DoctorsHelp.Application.Models/Specialization.cs index 2c73aef..b80b46f 100644 --- a/src/Application/DoctorsHelp.Application.Models/Specialization.cs +++ b/src/Application/DoctorsHelp.Application.Models/Specialization.cs @@ -2,7 +2,7 @@ public class Specialization { - public int? Id { get; set; } + public Guid? Id { get; set; } public string? Name { get; set; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Extensions/ServiceCollectionExtensions.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Extensions/ServiceCollectionExtensions.cs index 71bb668..9a9e744 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Extensions/ServiceCollectionExtensions.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Extensions/ServiceCollectionExtensions.cs @@ -1,10 +1,7 @@ -using DoctorsHelp.Application.Abstractions.Persistence; -using DoctorsHelp.Infrastructure.Persistence.Contexts; -using DoctorsHelp.Infrastructure.Persistence.Migrations; -using DoctorsHelp.Infrastructure.Persistence.Plugins; -using Itmo.Dev.Platform.Postgres.Extensions; -using Itmo.Dev.Platform.Postgres.Plugins; -using Microsoft.EntityFrameworkCore; +// using DoctorsHelp.Infrastructure.Persistence.Contexts; +// using DoctorsHelp.Infrastructure.Persistence.Interfaces; +// using DoctorsHelp.Infrastructure.Persistence.Repositories; +// using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -12,24 +9,17 @@ namespace DoctorsHelp.Infrastructure.Persistence.Extensions; public static class ServiceCollectionExtensions { - public static IServiceCollection AddInfrastructurePersistence(this IServiceCollection collection) - { - collection.AddPlatformPostgres(builder => builder.BindConfiguration("Infrastructure:Persistence:Postgres")); - collection.AddSingleton(); - - collection.AddPlatformMigrations(typeof(IAssemblyMarker).Assembly); - collection.AddHostedService(); - - // TODO: add repositories - collection.AddScoped(); - - return collection; - } - public static IServiceCollection AddInfrastructurePersistence(this IServiceCollection collection, IConfiguration configuration) { - collection.AddDbContext(options => - options.UseNpgsql(configuration.GetSection("Infrastructure:Persistence:Postgres:ConnectionString").Value)); + // collection.AddDbContext(options => + // options.UseNpgsql(configuration.GetConnectionString("Infrastructure:Persistence:Postgres:ConnectionString"))); + // + // collection.AddScoped(); + // collection.AddScoped(); + // collection.AddScoped(); + // collection.AddScoped(); + // collection.AddScoped(); + // collection.AddScoped(); return collection; } } \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/ISpecializationRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/ISpecializationRepository.cs index 02c66ef..13b5818 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/ISpecializationRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/ISpecializationRepository.cs @@ -5,9 +5,9 @@ namespace DoctorsHelp.Infrastructure.Persistence.Interfaces; public interface ISpecializationRepository { - void Add(Specialization specialization); + void AddSpecialization(Specialization specialization); - SpecializationModel GetSpecialization(int id); + SpecializationModel GetSpecialization(Guid id); void UpdateSpecialization(Specialization specialization); diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs index 634d9fd..57e3f3a 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs @@ -6,7 +6,7 @@ public class EmployeeModel public Guid UserId { get; set; } - public int? SpecializationId { get; set; } + public Guid? SpecializationId { get; set; } public string? Graduate { get; set; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs index 277cb44..2e4d0de 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs @@ -2,7 +2,7 @@ namespace Infrastructure.Persistence.Models; public class SpecializationModel { - public int? Id { get; set; } + public Guid? Id { get; set; } public string? Name { get; set; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs index 532a45c..9de2038 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs @@ -17,7 +17,7 @@ public void UpdateSpecialization(Specialization specialization) Update(specialization); } - public SpecializationModel GetSpecialization(int id) + public SpecializationModel GetSpecialization(Guid id) { return GetEntry(new Specialization { Id = id }).Entity; } @@ -28,6 +28,11 @@ public bool Delete(Specialization specialization) return true; } + public void AddSpecialization(Specialization specialization) + { + Add(specialization); + } + protected override DbSet DbSet => ((ApplicationDbContext)Context).Specializations; protected override SpecializationModel MapFrom(Specialization entity) diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/SpecializationController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/SpecializationController.cs index bf36cd4..5d0d939 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/SpecializationController.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/SpecializationController.cs @@ -17,12 +17,12 @@ public SpecializationController(ISpecializationService specializationService) } [HttpGet("{id}")] - public ActionResult Get(int id) + public ActionResult Get(Guid id) { var specialization = _specializationService.GetSpecialization(id); if (specialization == null) { - return NotFound(); + return BadRequest("No specialization found with the given id."); } return Ok(specialization); @@ -48,7 +48,7 @@ public ActionResult Post([FromBody] SpecializationPost data) } [HttpPut("{id}")] - public ActionResult Update(int id, [FromBody] Dictionary data) + public ActionResult Update(Guid id, [FromBody] Dictionary data) { try { @@ -62,7 +62,7 @@ public ActionResult Update(int id, [FromBody] Dictionary Date: Thu, 11 Apr 2024 23:59:10 +0300 Subject: [PATCH 11/12] fixed all --- .../IAppointmentService.cs | 8 +- .../IEmployeeService.cs | 6 +- .../IReviewService.cs | 8 +- .../IScheduleService.cs | 8 +- .../ISpecializationService.cs | 2 +- .../IUserService.cs | 2 +- .../Services/AppointmentService.cs | 43 ++++-- .../Services/EmployeeService.cs | 33 +++-- .../Services/ReviewService.cs | 38 +++-- .../Services/ScheduleService.cs | 42 ++++-- .../Services/SpecializationService.cs | 20 ++- .../Services/UserService.cs | 26 ++-- .../Appointment.cs | 4 +- .../Employee.cs | 4 +- .../Intefaces/IEntity.cs | 6 + .../DoctorsHelp.Application.Models/Review.cs | 4 +- .../Schedule.cs | 4 +- .../Specialization.cs | 2 +- .../DoctorsHelp.Application.Models/User.cs | 2 +- src/DoctorsHelp/Program.cs | 15 -- src/DoctorsHelp/appsettings.Local.json | 8 +- src/DoctorsHelp/appsettings.json | 12 +- .../Contexts/ApplicationDbContext.cs | 2 +- .../Converters/AppointmentConverter.cs | 17 ++- .../Converters/EmployeeConverter.cs | 15 +- .../Converters/ScheduleConverter.cs | 2 +- .../Converters/SpecializationConverter.cs | 11 +- .../Converters/UserConverter.cs | 21 +-- .../Extensions/ServiceCollectionExtensions.cs | 26 ++-- .../Interfaces/IAppointmentRepository.cs | 4 +- .../Interfaces/IEmployeeRepository.cs | 4 +- .../Interfaces/IReviewRepository.cs | 4 +- .../Interfaces/IScheduleRepository.cs | 6 +- .../Interfaces/ISpecializationRepository.cs | 2 +- .../Interfaces/IUserRepository.cs | 2 +- ....cs => 20240411191337_Initial.Designer.cs} | 132 ++++++++++-------- ...3_Initial.cs => 20240411191337_Initial.cs} | 79 ++++++----- .../ApplicationDbContextModelSnapshot.cs | 130 +++++++++-------- .../Models/AppointmentModel.cs | 8 +- .../Models/EmployeeModel.cs | 6 +- .../Models/ReviewModel.cs | 8 +- .../Models/ScheduleModel.cs | 8 +- .../Models/SpecializationModel.cs | 4 +- .../Models/UserModel.cs | 4 +- .../Repositories/AppointmentRepository.cs | 13 +- .../Repositories/EmployeeRepository.cs | 9 +- .../Repositories/RepositoryBase.cs | 27 +++- .../Repositories/ReviewRepository.cs | 13 +- .../Repositories/ScheduleRepository.cs | 18 ++- .../Repositories/SpecializationRepository.cs | 5 +- .../Repositories/UserRepository.cs | 4 +- .../Controllers/AppointmentController.cs | 11 +- .../Controllers/EmployeeController.cs | 10 +- .../Controllers/ReviewController.cs | 10 +- .../Controllers/ScheduleController.cs | 10 +- .../Controllers/SpecializationController.cs | 6 +- .../Controllers/UserController.cs | 9 +- .../Requests/AppointmentPost.cs | 2 +- .../Requests/ReviewPost.cs | 2 +- .../Requests/SchedulePost.cs | 2 +- .../Responses/AppointmentPostResponse.cs | 6 + .../Responses/EmployeePostResponse.cs | 6 + .../Responses/ReviewPostResponse.cs | 6 + .../Responses/SchedulePostResponse.cs | 6 + .../Responses/SpecializationPostResponse.cs | 6 + .../Responses/UserPostResponse.cs | 6 + 66 files changed, 576 insertions(+), 403 deletions(-) create mode 100644 src/Application/DoctorsHelp.Application.Models/Intefaces/IEntity.cs rename src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/{20240316100013_Initial.Designer.cs => 20240411191337_Initial.Designer.cs} (53%) rename src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/{20240316100013_Initial.cs => 20240411191337_Initial.cs} (75%) create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Responses/AppointmentPostResponse.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Responses/EmployeePostResponse.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Responses/ReviewPostResponse.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Responses/SchedulePostResponse.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Responses/SpecializationPostResponse.cs create mode 100644 src/Presentation/DoctorsHelp.Presentation.Http/Responses/UserPostResponse.cs diff --git a/src/Application/DoctorsHelp.Application.Contracts/IAppointmentService.cs b/src/Application/DoctorsHelp.Application.Contracts/IAppointmentService.cs index 62dc2bd..2e2c83f 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IAppointmentService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IAppointmentService.cs @@ -4,11 +4,11 @@ namespace DoctorsHelp.Application.Contracts; public interface IAppointmentService { - Appointment Create(Guid patientId, int scheduleId); + Appointment Create(Guid patientId, Guid scheduleId); - Appointment? GetAppointment(int patientId); + Appointment? GetAppointment(Guid patientId); - Appointment Update(int id, Dictionary data); + Appointment? Update(Guid id, Dictionary data); - bool Delete(int id); + bool Delete(Guid id); } diff --git a/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs b/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs index 5ec82de..f05b4c5 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IEmployeeService.cs @@ -6,9 +6,9 @@ public interface IEmployeeService { Employee Create(Guid userId, Guid specializationId, string graduate, string experience); - Employee? GetEmployee(int employeeId); + Employee? GetEmployee(Guid employeeId); - Employee Update(int id, Dictionary data); + Employee? Update(Guid id, Dictionary data); - bool Delete(int id); + bool Delete(Guid id); } \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs b/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs index 3d64b36..9c298b9 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IReviewService.cs @@ -4,11 +4,11 @@ namespace DoctorsHelp.Application.Contracts; public interface IReviewService { - Review Create(int appointmentId, int? grade, string comment); + Review Create(Guid appointmentId, int? grade, string comment); - Review? GetReview(int reviewId); + Review? GetReview(Guid reviewId); - Review Update(int id, Dictionary data); + Review? Update(Guid id, Dictionary data); - bool Delete(int id); + bool Delete(Guid id); } \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs b/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs index 0a457cf..37253dc 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IScheduleService.cs @@ -4,11 +4,11 @@ namespace DoctorsHelp.Application.Contracts; public interface IScheduleService { - Schedule Create(int employeeId, DateTime? dateStart, DateTime? dateEnd); + Schedule Create(Guid employeeId, DateTime? dateStart, DateTime? dateEnd); - Schedule? GetSchedule(int scheduleId); + Schedule? GetSchedule(Guid scheduleId); - Schedule Update(int id, Dictionary data); + Schedule? Update(Guid id, Dictionary data); - bool Delete(int id); + bool Delete(Guid id); } \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/ISpecializationService.cs b/src/Application/DoctorsHelp.Application.Contracts/ISpecializationService.cs index 8a22e7e..04fc389 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/ISpecializationService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/ISpecializationService.cs @@ -8,7 +8,7 @@ public interface ISpecializationService Specialization? GetSpecialization(Guid id); - Specialization Update(Guid id, Dictionary data); + Specialization? Update(Guid id, Dictionary data); bool Delete(Guid id); } \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/IUserService.cs b/src/Application/DoctorsHelp.Application.Contracts/IUserService.cs index 8bee8be..8123b02 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/IUserService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/IUserService.cs @@ -8,7 +8,7 @@ public interface IUserService User? GetUser(Guid id); - User UpdateUser(Guid id, Dictionary data); + User? UpdateUser(Guid id, Dictionary data); bool DeleteUser(Guid id); } \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs index cdc664d..5789960 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs @@ -18,47 +18,55 @@ public AppointmentService(IAppointmentRepository appointmentRepository, IUserRep _scheduleRepository = scheduleRepository; } - public Appointment Create(Guid patientId, int scheduleId) + public Appointment Create(Guid patientId, Guid scheduleId) { - User patient = UserConverter.UserModelToUser(_patientRepository.GetUser(patientId)); - Schedule schedule = ScheduleConverter.ScheduleModelToSchedule(_scheduleRepository.GetSchedule(scheduleId)); + User? patient = UserConverter.UserModelToUser(_patientRepository.GetUser(patientId)); + Schedule? schedule = ScheduleConverter.ScheduleModelToSchedule(_scheduleRepository.GetSchedule(scheduleId)); + + if (patient is null) + throw new Exception("Patient doesnt exist"); + if (schedule is null) + throw new Exception("Schedule doesnt exist"); var appointment = new Appointment { - // Assuming Appointment has a constructor or properties for this + Id = Guid.NewGuid(), Patient = patient, Schedule = schedule, }; - _appointmentRepository.Add(appointment); + _appointmentRepository.AddAppointment(appointment); return appointment; } - public Appointment? GetAppointment(int patientId) + public Appointment? GetAppointment(Guid patientId) { var appointmentModel = _appointmentRepository.GetAppointment(patientId); return AppointmentConverter.AppointmentModelToAppointment(appointmentModel); } - public Appointment Update(int id, Dictionary data) + public Appointment? Update(Guid id, Dictionary data) { - AppointmentModel appointmentToUpdate = _appointmentRepository.GetAppointment(id); + AppointmentModel? appointmentToUpdate = _appointmentRepository.GetAppointment(id); + + if (appointmentToUpdate is null) + throw new Exception("No such appointment"); foreach (var entry in data) { switch (entry.Key) { - case "PatientId": + case "patientId": Guid patientId; if (Guid.TryParse(entry.Value, out patientId)) appointmentToUpdate.PatientId = patientId; break; - case "ScheduleId": - int scheduleId; - if (int.TryParse(entry.Value, out scheduleId)) + case "scheduleId": + Guid scheduleId; + if (Guid.TryParse(entry.Value, out scheduleId)) appointmentToUpdate.ScheduleId = scheduleId; break; - case "Status": + case "status": int status; if (int.TryParse(entry.Value, out status)) appointmentToUpdate.Status = status; @@ -66,10 +74,17 @@ public Appointment Update(int id, Dictionary data) } } + var appointment = AppointmentConverter.AppointmentModelToAppointment(appointmentToUpdate); + + if (appointment is null) + return null; + + _appointmentRepository.UpdateAppointment(appointment); + return AppointmentConverter.AppointmentModelToAppointment(appointmentToUpdate); } - public bool Delete(int id) + public bool Delete(Guid id) { return _appointmentRepository.Delete(new Appointment { Id = id, }); } diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs index 8eaa2cc..281a8e4 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs @@ -1,7 +1,6 @@ using DoctorsHelp.Application.Models; using DoctorsHelp.Infrastructure.Persistence.Converters; using DoctorsHelp.Infrastructure.Persistence.Interfaces; -using DoctorsHelp.Infrastructure.Persistence.Repositories; using Infrastructure.Persistence.Models; namespace DoctorsHelp.Application.Contracts.Services; @@ -12,7 +11,7 @@ public class EmployeeService : IEmployeeService private readonly IUserRepository _userRepository; private readonly ISpecializationRepository _specializationRepository; - public EmployeeService(EmployeeRepository appointmentRepository, UserRepository userRepository, SpecializationRepository specializationRepository) + public EmployeeService(IEmployeeRepository appointmentRepository, IUserRepository userRepository, ISpecializationRepository specializationRepository) { _employeeRepository = appointmentRepository; _userRepository = userRepository; @@ -21,30 +20,39 @@ public EmployeeService(EmployeeRepository appointmentRepository, UserRepository public Employee Create(Guid userId, Guid specializationId, string graduate, string experience) { - User user = UserConverter.UserModelToUser(_userRepository.GetUser(userId)); - Specialization specialization = SpecializationConverter.SpecializationModelToSpecialization(_specializationRepository.GetSpecialization(specializationId)); + User? user = UserConverter.UserModelToUser(_userRepository.GetUser(userId)); + Specialization? specialization = SpecializationConverter.SpecializationModelToSpecialization(_specializationRepository.GetSpecialization(specializationId)); + + if (user is null) + throw new Exception("user doesnt exist"); + if (specialization is null) + throw new Exception("specialization doesnt exist"); var employee = new Employee { + Id = Guid.NewGuid(), User = user, Specialization = specialization, Graduate = graduate, Experience = experience, }; - _employeeRepository.Add(employee); + _employeeRepository.AddEmployee(employee); return employee; } - public Employee? GetEmployee(int employeeId) + public Employee? GetEmployee(Guid employeeId) { var employeeModel = _employeeRepository.GetEmployee(employeeId); return EmployeeConverter.EmployeeModelToEmployee(employeeModel); } - public Employee Update(int id, Dictionary data) + public Employee? Update(Guid id, Dictionary data) { - EmployeeModel employeeToUpdate = _employeeRepository.GetEmployee(id); + EmployeeModel? employeeToUpdate = _employeeRepository.GetEmployee(id); + + if (employeeToUpdate is null) + throw new Exception("No such employee"); foreach (var entry in data) { @@ -69,10 +77,17 @@ public Employee Update(int id, Dictionary data) } } + var employee = EmployeeConverter.EmployeeModelToEmployee(employeeToUpdate); + + if (employee is null) + return null; + + _employeeRepository.UpdateEmployee(employee); + return EmployeeConverter.EmployeeModelToEmployee(employeeToUpdate); } - public bool Delete(int id) + public bool Delete(Guid id) { return _employeeRepository.Delete(new Employee { Id = id, }); } diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs index 6da3f73..a738754 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs @@ -1,7 +1,6 @@ using DoctorsHelp.Application.Models; using DoctorsHelp.Infrastructure.Persistence.Converters; using DoctorsHelp.Infrastructure.Persistence.Interfaces; -using DoctorsHelp.Infrastructure.Persistence.Repositories; using Infrastructure.Persistence.Models; namespace DoctorsHelp.Application.Contracts.Services; @@ -11,61 +10,72 @@ public class ReviewService : IReviewService private readonly IReviewRepository _reviewRepository; private readonly IAppointmentRepository _appointmentRepository; - public ReviewService(ReviewRepository reviewRepository, AppointmentRepository appointmentRepository) + public ReviewService(IReviewRepository reviewRepository, IAppointmentRepository appointmentRepository) { _reviewRepository = reviewRepository; _appointmentRepository = appointmentRepository; } - public Review Create(int appointmentId, int? grade, string comment) + public Review Create(Guid appointmentId, int? grade, string comment) { - Appointment appointment = AppointmentConverter.AppointmentModelToAppointment(_appointmentRepository.GetAppointment(appointmentId)); + Appointment? appointment = AppointmentConverter.AppointmentModelToAppointment(_appointmentRepository.GetAppointment(appointmentId)); + + if (appointment is null) + throw new Exception("appointment doesnt exist"); var review = new Review { + Id = Guid.NewGuid(), Appointment = appointment, Grade = grade, Comment = comment, }; - _reviewRepository.Add(review); + _reviewRepository.AddReview(review); return review; } - public Review? GetReview(int reviewId) + public Review? GetReview(Guid reviewId) { var reviewModel = _reviewRepository.GetReview(reviewId); return ReviewConverter.ReviewModelToReview(reviewModel); } - public Review Update(int id, Dictionary data) + public Review? Update(Guid id, Dictionary data) { - ReviewModel reviewToUpdate = _reviewRepository.GetReview(id); + ReviewModel? reviewToUpdate = _reviewRepository.GetReview(id); + + if (reviewToUpdate is null) + throw new Exception("No such review"); foreach (var entry in data) { switch (entry.Key) { - case "AppointmentId": - int appointmentId; - if (int.TryParse(entry.Value, out appointmentId)) + case "appointmentId": + Guid appointmentId; + if (Guid.TryParse(entry.Value, out appointmentId)) reviewToUpdate.AppointmentId = appointmentId; break; - case "Rating": + case "rating": int grade; if (int.TryParse(entry.Value, out grade)) reviewToUpdate.Grade = grade; break; - case "Comment": + case "comment": reviewToUpdate.Comment = entry.Value; break; } } + var review = ReviewConverter.ReviewModelToReview(reviewToUpdate); + + _reviewRepository.UpdateReview(review); + return ReviewConverter.ReviewModelToReview(reviewToUpdate); } - public bool Delete(int id) + public bool Delete(Guid id) { return _reviewRepository.Delete(new Review { Id = id }); } diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs index b3135ea..4f1aee6 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs @@ -1,7 +1,6 @@ using DoctorsHelp.Application.Models; using DoctorsHelp.Infrastructure.Persistence.Converters; using DoctorsHelp.Infrastructure.Persistence.Interfaces; -using DoctorsHelp.Infrastructure.Persistence.Repositories; using Infrastructure.Persistence.Models; namespace DoctorsHelp.Application.Contracts.Services; @@ -11,60 +10,73 @@ public class ScheduleService : IScheduleService private readonly IScheduleRepository _scheduleRepository; private readonly IEmployeeRepository _employeeRepository; - public ScheduleService(ScheduleRepository scheduleRepository, EmployeeRepository employeeRepository) + public ScheduleService(IScheduleRepository scheduleRepository, IEmployeeRepository employeeRepository) { _scheduleRepository = scheduleRepository; _employeeRepository = employeeRepository; } - public Schedule Create(int employeeId, DateTime? dateStart, DateTime? dateEnd) + public Schedule Create(Guid employeeId, DateTime? dateStart, DateTime? dateEnd) { - Employee employee = EmployeeConverter.EmployeeModelToEmployee(_employeeRepository.GetEmployee(employeeId)); + Employee? employee = EmployeeConverter.EmployeeModelToEmployee(_employeeRepository.GetEmployee(employeeId)); + + if (employee is null) + throw new Exception("employee doesnt exist"); var schedule = new Schedule { - // Assuming Appointment has a constructor or properties for this + Id = Guid.NewGuid(), Employee = employee, DateStart = dateStart, DateEnd = dateEnd, }; - _scheduleRepository.Add(schedule); + _scheduleRepository.AddSchedule(schedule); return schedule; } - public Schedule? GetSchedule(int scheduleId) + public Schedule? GetSchedule(Guid scheduleId) { var scheduleModel = _scheduleRepository.GetSchedule(scheduleId); return ScheduleConverter.ScheduleModelToSchedule(scheduleModel); } - public Schedule Update(int id, Dictionary data) + public Schedule? Update(Guid id, Dictionary data) { - ScheduleModel scheduleToUpdate = _scheduleRepository.GetSchedule(id); + ScheduleModel? scheduleToUpdate = _scheduleRepository.GetSchedule(id); + + if (scheduleToUpdate is null) + throw new Exception("No such schedule"); foreach (var entry in data) { switch (entry.Key) { - case "EmployeeId": - int employeeId; - if (int.TryParse(entry.Value, out employeeId)) + case "employeeId": + Guid employeeId; + if (Guid.TryParse(entry.Value, out employeeId)) scheduleToUpdate.EmployeeId = employeeId; break; - case "DateStart": + case "dateStart": scheduleToUpdate.DateStart = new DateTime(Convert.ToInt32(entry.Value)); break; - case "DateEnd": + case "dateEnd": scheduleToUpdate.DateEnd = new DateTime(Convert.ToInt32(entry.Value)); break; } } + var schedule = ScheduleConverter.ScheduleModelToSchedule(scheduleToUpdate); + + if (schedule is null) + return null; + + _scheduleRepository.UpdateSchedule(schedule); + return ScheduleConverter.ScheduleModelToSchedule(scheduleToUpdate); } - public bool Delete(int id) + public bool Delete(Guid id) { return _scheduleRepository.Delete(new Schedule { Id = id, }); } diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/SpecializationService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/SpecializationService.cs index 996d1d1..97d6eb8 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/SpecializationService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/SpecializationService.cs @@ -28,28 +28,38 @@ public Specialization Create(string name, string description) public Specialization? GetSpecialization(Guid id) { - var specializationModel = _specializationRepository.GetSpecialization(id); + SpecializationModel? specializationModel = _specializationRepository.GetSpecialization(id); return SpecializationConverter.SpecializationModelToSpecialization(specializationModel); } - public Specialization Update(Guid id, Dictionary data) + public Specialization? Update(Guid id, Dictionary data) { - SpecializationModel specializationToUpdate = _specializationRepository.GetSpecialization(id); + SpecializationModel? specializationToUpdate = _specializationRepository.GetSpecialization(id); + + if (specializationToUpdate is null) + throw new Exception("No such specialization"); foreach (var entry in data) { switch (entry.Key) { - case "Name": + case "name": specializationToUpdate.Name = entry.Value; break; - case "Description": + case "description": specializationToUpdate.Description = entry.Value; break; } } + var specialization = SpecializationConverter.SpecializationModelToSpecialization(specializationToUpdate); + + if (specialization is null) + return null; + + _specializationRepository.UpdateSpecialization(specialization); + return SpecializationConverter.SpecializationModelToSpecialization(specializationToUpdate); } diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/UserService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/UserService.cs index cd0fe69..885680f 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/UserService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/UserService.cs @@ -1,7 +1,6 @@ using DoctorsHelp.Application.Models; using DoctorsHelp.Infrastructure.Persistence.Converters; using DoctorsHelp.Infrastructure.Persistence.Interfaces; -using DoctorsHelp.Infrastructure.Persistence.Repositories; using Infrastructure.Persistence.Models; namespace DoctorsHelp.Application.Contracts.Services; @@ -10,7 +9,7 @@ public class UserService : IUserService { private readonly IUserRepository _userRepository; - public UserService(UserRepository userRepository) + public UserService(IUserRepository userRepository) { _userRepository = userRepository; } @@ -19,6 +18,7 @@ public User Register(string name, string surname, string phone, string email, st { var user = new User { + Id = Guid.NewGuid(), Name = name, Surname = surname, HashedPassword = password, @@ -37,29 +37,39 @@ public User Register(string name, string surname, string phone, string email, st return UserConverter.UserModelToUser(userModel); } - public User UpdateUser(Guid id, Dictionary data) + public User? UpdateUser(Guid id, Dictionary data) { - UserModel userToUpdate = _userRepository.GetUser(id); + UserModel? userToUpdate = _userRepository.GetUser(id); + + if (userToUpdate is null) + throw new Exception("No such user"); foreach (var entry in data) { switch (entry.Key) { - case "Name": + case "name": userToUpdate.Name = entry.Value; break; - case "Surname": + case "surname": userToUpdate.Surname = entry.Value; break; - case "Phone": + case "phone": userToUpdate.Phone = entry.Value; break; - case "Email": + case "email": userToUpdate.Email = entry.Value; break; } } + var user = UserConverter.UserModelToUser(userToUpdate); + + if (user is null) + return null; + + _userRepository.UpdateUser(user); + return UserConverter.UserModelToUser(userToUpdate); } diff --git a/src/Application/DoctorsHelp.Application.Models/Appointment.cs b/src/Application/DoctorsHelp.Application.Models/Appointment.cs index b8acd80..b43508d 100644 --- a/src/Application/DoctorsHelp.Application.Models/Appointment.cs +++ b/src/Application/DoctorsHelp.Application.Models/Appointment.cs @@ -1,8 +1,8 @@ namespace DoctorsHelp.Application.Models; -public class Appointment +public class Appointment : IEntity { - public int? Id { get; set; } + public Guid? Id { get; set; } public User? Patient { get; set; } diff --git a/src/Application/DoctorsHelp.Application.Models/Employee.cs b/src/Application/DoctorsHelp.Application.Models/Employee.cs index a8219db..7a14f36 100644 --- a/src/Application/DoctorsHelp.Application.Models/Employee.cs +++ b/src/Application/DoctorsHelp.Application.Models/Employee.cs @@ -1,8 +1,8 @@ namespace DoctorsHelp.Application.Models; -public class Employee +public class Employee : IEntity { - public int? Id { get; set; } + public Guid? Id { get; set; } public User? User { get; set; } diff --git a/src/Application/DoctorsHelp.Application.Models/Intefaces/IEntity.cs b/src/Application/DoctorsHelp.Application.Models/Intefaces/IEntity.cs new file mode 100644 index 0000000..ec68373 --- /dev/null +++ b/src/Application/DoctorsHelp.Application.Models/Intefaces/IEntity.cs @@ -0,0 +1,6 @@ +namespace DoctorsHelp.Application.Models; + +public interface IEntity +{ + public Guid? Id { get; } +} \ No newline at end of file diff --git a/src/Application/DoctorsHelp.Application.Models/Review.cs b/src/Application/DoctorsHelp.Application.Models/Review.cs index 57987e6..7b6e005 100644 --- a/src/Application/DoctorsHelp.Application.Models/Review.cs +++ b/src/Application/DoctorsHelp.Application.Models/Review.cs @@ -1,8 +1,8 @@ namespace DoctorsHelp.Application.Models; -public class Review +public class Review : IEntity { - public int? Id { get; set; } + public Guid? Id { get; set; } public Appointment? Appointment { get; set; } diff --git a/src/Application/DoctorsHelp.Application.Models/Schedule.cs b/src/Application/DoctorsHelp.Application.Models/Schedule.cs index 6fa2aaa..00bd13c 100644 --- a/src/Application/DoctorsHelp.Application.Models/Schedule.cs +++ b/src/Application/DoctorsHelp.Application.Models/Schedule.cs @@ -1,8 +1,8 @@ namespace DoctorsHelp.Application.Models; -public class Schedule +public class Schedule : IEntity { - public int? Id { get; set; } + public Guid? Id { get; set; } public Employee? Employee { get; set; } diff --git a/src/Application/DoctorsHelp.Application.Models/Specialization.cs b/src/Application/DoctorsHelp.Application.Models/Specialization.cs index b80b46f..e61d7ba 100644 --- a/src/Application/DoctorsHelp.Application.Models/Specialization.cs +++ b/src/Application/DoctorsHelp.Application.Models/Specialization.cs @@ -1,6 +1,6 @@ namespace DoctorsHelp.Application.Models; -public class Specialization +public class Specialization : IEntity { public Guid? Id { get; set; } diff --git a/src/Application/DoctorsHelp.Application.Models/User.cs b/src/Application/DoctorsHelp.Application.Models/User.cs index 127ce12..b93a5ed 100644 --- a/src/Application/DoctorsHelp.Application.Models/User.cs +++ b/src/Application/DoctorsHelp.Application.Models/User.cs @@ -1,6 +1,6 @@ namespace DoctorsHelp.Application.Models; -public class User +public class User : IEntity { public Guid? Id { get; set; } diff --git a/src/DoctorsHelp/Program.cs b/src/DoctorsHelp/Program.cs index 4ecdae1..9af0284 100644 --- a/src/DoctorsHelp/Program.cs +++ b/src/DoctorsHelp/Program.cs @@ -3,14 +3,10 @@ using DoctorsHelp.Application.Extensions; using DoctorsHelp.Infrastructure.Persistence.Extensions; using DoctorsHelp.Presentation.Http.Extensions; -using DoctorsHelp.Util; using Itmo.Dev.Platform.Common.Extensions; using Itmo.Dev.Platform.Logging.Extensions; using Microsoft.Extensions.Options; using Newtonsoft.Json; -using Testcontainers.PostgreSql; - -const Profiles currentProfile = Profiles.Local; WebApplicationBuilder builder = WebApplication.CreateBuilder(args); @@ -21,17 +17,6 @@ builder.Services.AddApplication(); -if (currentProfile.Equals(Profiles.Local)) -{ - var postgres = new PostgreSqlBuilder() - .WithImage("postgres:15-alpine") - .Build(); - - await postgres.StartAsync(); - - builder.Configuration["Infrastructure:Persistence:Postgres:ConnectionString"] = postgres.GetConnectionString(); -} - builder.Services.AddInfrastructurePersistence(builder.Configuration); builder.Services .AddControllers() diff --git a/src/DoctorsHelp/appsettings.Local.json b/src/DoctorsHelp/appsettings.Local.json index d4175a0..9d3ce72 100644 --- a/src/DoctorsHelp/appsettings.Local.json +++ b/src/DoctorsHelp/appsettings.Local.json @@ -2,13 +2,7 @@ "Infrastructure": { "Persistence": { "Postgres": { - "Host": "localhost", - "Port": 6432, - "Database": "postgres", - "Username": "postgres", - "Password": "postgres", - "SslMode": "Prefer", - "Pooling": true + "ConnectionString": "Host=rc1b-i7lu7rt5vmg38nh0.mdb.yandexcloud.net;Port=6432;Database=oop;Username=g1phy;Password=fPr-KsP-h9W-q48;" } } }, diff --git a/src/DoctorsHelp/appsettings.json b/src/DoctorsHelp/appsettings.json index cd55282..181682c 100644 --- a/src/DoctorsHelp/appsettings.json +++ b/src/DoctorsHelp/appsettings.json @@ -3,20 +3,14 @@ "Infrastructure": { "Persistence": { "Postgres": { - "Host": "", - "Port": -1, - "Database": "", - "Username": "", - "Password": "", - "SslMode": "Prefer", - "Pooling": true + "ConnectionString": "Host=rc1b-i7lu7rt5vmg38nh0.mdb.yandexcloud.net;Port=6432;Database=oop;Username=g1phy;Password=fPr-KsP-h9W-q48;" } - }, + } }, "Presentation": { }, "Platform": { - "Environment": "", + "Environment": "" }, "Sentry": { "Enabled": true, diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Contexts/ApplicationDbContext.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Contexts/ApplicationDbContext.cs index e52df6c..1a7e9a8 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Contexts/ApplicationDbContext.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Contexts/ApplicationDbContext.cs @@ -25,6 +25,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.ApplyConfigurationsFromAssembly(typeof(ApplicationDbContext).Assembly); - base.OnModelCreating(modelBuilder); + // base.OnModelCreating(modelBuilder); } } \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/AppointmentConverter.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/AppointmentConverter.cs index a7f2cc1..07970ac 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/AppointmentConverter.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/AppointmentConverter.cs @@ -5,16 +5,19 @@ namespace DoctorsHelp.Infrastructure.Persistence.Converters; public class AppointmentConverter { - public static Appointment AppointmentModelToAppointment(AppointmentModel? appointmentModel) + public static Appointment? AppointmentModelToAppointment(AppointmentModel? appointmentModel) { + if (appointmentModel is null) + return null; + return new Appointment { - Id = appointmentModel?.Id, - Patient = UserConverter.UserModelToUser(appointmentModel?.Patient), - Schedule = ScheduleConverter.ScheduleModelToSchedule(appointmentModel?.Schedule), - CreatedAt = appointmentModel?.CreatedAt, - UpdatedAt = appointmentModel?.UpdatedAt, - Status = appointmentModel?.Status, + Id = appointmentModel.Id, + Patient = UserConverter.UserModelToUser(appointmentModel.Patient), + Schedule = ScheduleConverter.ScheduleModelToSchedule(appointmentModel.Schedule), + CreatedAt = appointmentModel.CreatedAt, + UpdatedAt = appointmentModel.UpdatedAt, + Status = appointmentModel.Status, }; } } \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/EmployeeConverter.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/EmployeeConverter.cs index 6821fc3..a5340c1 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/EmployeeConverter.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/EmployeeConverter.cs @@ -5,15 +5,18 @@ namespace DoctorsHelp.Infrastructure.Persistence.Converters; public class EmployeeConverter { - public static Employee EmployeeModelToEmployee(EmployeeModel? employeeModel) + public static Employee? EmployeeModelToEmployee(EmployeeModel? employeeModel) { + if (employeeModel is null) + return null; + return new Employee { - Id = employeeModel?.Id, - User = UserConverter.UserModelToUser(employeeModel?.User), - Specialization = SpecializationConverter.SpecializationModelToSpecialization(employeeModel?.Specialization), - Graduate = employeeModel?.Graduate, - Experience = employeeModel?.Experience, + Id = employeeModel.Id, + User = UserConverter.UserModelToUser(employeeModel.User), + Specialization = SpecializationConverter.SpecializationModelToSpecialization(employeeModel.Specialization), + Graduate = employeeModel.Graduate, + Experience = employeeModel.Experience, }; } } \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/ScheduleConverter.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/ScheduleConverter.cs index eda27ad..791f904 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/ScheduleConverter.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/ScheduleConverter.cs @@ -5,7 +5,7 @@ namespace DoctorsHelp.Infrastructure.Persistence.Converters; public class ScheduleConverter { - public static Schedule ScheduleModelToSchedule(ScheduleModel? scheduleModel) + public static Schedule? ScheduleModelToSchedule(ScheduleModel? scheduleModel) { return new Schedule { diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/SpecializationConverter.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/SpecializationConverter.cs index d17a6ba..13602d2 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/SpecializationConverter.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/SpecializationConverter.cs @@ -5,13 +5,16 @@ namespace DoctorsHelp.Infrastructure.Persistence.Converters; public class SpecializationConverter { - public static Specialization SpecializationModelToSpecialization(SpecializationModel? specializationModel) + public static Specialization? SpecializationModelToSpecialization(SpecializationModel? specializationModel) { + if (specializationModel is null) + return null; + return new Specialization { - Id = specializationModel?.Id, - Name = specializationModel?.Name, - Description = specializationModel?.Description, + Id = specializationModel.Id, + Name = specializationModel.Name, + Description = specializationModel.Description, }; } } \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/UserConverter.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/UserConverter.cs index 98b4a57..9b13393 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/UserConverter.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Converters/UserConverter.cs @@ -5,18 +5,21 @@ namespace DoctorsHelp.Infrastructure.Persistence.Converters; public class UserConverter { - public static User UserModelToUser(UserModel? userModel) + public static User? UserModelToUser(UserModel? userModel) { + if (userModel is null) + return null; + return new User { - Id = userModel?.Id, - Name = userModel?.Name, - Surname = userModel?.Surname, - Phone = userModel?.Phone, - Email = userModel?.Email, - HashedPassword = userModel?.HashedPassword, - Birthdate = userModel?.Birthdate, - Role = userModel?.Role, + Id = userModel.Id, + Name = userModel.Name, + Surname = userModel.Surname, + Phone = userModel.Phone, + Email = userModel.Email, + HashedPassword = userModel.HashedPassword, + Birthdate = userModel.Birthdate, + Role = userModel.Role, }; } } \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Extensions/ServiceCollectionExtensions.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Extensions/ServiceCollectionExtensions.cs index 9a9e744..af5a45b 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Extensions/ServiceCollectionExtensions.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Extensions/ServiceCollectionExtensions.cs @@ -1,7 +1,7 @@ -// using DoctorsHelp.Infrastructure.Persistence.Contexts; -// using DoctorsHelp.Infrastructure.Persistence.Interfaces; -// using DoctorsHelp.Infrastructure.Persistence.Repositories; -// using Microsoft.EntityFrameworkCore; +using DoctorsHelp.Infrastructure.Persistence.Contexts; +using DoctorsHelp.Infrastructure.Persistence.Interfaces; +using DoctorsHelp.Infrastructure.Persistence.Repositories; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -11,15 +11,15 @@ public static class ServiceCollectionExtensions { public static IServiceCollection AddInfrastructurePersistence(this IServiceCollection collection, IConfiguration configuration) { - // collection.AddDbContext(options => - // options.UseNpgsql(configuration.GetConnectionString("Infrastructure:Persistence:Postgres:ConnectionString"))); - // - // collection.AddScoped(); - // collection.AddScoped(); - // collection.AddScoped(); - // collection.AddScoped(); - // collection.AddScoped(); - // collection.AddScoped(); + collection.AddDbContext(options => + options.UseNpgsql(configuration.GetSection("Infrastructure:Persistence:Postgres:ConnectionString").Value)); + + collection.AddScoped(); + collection.AddScoped(); + collection.AddScoped(); + collection.AddScoped(); + collection.AddScoped(); + collection.AddScoped(); return collection; } } \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IAppointmentRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IAppointmentRepository.cs index 0d999cb..8982c42 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IAppointmentRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IAppointmentRepository.cs @@ -5,9 +5,9 @@ namespace DoctorsHelp.Infrastructure.Persistence.Interfaces; public interface IAppointmentRepository { - void Add(Appointment appointment); + void AddAppointment(Appointment appointment); - AppointmentModel GetAppointment(int id); + AppointmentModel? GetAppointment(Guid id); void UpdateAppointment(Appointment appointment); diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IEmployeeRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IEmployeeRepository.cs index c066bbc..59ff70f 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IEmployeeRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IEmployeeRepository.cs @@ -5,9 +5,9 @@ namespace DoctorsHelp.Infrastructure.Persistence.Interfaces; public interface IEmployeeRepository { - void Add(Employee employee); + void AddEmployee(Employee employee); - EmployeeModel GetEmployee(int id); + EmployeeModel? GetEmployee(Guid id); void UpdateEmployee(Employee employee); diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IReviewRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IReviewRepository.cs index 8314493..1310db0 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IReviewRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IReviewRepository.cs @@ -5,9 +5,9 @@ namespace DoctorsHelp.Infrastructure.Persistence.Interfaces; public interface IReviewRepository { - void Add(Review review); + void AddReview(Review review); - ReviewModel GetReview(int id); + ReviewModel? GetReview(Guid id); void UpdateReview(Review review); diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IScheduleRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IScheduleRepository.cs index 1e6da01..f8f51a5 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IScheduleRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IScheduleRepository.cs @@ -5,11 +5,11 @@ namespace DoctorsHelp.Infrastructure.Persistence.Interfaces; public interface IScheduleRepository { - void Add(Schedule schedule); + void AddSchedule(Schedule schedule); - ScheduleModel GetSchedule(int id); + ScheduleModel? GetSchedule(Guid id); - void Update(Schedule schedule); + void UpdateSchedule(Schedule schedule); bool Delete(Schedule schedule); } \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/ISpecializationRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/ISpecializationRepository.cs index 13b5818..e8ee539 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/ISpecializationRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/ISpecializationRepository.cs @@ -7,7 +7,7 @@ public interface ISpecializationRepository { void AddSpecialization(Specialization specialization); - SpecializationModel GetSpecialization(Guid id); + SpecializationModel? GetSpecialization(Guid id); void UpdateSpecialization(Specialization specialization); diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IUserRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IUserRepository.cs index 8921927..106c1c4 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IUserRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Interfaces/IUserRepository.cs @@ -7,7 +7,7 @@ public interface IUserRepository { void Add(User user); - UserModel GetUser(Guid id); + UserModel? GetUser(Guid id); void UpdateUser(User user); diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.Designer.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240411191337_Initial.Designer.cs similarity index 53% rename from src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.Designer.cs rename to src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240411191337_Initial.Designer.cs index 24a26aa..d6d67d1 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.Designer.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240411191337_Initial.Designer.cs @@ -12,7 +12,7 @@ namespace DoctorsHelp.Infrastructure.Persistence.Migrations { [DbContext(typeof(ApplicationDbContext))] - [Migration("20240316100013_Initial")] + [Migration("20240411191337_Initial")] partial class Initial { /// @@ -25,27 +25,25 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("DoctorsHelp.Application.Models.Appointment", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.AppointmentModel", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + .HasColumnType("uuid"); - b.Property("CreatedAt") + b.Property("CreatedAt") .HasColumnType("timestamp with time zone"); - b.Property("PatientId") + b.Property("PatientId") .HasColumnType("uuid"); - b.Property("ScheduleId") - .HasColumnType("integer"); + b.Property("ScheduleId") + .HasColumnType("uuid"); - b.Property("Status") + b.Property("Status") .HasColumnType("integer"); - b.Property("UpdatedAt") + b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); b.HasKey("Id"); @@ -57,13 +55,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("Appointments"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Employee", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.EmployeeModel", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + .HasColumnType("uuid"); b.Property("Experience") .HasColumnType("text"); @@ -71,40 +67,40 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.Property("Graduate") .HasColumnType("text"); - b.Property("Specialization") - .HasColumnType("integer"); + b.Property("SpecializationId") + .HasColumnType("uuid"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("uuid"); b.HasKey("Id"); + b.HasIndex("SpecializationId"); + b.HasIndex("UserId"); b.ToTable("Employees"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Review", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.ReviewModel", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + .HasColumnType("uuid"); - b.Property("AppointmentId") - .HasColumnType("integer"); + b.Property("AppointmentId") + .HasColumnType("uuid"); b.Property("Comment") .HasColumnType("text"); - b.Property("CreatedAt") + b.Property("CreatedAt") .HasColumnType("timestamp with time zone"); - b.Property("Grade") + b.Property("Grade") .HasColumnType("integer"); - b.Property("UpdatedAt") + b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); b.HasKey("Id"); @@ -114,24 +110,22 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("Reviews"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Schedule", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.ScheduleModel", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + .HasColumnType("uuid"); - b.Property("DateEnd") + b.Property("DateEnd") .HasColumnType("timestamp with time zone"); - b.Property("DateStart") + b.Property("DateStart") .HasColumnType("timestamp with time zone"); - b.Property("EmployeeId") - .HasColumnType("integer"); + b.Property("EmployeeId") + .HasColumnType("uuid"); - b.Property("Status") + b.Property("Status") .HasColumnType("integer"); b.HasKey("Id"); @@ -141,13 +135,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("Schedules"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Specialization", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.SpecializationModel", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + .HasColumnType("uuid"); b.Property("Description") .HasColumnType("text"); @@ -160,13 +152,13 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("Specializations"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.User", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.UserModel", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("uuid"); - b.Property("Birthdate") + b.Property("Birthdate") .HasColumnType("date"); b.Property("Email") @@ -192,44 +184,60 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder) b.ToTable("Users"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Appointment", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.AppointmentModel", b => { - b.HasOne("DoctorsHelp.Application.Models.User", "Patient") + b.HasOne("Infrastructure.Persistence.Models.UserModel", "Patient") .WithMany() - .HasForeignKey("PatientId"); + .HasForeignKey("PatientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); - b.HasOne("DoctorsHelp.Application.Models.Schedule", "Schedule") + b.HasOne("Infrastructure.Persistence.Models.ScheduleModel", "Schedule") .WithMany() - .HasForeignKey("ScheduleId"); + .HasForeignKey("ScheduleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("Patient"); b.Navigation("Schedule"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Employee", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.EmployeeModel", b => { - b.HasOne("DoctorsHelp.Application.Models.User", "User") + b.HasOne("Infrastructure.Persistence.Models.SpecializationModel", "Specialization") .WithMany() - .HasForeignKey("UserId"); + .HasForeignKey("SpecializationId"); + + b.HasOne("Infrastructure.Persistence.Models.UserModel", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Specialization"); b.Navigation("User"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Review", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.ReviewModel", b => { - b.HasOne("DoctorsHelp.Application.Models.Appointment", "Appointment") + b.HasOne("Infrastructure.Persistence.Models.AppointmentModel", "Appointment") .WithMany() - .HasForeignKey("AppointmentId"); + .HasForeignKey("AppointmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("Appointment"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Schedule", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.ScheduleModel", b => { - b.HasOne("DoctorsHelp.Application.Models.Employee", "Employee") + b.HasOne("Infrastructure.Persistence.Models.EmployeeModel", "Employee") .WithMany() - .HasForeignKey("EmployeeId"); + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("Employee"); }); diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240411191337_Initial.cs similarity index 75% rename from src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.cs rename to src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240411191337_Initial.cs index 2013210..82fbad7 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240316100013_Initial.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/20240411191337_Initial.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable @@ -15,8 +14,7 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Specializations", columns: table => new { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + Id = table.Column(type: "uuid", nullable: false), Name = table.Column(type: "text", nullable: true), Description = table.Column(type: "text", nullable: true), }, @@ -35,7 +33,7 @@ protected override void Up(MigrationBuilder migrationBuilder) Phone = table.Column(type: "text", nullable: true), Email = table.Column(type: "text", nullable: true), HashedPassword = table.Column(type: "text", nullable: true), - Birthdate = table.Column(type: "date", nullable: false), + Birthdate = table.Column(type: "date", nullable: true), Role = table.Column(type: "text", nullable: true), }, constraints: table => @@ -47,33 +45,37 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "Employees", columns: table => new { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - UserId = table.Column(type: "uuid", nullable: true), - Specialization = table.Column(type: "integer", nullable: false), + Id = table.Column(type: "uuid", nullable: false), + UserId = table.Column(type: "uuid", nullable: false), + SpecializationId = table.Column(type: "uuid", nullable: true), Graduate = table.Column(type: "text", nullable: true), Experience = table.Column(type: "text", nullable: true), }, constraints: table => { table.PrimaryKey("PK_Employees", x => x.Id); + table.ForeignKey( + name: "FK_Employees_Specializations_SpecializationId", + column: x => x.SpecializationId, + principalTable: "Specializations", + principalColumn: "Id"); table.ForeignKey( name: "FK_Employees_Users_UserId", column: x => x.UserId, principalTable: "Users", - principalColumn: "Id"); + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Schedules", columns: table => new { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - EmployeeId = table.Column(type: "integer", nullable: true), - DateStart = table.Column(type: "timestamp with time zone", nullable: false), - DateEnd = table.Column(type: "timestamp with time zone", nullable: false), - Status = table.Column(type: "integer", nullable: false), + Id = table.Column(type: "uuid", nullable: false), + EmployeeId = table.Column(type: "uuid", nullable: false), + DateStart = table.Column(type: "timestamp with time zone", nullable: true), + DateEnd = table.Column(type: "timestamp with time zone", nullable: true), + Status = table.Column(type: "integer", nullable: true), }, constraints: table => { @@ -82,20 +84,20 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "FK_Schedules_Employees_EmployeeId", column: x => x.EmployeeId, principalTable: "Employees", - principalColumn: "Id"); + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Appointments", columns: table => new { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - PatientId = table.Column(type: "uuid", nullable: true), - ScheduleId = table.Column(type: "integer", nullable: true), - CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), - UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), - Status = table.Column(type: "integer", nullable: false), + Id = table.Column(type: "uuid", nullable: false), + PatientId = table.Column(type: "uuid", nullable: false), + ScheduleId = table.Column(type: "uuid", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: true), + UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), + Status = table.Column(type: "integer", nullable: true), }, constraints: table => { @@ -104,25 +106,26 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "FK_Appointments_Schedules_ScheduleId", column: x => x.ScheduleId, principalTable: "Schedules", - principalColumn: "Id"); + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); table.ForeignKey( name: "FK_Appointments_Users_PatientId", column: x => x.PatientId, principalTable: "Users", - principalColumn: "Id"); + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( name: "Reviews", columns: table => new { - Id = table.Column(type: "integer", nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), - AppointmentId = table.Column(type: "integer", nullable: true), - Grade = table.Column(type: "integer", nullable: false), + Id = table.Column(type: "uuid", nullable: false), + AppointmentId = table.Column(type: "uuid", nullable: false), + Grade = table.Column(type: "integer", nullable: true), Comment = table.Column(type: "text", nullable: true), - CreatedAt = table.Column(type: "timestamp with time zone", nullable: false), - UpdatedAt = table.Column(type: "timestamp with time zone", nullable: false), + CreatedAt = table.Column(type: "timestamp with time zone", nullable: true), + UpdatedAt = table.Column(type: "timestamp with time zone", nullable: true), }, constraints: table => { @@ -131,7 +134,8 @@ protected override void Up(MigrationBuilder migrationBuilder) name: "FK_Reviews_Appointments_AppointmentId", column: x => x.AppointmentId, principalTable: "Appointments", - principalColumn: "Id"); + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( @@ -144,6 +148,11 @@ protected override void Up(MigrationBuilder migrationBuilder) table: "Appointments", column: "ScheduleId"); + migrationBuilder.CreateIndex( + name: "IX_Employees_SpecializationId", + table: "Employees", + column: "SpecializationId"); + migrationBuilder.CreateIndex( name: "IX_Employees_UserId", table: "Employees", @@ -166,9 +175,6 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "Reviews"); - migrationBuilder.DropTable( - name: "Specializations"); - migrationBuilder.DropTable( name: "Appointments"); @@ -178,6 +184,9 @@ protected override void Down(MigrationBuilder migrationBuilder) migrationBuilder.DropTable( name: "Employees"); + migrationBuilder.DropTable( + name: "Specializations"); + migrationBuilder.DropTable( name: "Users"); } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs index 93cea9d..4427002 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Migrations/ApplicationDbContextModelSnapshot.cs @@ -22,27 +22,25 @@ protected override void BuildModel(ModelBuilder modelBuilder) NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); - modelBuilder.Entity("DoctorsHelp.Application.Models.Appointment", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.AppointmentModel", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + .HasColumnType("uuid"); - b.Property("CreatedAt") + b.Property("CreatedAt") .HasColumnType("timestamp with time zone"); - b.Property("PatientId") + b.Property("PatientId") .HasColumnType("uuid"); - b.Property("ScheduleId") - .HasColumnType("integer"); + b.Property("ScheduleId") + .HasColumnType("uuid"); - b.Property("Status") + b.Property("Status") .HasColumnType("integer"); - b.Property("UpdatedAt") + b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); b.HasKey("Id"); @@ -54,13 +52,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Appointments"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Employee", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.EmployeeModel", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + .HasColumnType("uuid"); b.Property("Experience") .HasColumnType("text"); @@ -68,40 +64,40 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Property("Graduate") .HasColumnType("text"); - b.Property("Specialization") - .HasColumnType("integer"); + b.Property("SpecializationId") + .HasColumnType("uuid"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("uuid"); b.HasKey("Id"); + b.HasIndex("SpecializationId"); + b.HasIndex("UserId"); b.ToTable("Employees"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Review", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.ReviewModel", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + .HasColumnType("uuid"); - b.Property("AppointmentId") - .HasColumnType("integer"); + b.Property("AppointmentId") + .HasColumnType("uuid"); b.Property("Comment") .HasColumnType("text"); - b.Property("CreatedAt") + b.Property("CreatedAt") .HasColumnType("timestamp with time zone"); - b.Property("Grade") + b.Property("Grade") .HasColumnType("integer"); - b.Property("UpdatedAt") + b.Property("UpdatedAt") .HasColumnType("timestamp with time zone"); b.HasKey("Id"); @@ -111,24 +107,22 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Reviews"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Schedule", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.ScheduleModel", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + .HasColumnType("uuid"); - b.Property("DateEnd") + b.Property("DateEnd") .HasColumnType("timestamp with time zone"); - b.Property("DateStart") + b.Property("DateStart") .HasColumnType("timestamp with time zone"); - b.Property("EmployeeId") - .HasColumnType("integer"); + b.Property("EmployeeId") + .HasColumnType("uuid"); - b.Property("Status") + b.Property("Status") .HasColumnType("integer"); b.HasKey("Id"); @@ -138,13 +132,11 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Schedules"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Specialization", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.SpecializationModel", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("integer"); - - NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + .HasColumnType("uuid"); b.Property("Description") .HasColumnType("text"); @@ -157,13 +149,13 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Specializations"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.User", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.UserModel", b => { - b.Property("Id") + b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("uuid"); - b.Property("Birthdate") + b.Property("Birthdate") .HasColumnType("date"); b.Property("Email") @@ -189,44 +181,60 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("Users"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Appointment", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.AppointmentModel", b => { - b.HasOne("DoctorsHelp.Application.Models.User", "Patient") + b.HasOne("Infrastructure.Persistence.Models.UserModel", "Patient") .WithMany() - .HasForeignKey("PatientId"); + .HasForeignKey("PatientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); - b.HasOne("DoctorsHelp.Application.Models.Schedule", "Schedule") + b.HasOne("Infrastructure.Persistence.Models.ScheduleModel", "Schedule") .WithMany() - .HasForeignKey("ScheduleId"); + .HasForeignKey("ScheduleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("Patient"); b.Navigation("Schedule"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Employee", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.EmployeeModel", b => { - b.HasOne("DoctorsHelp.Application.Models.User", "User") + b.HasOne("Infrastructure.Persistence.Models.SpecializationModel", "Specialization") .WithMany() - .HasForeignKey("UserId"); + .HasForeignKey("SpecializationId"); + + b.HasOne("Infrastructure.Persistence.Models.UserModel", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Specialization"); b.Navigation("User"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Review", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.ReviewModel", b => { - b.HasOne("DoctorsHelp.Application.Models.Appointment", "Appointment") + b.HasOne("Infrastructure.Persistence.Models.AppointmentModel", "Appointment") .WithMany() - .HasForeignKey("AppointmentId"); + .HasForeignKey("AppointmentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("Appointment"); }); - modelBuilder.Entity("DoctorsHelp.Application.Models.Schedule", b => + modelBuilder.Entity("Infrastructure.Persistence.Models.ScheduleModel", b => { - b.HasOne("DoctorsHelp.Application.Models.Employee", "Employee") + b.HasOne("Infrastructure.Persistence.Models.EmployeeModel", "Employee") .WithMany() - .HasForeignKey("EmployeeId"); + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("Employee"); }); diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/AppointmentModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/AppointmentModel.cs index cda19da..faf9d11 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/AppointmentModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/AppointmentModel.cs @@ -1,12 +1,14 @@ +using DoctorsHelp.Application.Models; + namespace Infrastructure.Persistence.Models; -public class AppointmentModel +public class AppointmentModel : IEntity { - public int? Id { get; set; } + public Guid? Id { get; set; } public Guid PatientId { get; set; } - public int ScheduleId { get; set; } + public Guid ScheduleId { get; set; } public DateTime? CreatedAt { get; set; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs index 57e3f3a..266a7a7 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs @@ -1,8 +1,10 @@ +using DoctorsHelp.Application.Models; + namespace Infrastructure.Persistence.Models; -public class EmployeeModel +public class EmployeeModel : IEntity { - public int? Id { get; set; } + public Guid? Id { get; set; } public Guid UserId { get; set; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ReviewModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ReviewModel.cs index 08f3dfc..aee4dcb 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ReviewModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ReviewModel.cs @@ -1,10 +1,12 @@ +using DoctorsHelp.Application.Models; + namespace Infrastructure.Persistence.Models; -public class ReviewModel +public class ReviewModel : IEntity { - public int? Id { get; set; } + public Guid? Id { get; set; } - public int AppointmentId { get; set; } + public Guid AppointmentId { get; set; } public int? Grade { get; set; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ScheduleModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ScheduleModel.cs index 5a432c3..3408b18 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ScheduleModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/ScheduleModel.cs @@ -1,10 +1,12 @@ +using DoctorsHelp.Application.Models; + namespace Infrastructure.Persistence.Models; -public class ScheduleModel +public class ScheduleModel : IEntity { - public int? Id { get; set; } + public Guid? Id { get; set; } - public int EmployeeId { get; set; } + public Guid EmployeeId { get; set; } public DateTime? DateStart { get; set; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs index 2e4d0de..c488c97 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/SpecializationModel.cs @@ -1,6 +1,8 @@ +using DoctorsHelp.Application.Models; + namespace Infrastructure.Persistence.Models; -public class SpecializationModel +public class SpecializationModel : IEntity { public Guid? Id { get; set; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/UserModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/UserModel.cs index 87ba2a9..785feda 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/UserModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/UserModel.cs @@ -1,6 +1,8 @@ +using DoctorsHelp.Application.Models; + namespace Infrastructure.Persistence.Models; -public class UserModel +public class UserModel : IEntity { public Guid? Id { get; set; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/AppointmentRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/AppointmentRepository.cs index 5ade7f7..19ce9e3 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/AppointmentRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/AppointmentRepository.cs @@ -12,9 +12,9 @@ public AppointmentRepository(ApplicationDbContext context) : base(context) { } - public AppointmentModel GetAppointment(int id) + public AppointmentModel? GetAppointment(Guid id) { - return GetEntry(new Appointment { Id = id }).Entity; + return GetEntry(new Appointment { Id = id })?.Entity; } public void UpdateAppointment(Appointment appointment) @@ -28,6 +28,11 @@ public bool Delete(Appointment appointment) return true; } + public void AddAppointment(Appointment appointment) + { + Add(appointment); + } + protected override DbSet DbSet => ((ApplicationDbContext)Context).Appointments; protected override AppointmentModel MapFrom(Appointment entity) @@ -36,7 +41,7 @@ protected override AppointmentModel MapFrom(Appointment entity) { Id = entity.Id, PatientId = entity.Patient?.Id ?? Guid.Empty, - ScheduleId = entity.Schedule?.Id ?? 0, + ScheduleId = entity.Schedule?.Id ?? Guid.Empty, CreatedAt = entity.CreatedAt, UpdatedAt = entity.UpdatedAt, Status = entity.Status, @@ -51,7 +56,7 @@ protected override bool Equal(Appointment entity, AppointmentModel model) protected override void UpdateModel(AppointmentModel model, Appointment entity) { model.PatientId = entity.Patient?.Id ?? Guid.Empty; - model.ScheduleId = entity.Schedule?.Id ?? 0; + model.ScheduleId = entity.Schedule?.Id ?? Guid.Empty; model.CreatedAt = entity.CreatedAt; model.UpdatedAt = entity.UpdatedAt; model.Status = entity.Status; diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs index ab358e6..a90f495 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs @@ -12,9 +12,9 @@ public EmployeeRepository(ApplicationDbContext context) : base(context) { } - public EmployeeModel GetEmployee(int id) + public EmployeeModel? GetEmployee(Guid id) { - return GetEntry(new Employee { Id = id }).Entity; + return GetEntry(new Employee { Id = id })?.Entity; } public void UpdateEmployee(Employee employee) @@ -28,6 +28,11 @@ public bool Delete(Employee employee) return true; } + public void AddEmployee(Employee employee) + { + Add(employee); + } + protected override DbSet DbSet => ((ApplicationDbContext)Context).Employees; protected override EmployeeModel MapFrom(Employee entity) diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs index ee3fdae..c3a2d58 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs @@ -1,9 +1,12 @@ +using DoctorsHelp.Application.Models; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; namespace DoctorsHelp.Infrastructure.Persistence.Repositories; -public abstract class RepositoryBase where TModel : class +public abstract class RepositoryBase + where TEntity : IEntity + where TModel : class, IEntity { #pragma warning disable IDE0032 private readonly DbContext _context; @@ -21,6 +24,7 @@ public void Add(TEntity entity) { TModel model = MapFrom(entity); DbSet.Add(model); + _context.SaveChanges(); } public void AddRange(IEnumerable entities) @@ -31,15 +35,23 @@ public void AddRange(IEnumerable entities) public void Update(TEntity entity) { - EntityEntry entry = GetEntry(entity); - UpdateModel(entry.Entity, entity); + EntityEntry? entry = GetEntry(entity); + + if (entry is null) + return; + UpdateModel(entry.Entity, entity); entry.State = EntityState.Modified; + _context.SaveChanges(); } public void Remove(TEntity entity) { - EntityEntry entry = GetEntry(entity); + EntityEntry? entry = GetEntry(entity); + + if (entry is null) + return; + entry.State = entry.State is EntityState.Added ? EntityState.Detached : EntityState.Deleted; } @@ -49,12 +61,13 @@ public void Remove(TEntity entity) protected abstract void UpdateModel(TModel model, TEntity entity); - protected EntityEntry GetEntry(TEntity entity) + protected EntityEntry? GetEntry(TEntity entity) { - TModel? existing = DbSet.Local.FirstOrDefault(model => Equal(entity, model)); + TModel? existing = DbSet.FirstOrDefault(model => model.Id == entity.Id); + Console.WriteLine(existing is null); return existing is not null ? _context.Entry(existing) - : DbSet.Attach(MapFrom(entity)); + : null; } } \ No newline at end of file diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ReviewRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ReviewRepository.cs index 71343bb..bd27fa1 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ReviewRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ReviewRepository.cs @@ -12,9 +12,9 @@ public ReviewRepository(ApplicationDbContext context) : base(context) { } - public ReviewModel GetReview(int id) + public ReviewModel? GetReview(Guid id) { - return GetEntry(new Review { Id = id }).Entity; + return GetEntry(new Review { Id = id })?.Entity; } public void UpdateReview(Review review) @@ -28,6 +28,11 @@ public bool Delete(Review review) return true; } + public void AddReview(Review review) + { + Add(review); + } + protected override DbSet DbSet => ((ApplicationDbContext)Context).Reviews; protected override ReviewModel MapFrom(Review entity) @@ -35,7 +40,7 @@ protected override ReviewModel MapFrom(Review entity) return new ReviewModel { Id = entity.Id, - AppointmentId = entity.Appointment?.Id ?? 0, + AppointmentId = entity.Appointment?.Id ?? Guid.Empty, Grade = entity.Grade, Comment = entity.Comment, CreatedAt = entity.CreatedAt, @@ -50,7 +55,7 @@ protected override bool Equal(Review entity, ReviewModel model) protected override void UpdateModel(ReviewModel model, Review entity) { - model.AppointmentId = entity.Appointment?.Id ?? 0; + model.AppointmentId = entity.Appointment?.Id ?? Guid.Empty; model.Grade = entity.Grade; model.Comment = entity.Comment; model.CreatedAt = entity.CreatedAt; diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ScheduleRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ScheduleRepository.cs index 3e838dc..38d6a74 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ScheduleRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/ScheduleRepository.cs @@ -12,9 +12,14 @@ public ScheduleRepository(ApplicationDbContext context) : base(context) { } - public ScheduleModel GetSchedule(int id) + public ScheduleModel? GetSchedule(Guid id) { - return GetEntry(new Schedule { Id = id }).Entity; + return GetEntry(new Schedule { Id = id })?.Entity; + } + + public void UpdateSchedule(Schedule schedule) + { + Update(schedule); } public bool Delete(Schedule schedule) @@ -23,6 +28,11 @@ public bool Delete(Schedule schedule) return true; } + public void AddSchedule(Schedule schedule) + { + Add(schedule); + } + protected override DbSet DbSet => ((ApplicationDbContext)Context).Schedules; protected override ScheduleModel MapFrom(Schedule entity) @@ -30,7 +40,7 @@ protected override ScheduleModel MapFrom(Schedule entity) return new ScheduleModel { Id = entity.Id, - EmployeeId = entity.Employee?.Id ?? 0, + EmployeeId = entity.Employee?.Id ?? Guid.Empty, DateStart = entity.DateStart, DateEnd = entity.DateEnd, Status = entity.Status, @@ -44,7 +54,7 @@ protected override bool Equal(Schedule entity, ScheduleModel model) protected override void UpdateModel(ScheduleModel model, Schedule entity) { - model.EmployeeId = entity.Employee?.Id ?? 0; + model.EmployeeId = entity.Employee?.Id ?? Guid.Empty; model.DateStart = entity.DateStart; model.DateEnd = entity.DateEnd; model.Status = entity.Status; diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs index 9de2038..3388392 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/SpecializationRepository.cs @@ -17,9 +17,10 @@ public void UpdateSpecialization(Specialization specialization) Update(specialization); } - public SpecializationModel GetSpecialization(Guid id) + public SpecializationModel? GetSpecialization(Guid id) { - return GetEntry(new Specialization { Id = id }).Entity; + SpecializationModel? entry = GetEntry(new Specialization { Id = id })?.Entity; + return entry; } public bool Delete(Specialization specialization) diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/UserRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/UserRepository.cs index 0082838..0bfc42b 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/UserRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/UserRepository.cs @@ -12,9 +12,9 @@ public UserRepository(ApplicationDbContext context) : base(context) { } - public UserModel GetUser(Guid id) + public UserModel? GetUser(Guid id) { - return GetEntry(new User { Id = id }).Entity; + return GetEntry(new User { Id = id })?.Entity; } public void UpdateUser(User user) diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/AppointmentController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/AppointmentController.cs index 1dcd99d..12aa80c 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/AppointmentController.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/AppointmentController.cs @@ -1,11 +1,12 @@ using DoctorsHelp.Application.Contracts; using DoctorsHelp.Application.Models; using DoctorsHelp.Presentation.Http.Requests; +using DoctorsHelp.Presentation.Http.Responses; using Microsoft.AspNetCore.Mvc; namespace DoctorsHelp.Presentation.Http.Controllers; [ApiController] -[Route("[controller]")] +[Route("appointment")] public class AppointmentController : ControllerBase { private readonly IAppointmentService _appointmentService; @@ -16,7 +17,7 @@ public AppointmentController(IAppointmentService appointmentService) } [HttpGet("{id}")] - public ActionResult Get(int id) + public ActionResult Get(Guid id) { var appointment = _appointmentService.GetAppointment(id); if (appointment == null) @@ -28,7 +29,7 @@ public ActionResult Get(int id) } [HttpPost] - public ActionResult Post([FromBody] AppointmentPost data) + public ActionResult Post([FromBody] AppointmentPost data) { try { @@ -42,7 +43,7 @@ public ActionResult Post([FromBody] AppointmentPost data) } [HttpPut("{id}")] - public ActionResult Update(int id, [FromBody] Dictionary data) + public ActionResult Update(Guid id, [FromBody] Dictionary data) { try { @@ -56,7 +57,7 @@ public ActionResult Update(int id, [FromBody] Dictionary Get(int id) + public ActionResult Get(Guid id) { var employee = _employeeService.GetEmployee(id); if (employee == null) @@ -29,7 +29,7 @@ public ActionResult Get(int id) } [HttpPost] - public ActionResult Post([FromBody] EmployeePost data) + public ActionResult Post([FromBody] EmployeePost data) { if (string.IsNullOrWhiteSpace(data.Graduate) || string.IsNullOrWhiteSpace(data.Experience)) { @@ -48,7 +48,7 @@ public ActionResult Post([FromBody] EmployeePost data) } [HttpPut("{id}")] - public ActionResult Update(int id, [FromBody] Dictionary data) + public ActionResult Update(Guid id, [FromBody] Dictionary data) { try { @@ -62,7 +62,7 @@ public ActionResult Update(int id, [FromBody] Dictionary Get(int id) + public ActionResult Get(Guid id) { var review = _reviewService.GetReview(id); if (review == null) @@ -29,7 +29,7 @@ public ActionResult Get(int id) } [HttpPost] - public ActionResult Post([FromBody] ReviewPost data) + public ActionResult Post([FromBody] ReviewPost data) { if (data.Grade < 1 || string.IsNullOrWhiteSpace(data.Comment)) { @@ -48,7 +48,7 @@ public ActionResult Post([FromBody] ReviewPost data) } [HttpPut("{id}")] - public ActionResult Update(int id, [FromBody] Dictionary data) + public ActionResult Update(Guid id, [FromBody] Dictionary data) { try { @@ -62,7 +62,7 @@ public ActionResult Update(int id, [FromBody] Dictionary } [HttpDelete("{id}")] - public IActionResult Delete(int id) + public IActionResult Delete(Guid id) { var result = _reviewService.Delete(id); if (result) diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ScheduleController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ScheduleController.cs index 6f25469..4c06b88 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ScheduleController.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/ScheduleController.cs @@ -6,7 +6,7 @@ namespace DoctorsHelp.Presentation.Http.Controllers; [ApiController] -[Route("[controller]")] +[Route("schedule")] public class ScheduleController : ControllerBase { private readonly IScheduleService _scheduleService; @@ -17,7 +17,7 @@ public ScheduleController(IScheduleService scheduleService) } [HttpGet("{id}")] - public ActionResult Get(int id) + public ActionResult Get(Guid id) { var schedule = _scheduleService.GetSchedule(id); if (schedule == null) @@ -29,7 +29,7 @@ public ActionResult Get(int id) } [HttpPost] - public ActionResult Post([FromBody] SchedulePost data) + public ActionResult Post([FromBody] SchedulePost data) { if (data.DateStart == default || data.DateEnd == default) { @@ -53,7 +53,7 @@ public ActionResult Post([FromBody] SchedulePost data) } [HttpPut("{id}")] - public ActionResult Update(int id, [FromBody] Dictionary data) + public ActionResult Update(Guid id, [FromBody] Dictionary data) { try { @@ -67,7 +67,7 @@ public ActionResult Update(int id, [FromBody] Dictionary Get(Guid id) { var specialization = _specializationService.GetSpecialization(id); if (specialization == null) - { return BadRequest("No specialization found with the given id."); - } return Ok(specialization); } [HttpPost] - public ActionResult Post([FromBody] SpecializationPost data) + public ActionResult Post([FromBody] SpecializationPost data) { if (data.Name == null || data.Description == null) { diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs index 4224753..d5e8132 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs @@ -6,7 +6,7 @@ namespace DoctorsHelp.Presentation.Http.Controllers; [ApiController] -[Route("[controller]")] +[Route("user")] public class UserController : ControllerBase { private readonly IUserService _userService; @@ -21,15 +21,13 @@ public ActionResult Get(Guid id) { var user = _userService.GetUser(id); if (user == null) - { return NotFound(); - } return Ok(user); } - [HttpPost("register")] - public ActionResult Register([FromBody] UserPost data) + [HttpPost] + public ActionResult Post([FromBody] UserPost data) { if (string.IsNullOrWhiteSpace(data.Name) || string.IsNullOrWhiteSpace(data.Surname) || @@ -43,6 +41,7 @@ public ActionResult Register([FromBody] UserPost data) try { var user = _userService.Register(data.Name, data.Surname, data.Phone, data.Email, data.Password, data.Birthdate); + Console.WriteLine("User post"); return CreatedAtAction(nameof(Get), new { id = user.Id }, user); } catch (Exception ex) diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Requests/AppointmentPost.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/AppointmentPost.cs index a039709..62e5d57 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Requests/AppointmentPost.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/AppointmentPost.cs @@ -4,5 +4,5 @@ public class AppointmentPost { public Guid PatientId { get; set; } - public int ScheduleId { get; set; } + public Guid ScheduleId { get; set; } } \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Requests/ReviewPost.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/ReviewPost.cs index 432f679..6dee4f2 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Requests/ReviewPost.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/ReviewPost.cs @@ -2,7 +2,7 @@ public class ReviewPost { - public int AppointmentId { get; set; } + public Guid AppointmentId { get; set; } public int Grade { get; set; } diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Requests/SchedulePost.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/SchedulePost.cs index 76b7e45..cd69cb5 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Requests/SchedulePost.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Requests/SchedulePost.cs @@ -2,7 +2,7 @@ public class SchedulePost { - public int EmployeeId { get; set; } + public Guid EmployeeId { get; set; } public DateTime? DateStart { get; set; } diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Responses/AppointmentPostResponse.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Responses/AppointmentPostResponse.cs new file mode 100644 index 0000000..1e64a72 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Responses/AppointmentPostResponse.cs @@ -0,0 +1,6 @@ +namespace DoctorsHelp.Presentation.Http.Responses; + +public class AppointmentPostResponse +{ + public Guid AppointmentId { get; set; } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Responses/EmployeePostResponse.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Responses/EmployeePostResponse.cs new file mode 100644 index 0000000..1b22282 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Responses/EmployeePostResponse.cs @@ -0,0 +1,6 @@ +namespace DoctorsHelp.Presentation.Http.Requests; + +public class EmployeePostResponse +{ + public Guid EmployeeId { get; set; } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Responses/ReviewPostResponse.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Responses/ReviewPostResponse.cs new file mode 100644 index 0000000..a40f161 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Responses/ReviewPostResponse.cs @@ -0,0 +1,6 @@ +namespace DoctorsHelp.Presentation.Http.Requests; + +public class ReviewPostResponse +{ + public Guid ReviewId { get; set; } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Responses/SchedulePostResponse.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Responses/SchedulePostResponse.cs new file mode 100644 index 0000000..6f7fd50 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Responses/SchedulePostResponse.cs @@ -0,0 +1,6 @@ +namespace DoctorsHelp.Presentation.Http.Requests; + +public class SchedulePostResponse +{ + public Guid ReviewId { get; set; } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Responses/SpecializationPostResponse.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Responses/SpecializationPostResponse.cs new file mode 100644 index 0000000..ad70f09 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Responses/SpecializationPostResponse.cs @@ -0,0 +1,6 @@ +namespace DoctorsHelp.Presentation.Http.Requests; + +public class SpecializationPostResponse +{ + public Guid SpecializationId { get; set; } +} \ No newline at end of file diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Responses/UserPostResponse.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Responses/UserPostResponse.cs new file mode 100644 index 0000000..63f8e60 --- /dev/null +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Responses/UserPostResponse.cs @@ -0,0 +1,6 @@ +namespace DoctorsHelp.Presentation.Http.Requests; + +public class UserPostResponse +{ + public Guid UserId { get; set; } +} \ No newline at end of file From 3760c02be3e3010fc69c478758976ff03ebad43e Mon Sep 17 00:00:00 2001 From: AlexYrkn <61319606+AlexYrkn@users.noreply.github.com> Date: Sat, 13 Apr 2024 14:00:47 +0300 Subject: [PATCH 12/12] fixed models connections --- .../Services/AppointmentService.cs | 6 ++++++ .../Services/EmployeeService.cs | 8 +++++++- .../Services/ReviewService.cs | 3 +++ .../Services/ScheduleService.cs | 3 +++ .../Models/EmployeeModel.cs | 2 +- .../Repositories/EmployeeRepository.cs | 4 ++-- .../Repositories/RepositoryBase.cs | 1 - .../Controllers/UserController.cs | 1 - 8 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs index 5789960..8c65a42 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/AppointmentService.cs @@ -42,6 +42,12 @@ public Appointment Create(Guid patientId, Guid scheduleId) { var appointmentModel = _appointmentRepository.GetAppointment(patientId); + if (appointmentModel is not null) + { + appointmentModel.Patient = _patientRepository.GetUser(appointmentModel.PatientId); + appointmentModel.Schedule = _scheduleRepository.GetSchedule(appointmentModel.ScheduleId); + } + return AppointmentConverter.AppointmentModelToAppointment(appointmentModel); } diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs index 281a8e4..7028669 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/EmployeeService.cs @@ -42,7 +42,13 @@ public Employee Create(Guid userId, Guid specializationId, string graduate, stri public Employee? GetEmployee(Guid employeeId) { - var employeeModel = _employeeRepository.GetEmployee(employeeId); + EmployeeModel? employeeModel = _employeeRepository.GetEmployee(employeeId); + + if (employeeModel is not null) + { + employeeModel.User = _userRepository.GetUser(employeeModel.UserId); + employeeModel.Specialization = _specializationRepository.GetSpecialization(employeeModel.SpecializationId); + } return EmployeeConverter.EmployeeModelToEmployee(employeeModel); } diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs index a738754..2f8cf4b 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/ReviewService.cs @@ -38,6 +38,9 @@ public Review Create(Guid appointmentId, int? grade, string comment) { var reviewModel = _reviewRepository.GetReview(reviewId); + if (reviewModel is not null) + reviewModel.Appointment = _appointmentRepository.GetAppointment(reviewModel.AppointmentId); + return ReviewConverter.ReviewModelToReview(reviewModel); } diff --git a/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs b/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs index 4f1aee6..7a7e262 100644 --- a/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs +++ b/src/Application/DoctorsHelp.Application.Contracts/Services/ScheduleService.cs @@ -38,6 +38,9 @@ public Schedule Create(Guid employeeId, DateTime? dateStart, DateTime? dateEnd) { var scheduleModel = _scheduleRepository.GetSchedule(scheduleId); + if (scheduleModel is not null) + scheduleModel.Employee = _employeeRepository.GetEmployee(scheduleModel.EmployeeId); + return ScheduleConverter.ScheduleModelToSchedule(scheduleModel); } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs index 266a7a7..593b8a2 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Models/EmployeeModel.cs @@ -8,7 +8,7 @@ public class EmployeeModel : IEntity public Guid UserId { get; set; } - public Guid? SpecializationId { get; set; } + public Guid SpecializationId { get; set; } public string? Graduate { get; set; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs index a90f495..8825f14 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/EmployeeRepository.cs @@ -41,7 +41,7 @@ protected override EmployeeModel MapFrom(Employee entity) { Id = entity.Id, UserId = entity.User?.Id ?? Guid.Empty, - SpecializationId = entity.Specialization?.Id, + SpecializationId = entity.Specialization?.Id ?? Guid.Empty, Graduate = entity.Graduate, Experience = entity.Experience, }; @@ -55,7 +55,7 @@ protected override bool Equal(Employee entity, EmployeeModel model) protected override void UpdateModel(EmployeeModel model, Employee entity) { model.UserId = entity.User?.Id ?? Guid.Empty; - model.SpecializationId = entity.Specialization?.Id; + model.SpecializationId = entity.Specialization?.Id ?? Guid.Empty; model.Graduate = entity.Graduate; model.Experience = entity.Experience; } diff --git a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs index c3a2d58..331b9d2 100644 --- a/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs +++ b/src/Infrastructure/DoctorsHelp.Infrastructure.Persistence/Repositories/RepositoryBase.cs @@ -65,7 +65,6 @@ public void Remove(TEntity entity) { TModel? existing = DbSet.FirstOrDefault(model => model.Id == entity.Id); - Console.WriteLine(existing is null); return existing is not null ? _context.Entry(existing) : null; diff --git a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs index d5e8132..97c6482 100644 --- a/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs +++ b/src/Presentation/DoctorsHelp.Presentation.Http/Controllers/UserController.cs @@ -41,7 +41,6 @@ public ActionResult Post([FromBody] UserPost data) try { var user = _userService.Register(data.Name, data.Surname, data.Phone, data.Email, data.Password, data.Birthdate); - Console.WriteLine("User post"); return CreatedAtAction(nameof(Get), new { id = user.Id }, user); } catch (Exception ex)