Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
569 changes: 569 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

33 changes: 0 additions & 33 deletions .github/workflows/main.yml

This file was deleted.

17 changes: 13 additions & 4 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,24 @@
<EnablePackageVersionOverride>false</EnablePackageVersionOverride>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Itmo.Dev.Editorconfig" Version="1.0.2" />
<PackageVersion Include="Itmo.Dev.Platform.Logging" Version="1.0.89" />
<PackageVersion Include="Itmo.Dev.Platform.Postgres" Version="1.1.89" />
<PackageVersion Include="DotNet.Testcontainers" Version="1.6.0" />
<PackageVersion Include="EntityFramework" Version="6.4.4" />
<PackageVersion Include="Itmo.Dev.Editorconfig" Version="1.0.1" />
<PackageVersion Include="Itmo.Dev.Platform.Logging" Version="1.0.82" />
<PackageVersion Include="Itmo.Dev.Platform.Postgres" Version="1.1.82" />
<PackageVersion Include="Itmo.Dev.Platform.Common" Version="1.1.82" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="7.0.15" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="7.0.10" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.10" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.10" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="SourceKit.Generators.Builder" Version="1.1.24" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.435" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="Testcontainers" Version="3.7.0" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="3.7.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\Infrastructure\DoctorsHelp.Infrastructure.Persistence\DoctorsHelp.Infrastructure.Persistence.csproj" />
<ProjectReference Include="..\DoctorsHelp.Application.Models\DoctorsHelp.Application.Models.csproj"/>
</ItemGroup>

<ItemGroup>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ namespace DoctorsHelp.Application.Contracts;

public interface IAppointmentService
{
Appointment Create(User patient, Schedule schedule);
Appointment Create(Guid patientId, Guid scheduleId);

Appointment GetAppointment(int patientId);
Appointment? GetAppointment(Guid patientId);

Appointment Update(int id, Dictionary<string, string> data);
Appointment? Update(Guid id, Dictionary<string, string> data);

bool Delete(int id);
}
bool Delete(Guid id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ namespace DoctorsHelp.Application.Contracts;

public interface IEmployeeService
{
Employee Create(User user, Specialization specialization, string graduate, string experience);
Employee Create(Guid userId, Guid specializationId, string graduate, string experience);

Employee GetEmployee();
Employee? GetEmployee(Guid employeeId);

Employee GetById(int id);
Employee? Update(Guid id, Dictionary<string, string> data);

Employee Update(int id, Dictionary<string, string> data);

bool Delete(int id);
bool Delete(Guid id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ namespace DoctorsHelp.Application.Contracts;

public interface IReviewService
{
Review Create(Appointment appointment, int grade, string comment);
Review Create(Guid appointmentId, int? grade, string comment);

Review GetReview(int appointmentId);
Review? GetReview(Guid reviewId);

Review Update(int id, Dictionary<string, string> data);
Review? Update(Guid id, Dictionary<string, string> data);

bool Delete(int id);
bool Delete(Guid id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ namespace DoctorsHelp.Application.Contracts;

public interface IScheduleService
{
Review Create(Employee employee, DateTime dateStart, DateTime dateEnd);
Schedule Create(Guid employeeId, DateTime? dateStart, DateTime? dateEnd);

Review GeSchedule(int employeeId);
Schedule? GetSchedule(Guid scheduleId);

Review Update(int id, Dictionary<string, string> data);
Schedule? Update(Guid id, Dictionary<string, string> data);

bool Delete(int id);
bool Delete(Guid id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> data);
Specialization? Update(Guid id, Dictionary<string, string> data);

bool Delete(int id);
bool Delete(Guid id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> data);

User Update(int id, Dictionary<string, string> data);

bool Delete(int id);
bool DeleteUser(Guid id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using DoctorsHelp.Application.Models;
using DoctorsHelp.Infrastructure.Persistence.Converters;
using DoctorsHelp.Infrastructure.Persistence.Interfaces;
using Infrastructure.Persistence.Models;

namespace DoctorsHelp.Application.Contracts.Services;

public class AppointmentService : IAppointmentService
{
private readonly IAppointmentRepository _appointmentRepository;
private readonly IUserRepository _patientRepository;
private readonly IScheduleRepository _scheduleRepository;

public AppointmentService(IAppointmentRepository appointmentRepository, IUserRepository userRepository, IScheduleRepository scheduleRepository)
{
_appointmentRepository = appointmentRepository;
_patientRepository = userRepository;
_scheduleRepository = scheduleRepository;
}

public Appointment Create(Guid patientId, Guid 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
{
Id = Guid.NewGuid(),
Patient = patient,
Schedule = schedule,
};
_appointmentRepository.AddAppointment(appointment);
return appointment;
}

public Appointment? GetAppointment(Guid patientId)
{
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);
}

public Appointment? Update(Guid id, Dictionary<string, string> data)
{
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":
Guid patientId;
if (Guid.TryParse(entry.Value, out patientId))
appointmentToUpdate.PatientId = patientId;
break;
case "scheduleId":
Guid scheduleId;
if (Guid.TryParse(entry.Value, out scheduleId))
appointmentToUpdate.ScheduleId = scheduleId;
break;
case "status":
int status;
if (int.TryParse(entry.Value, out status))
appointmentToUpdate.Status = status;
break;
}
}

var appointment = AppointmentConverter.AppointmentModelToAppointment(appointmentToUpdate);

if (appointment is null)
return null;

_appointmentRepository.UpdateAppointment(appointment);

return AppointmentConverter.AppointmentModelToAppointment(appointmentToUpdate);
}

public bool Delete(Guid id)
{
return _appointmentRepository.Delete(new Appointment { Id = id, });
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using DoctorsHelp.Application.Models;
using DoctorsHelp.Infrastructure.Persistence.Converters;
using DoctorsHelp.Infrastructure.Persistence.Interfaces;
using Infrastructure.Persistence.Models;

namespace DoctorsHelp.Application.Contracts.Services;

public class EmployeeService : IEmployeeService
{
private readonly IEmployeeRepository _employeeRepository;
private readonly IUserRepository _userRepository;
private readonly ISpecializationRepository _specializationRepository;

public EmployeeService(IEmployeeRepository appointmentRepository, IUserRepository userRepository, ISpecializationRepository specializationRepository)
{
_employeeRepository = appointmentRepository;
_userRepository = userRepository;
_specializationRepository = specializationRepository;
}

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));

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.AddEmployee(employee);
return employee;
}

public Employee? GetEmployee(Guid 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);
}

public Employee? Update(Guid id, Dictionary<string, string> data)
{
EmployeeModel? employeeToUpdate = _employeeRepository.GetEmployee(id);

if (employeeToUpdate is null)
throw new Exception("No such employee");

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":
Guid specializationId;
if (Guid.TryParse(entry.Value, out specializationId))
employeeToUpdate.SpecializationId = specializationId;
break;
case "Graduate":
employeeToUpdate.Graduate = entry.Value;
break;
case "Experience":
employeeToUpdate.Experience = entry.Value;
break;
}
}

var employee = EmployeeConverter.EmployeeModelToEmployee(employeeToUpdate);

if (employee is null)
return null;

_employeeRepository.UpdateEmployee(employee);

return EmployeeConverter.EmployeeModelToEmployee(employeeToUpdate);
}

public bool Delete(Guid id)
{
return _employeeRepository.Delete(new Employee { Id = id, });
}
}
Loading