Commit 47d96d17 authored by Almouhannad's avatar Almouhannad

(B) Add receptionist use cases commands and queries

parent 65bc5fc3
...@@ -14,8 +14,4 @@ ...@@ -14,8 +14,4 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" /> <ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Employees\Queries\" />
</ItemGroup>
</Project> </Project>
using Application.Abstractions.CQRS.Queries;
using Domain.Repositories;
using Domain.Shared;
namespace Application.Doctors.Queries.GetAllDoctors;
public class GetAllDoctorsHandler : IQueryHandler<GetAllDoctorsQuery, GetAllDoctorsResponse>
{
#region CTOR DI
private readonly IDoctorsRepository _doctorsRepository;
public GetAllDoctorsHandler(IDoctorsRepository doctorsRepository)
{
_doctorsRepository = doctorsRepository;
}
#endregion
public async Task<Result<GetAllDoctorsResponse>> Handle(GetAllDoctorsQuery request, CancellationToken cancellationToken)
{
#region 1. Fetch data from persistence
var dataFromPersistenceResult = await _doctorsRepository.GetAllAsync();
if (dataFromPersistenceResult.IsFailure)
return Result.Failure<GetAllDoctorsResponse>(dataFromPersistenceResult.Error);
var doctors = dataFromPersistenceResult.Value;
#endregion
return Result.Success<GetAllDoctorsResponse>(GetAllDoctorsResponse.GetResponse(doctors));
}
}
using Application.Abstractions.CQRS.Queries;
namespace Application.Doctors.Queries.GetAllDoctors;
public class GetAllDoctorsQuery : IQuery<GetAllDoctorsResponse>
{
}
using Domain.Entities.People.Doctors;
namespace Application.Doctors.Queries.GetAllDoctors;
public class GetAllDoctorsResponse
{
public class GetAllDoctorsResponseItem
{
public string FullName { get; set; } = null!;
public string Status { get; set; } = null!;
public ICollection<PhoneItem> Phones { get; set; } = null!;
}
public class PhoneItem
{
public string Name { get; set; } = null!;
public string Phone { get; set; } = null!;
}
public ICollection<GetAllDoctorsResponseItem> Doctors { get; set; } = null!;
public static GetAllDoctorsResponse GetResponse(ICollection<Doctor> doctors)
{
List<GetAllDoctorsResponseItem> response = new();
foreach (var doctor in doctors)
{
List<PhoneItem> phones = new();
foreach (var phone in doctor.Phones)
{
phones.Add(new PhoneItem
{
Name = phone.Name!,
Phone = phone.Phone,
});
}
response.Add(new GetAllDoctorsResponseItem
{
FullName = doctor.PersonalInfo.FullName,
Status = doctor.Status.Name,
Phones = phones
});
}
return new GetAllDoctorsResponse
{
Doctors = response
};
}
}
using Application.Abstractions.CQRS.Queries;
using Domain.Repositories;
using Domain.Shared;
namespace Application.Employees.Queries.GetBySerialNumber;
public class GetEmployeeBySerialNumberHandler : IQueryHandler<GetEmployeeBySerialNumberQuery, GetEmployeeBySerialNumberResponse>
{
#region CTOR DI
private readonly IEmployeesRepository _employeesRepository;
public GetEmployeeBySerialNumberHandler(IEmployeesRepository employeesRepository)
{
_employeesRepository = employeesRepository;
}
#endregion
public async Task<Result<GetEmployeeBySerialNumberResponse>> Handle(GetEmployeeBySerialNumberQuery request, CancellationToken cancellationToken)
{
#region 1. Fetch from persistence
var employeeFromPersistenceResult = await _employeesRepository.GetEmployeeBySerialNumberAsync(request.SerialNumber);
if (employeeFromPersistenceResult.IsFailure)
return Result.Failure<GetEmployeeBySerialNumberResponse>(employeeFromPersistenceResult.Error);
var employee = employeeFromPersistenceResult.Value;
#endregion
return Result.Success<GetEmployeeBySerialNumberResponse>
(GetEmployeeBySerialNumberResponse.GetResponse(employee));
}
}
using Application.Abstractions.CQRS.Queries;
namespace Application.Employees.Queries.GetBySerialNumber;
public class GetEmployeeBySerialNumberQuery : IQuery<GetEmployeeBySerialNumberResponse>
{
public string SerialNumber { get; set; } = null!;
}
using Domain.Entities.People.Employees;
namespace Application.Employees.Queries.GetBySerialNumber;
public class GetEmployeeBySerialNumberResponse
{
public int Id { get; set; }
public string FirstName { get; set; } = null!;
public string MiddleName { get; set; } = null!;
public string LastName { get; set; } = null!;
public string Gender { get; set; } = null!;
public DateOnly DateOfBirth { get; set; }
public string SerialNumber { get; set; } = null!;
public string CenterStatus { get; set; } = null!;
public static GetEmployeeBySerialNumberResponse GetResponse(Employee employee)
{
return new GetEmployeeBySerialNumberResponse
{
Id = employee.Id,
FirstName = employee.Patient.PersonalInfo.FirstName,
MiddleName = employee.Patient.PersonalInfo.MiddleName,
LastName = employee.Patient.PersonalInfo.LastName,
Gender = employee.Patient.Gender.Name,
DateOfBirth = employee.Patient.DateOfBirth,
SerialNumber = employee.SerialNumber,
CenterStatus = employee.CenterStatus
};
}
}
using Application.Abstractions.CQRS.Commands;
namespace Application.WaitingList.Commands.CreateWaitingListRecord;
public class CreateWaitingListRecordCommand : ICommand
{
public string SerialNumber { get; set; } = null!;
}
using Application.Abstractions.CQRS.Commands;
using Domain.Entities.WaitingList;
using Domain.Errors;
using Domain.Repositories;
using Domain.Shared;
using Domain.UnitOfWork;
namespace Application.WaitingList.Commands.CreateWaitingListRecord;
public class CreateWaitingListRecordHandler : CommandHandlerBase<CreateWaitingListRecordCommand>
{
#region CTOR DI
private readonly IEmployeesRepository _employeesRepository;
private readonly IWaitingListRepository _waitingListRepository;
public CreateWaitingListRecordHandler(IUnitOfWork unitOfWork, IWaitingListRepository waitingListRepository, IEmployeesRepository employeesRepository) : base(unitOfWork)
{
_waitingListRepository = waitingListRepository;
_employeesRepository = employeesRepository;
}
#endregion
public override async Task<Result> HandleHelper(CreateWaitingListRecordCommand request, CancellationToken cancellationToken)
{
#region 1. Fetch employee from persistence
var employeeFromPersistenceResult = await _employeesRepository.GetEmployeeBySerialNumberAsync(request.SerialNumber);
if (employeeFromPersistenceResult.IsFailure)
return Result.Failure(employeeFromPersistenceResult.Error);
var employee = employeeFromPersistenceResult.Value;
#endregion
#region 2. Check duplicate
var duplicateResult = await _waitingListRepository.IsEmployeeInWaitingListAsync(request.SerialNumber);
if (duplicateResult.IsFailure)
return Result.Failure(duplicateResult.Error);
if (duplicateResult.Value)
return Result.Failure(DomainErrors.PatientAlreadyInWaitingList);
#endregion
#region 3. Create waiting list record
var waitingListRecordResult = WaitingListRecord.Create(employee.Id);
if (waitingListRecordResult.IsFailure)
return Result.Failure(waitingListRecordResult.Error);
var waitingListRecord = waitingListRecordResult.Value;
#endregion
#region 4. save changes
var saveChangesResult = await _waitingListRepository.CreateAsync(waitingListRecord);
if (saveChangesResult.IsFailure)
return Result.Failure(saveChangesResult.Error);
#endregion
return Result.Success();
}
}
using Application.Abstractions.CQRS.Commands;
namespace Application.WaitingList.Commands.DeleteWaitingListRecord;
public class DeleteWaitingListRecordCommand : ICommand
{
public int Id { get; set; }
}
using Application.Abstractions.CQRS.Commands;
using Domain.Repositories;
using Domain.Shared;
using Domain.UnitOfWork;
namespace Application.WaitingList.Commands.DeleteWaitingListRecord;
public class DeleteWaitingListRecordHandler : CommandHandlerBase<DeleteWaitingListRecordCommand>
{
#region CTOR DI
private readonly IWaitingListRepository _waitingListRepository;
public DeleteWaitingListRecordHandler(IUnitOfWork unitOfWork, IWaitingListRepository waitingListRepository) : base(unitOfWork)
{
_waitingListRepository = waitingListRepository;
}
#endregion
public override async Task<Result> HandleHelper(DeleteWaitingListRecordCommand request, CancellationToken cancellationToken)
{
#region 1. Fetch from persistence
var recordFromPersistenceResult = await _waitingListRepository.GetByIdAsync(request.Id);
if (recordFromPersistenceResult.IsFailure)
return Result.Failure(recordFromPersistenceResult.Error);
var record = recordFromPersistenceResult.Value;
#endregion
#region 2. Perform delete
var deleteResult = await _waitingListRepository.DeleteAsync(record);
if (deleteResult.IsFailure)
return Result.Failure(deleteResult.Error);
#endregion
return Result.Success();
}
}
using Application.Abstractions.CQRS.Queries;
namespace Application.WaitingList.Queries;
public class GetAllWaitingListRecordsQuery : IQuery<GetAllWaitingListRecordsResponse>
{
}
using Application.Abstractions.CQRS.Queries;
using Domain.Entities.WaitingList;
using Domain.Repositories;
using Domain.Shared;
using static Application.WaitingList.Queries.GetAllWaitingListRecordsResponse;
namespace Application.WaitingList.Queries;
public class GetAllWaitingListRecordsQueryHandler : IQueryHandler<GetAllWaitingListRecordsQuery, GetAllWaitingListRecordsResponse>
{
#region CTOR DI
private readonly IWaitingListRepository _waitingListRepository;
private readonly IPatientsRepository _petientsRepository;
public GetAllWaitingListRecordsQueryHandler(IWaitingListRepository waitingListRepository, IPatientsRepository petientsRepository)
{
_waitingListRepository = waitingListRepository;
_petientsRepository = petientsRepository;
}
#endregion
public async Task<Result<GetAllWaitingListRecordsResponse>> Handle(GetAllWaitingListRecordsQuery request, CancellationToken cancellationToken)
{
#region 1. Fetch all from persistence
var fetchAllResult = await _waitingListRepository.GetAllAsync();
if (fetchAllResult.IsFailure)
return Result.Failure<GetAllWaitingListRecordsResponse>(fetchAllResult.Error);
var allRecords = fetchAllResult.Value;
#endregion
#region 2. Generate response
List<GetAllWaitingListRecordsResponseItem> response = [];
foreach (WaitingListRecord record in allRecords)
{
var isEmployee = await _petientsRepository.IsEmployeeByIdAsync(record.PatientId);
if (isEmployee.IsFailure)
return Result.Failure<GetAllWaitingListRecordsResponse>(isEmployee.Error);
var responseItem = new GetAllWaitingListRecordsResponseItem
{
Id = record.Id,
PatientId = record.PatientId,
IsEmployee = isEmployee.Value,
FullName = record.Patient.PersonalInfo.FullName,
ArrivalTime = record.ArrivalTime
};
response.Add(responseItem);
}
#endregion
return Result.Success<GetAllWaitingListRecordsResponse>
(new GetAllWaitingListRecordsResponse
{
WaitingListRecords = response
});
}
}
namespace Application.WaitingList.Queries;
public class GetAllWaitingListRecordsResponse
{
public class GetAllWaitingListRecordsResponseItem
{
public int Id { get; set; }
public int PatientId { get; set; }
public string FullName { get; set; } = null!;
public bool IsEmployee { get; set; }
public DateTime ArrivalTime { get; set; }
}
public ICollection<GetAllWaitingListRecordsResponseItem> WaitingListRecords { get; set; } = null!;
}
...@@ -10,9 +10,10 @@ public sealed class WaitingListRecord : Entity ...@@ -10,9 +10,10 @@ public sealed class WaitingListRecord : Entity
#region Private ctor #region Private ctor
private WaitingListRecord(int id) : base(id) { } private WaitingListRecord(int id) : base(id) { }
private WaitingListRecord(int id, int patientId) : base(id) private WaitingListRecord(int id, int patientId, DateTime arrivalTime) : base(id)
{ {
PatientId = patientId; PatientId = patientId;
ArrivalTime = arrivalTime;
} }
#endregion #endregion
...@@ -28,7 +29,7 @@ public sealed class WaitingListRecord : Entity ...@@ -28,7 +29,7 @@ public sealed class WaitingListRecord : Entity
#region Additional #region Additional
DateTime ArrivalTime { get; set; } public DateTime ArrivalTime { get; set; }
#endregion #endregion
...@@ -42,7 +43,7 @@ public sealed class WaitingListRecord : Entity ...@@ -42,7 +43,7 @@ public sealed class WaitingListRecord : Entity
{ {
if (patientId <= 0) if (patientId <= 0)
return Result.Failure<WaitingListRecord>(Errors.DomainErrors.InvalidValuesError); return Result.Failure<WaitingListRecord>(Errors.DomainErrors.InvalidValuesError);
return new WaitingListRecord(0, patientId); return new WaitingListRecord(0, patientId, DateTime.Now);
} }
#endregion #endregion
......
...@@ -40,4 +40,10 @@ public static class DomainErrors ...@@ -40,4 +40,10 @@ public static class DomainErrors
public static Error InvalidHolidayDuration => public static Error InvalidHolidayDuration =>
new("Domain.InvalidHolidayDuration", "الحد الأقصى للإجازة المرضية هو خمس أيام"); new("Domain.InvalidHolidayDuration", "الحد الأقصى للإجازة المرضية هو خمس أيام");
public static Error SerialNumberNotFound =>
new("Domain.SerialNumberNotFound", "لا يوجد موظف بهذا الرقم الذاتي");
public static Error PatientAlreadyInWaitingList =>
new("Domain.PatientAlreadyInWaitingList", "المريض موجود في قائمة الانتظار بالفعل");
} }
using Domain.Entities.People.Doctors;
using Domain.Repositories.Base;
namespace Domain.Repositories;
public interface IDoctorsRepository : IRepository<Doctor>
{
}
using Domain.Entities.People.Patients; using Domain.Entities.People.Employees;
using Domain.Entities.People.FamilyMembers;
using Domain.Entities.People.Patients;
using Domain.Repositories.Base; using Domain.Repositories.Base;
using Domain.Shared; using Domain.Shared;
...@@ -11,4 +13,15 @@ public interface IPatientsRepository : IRepository<Patient> ...@@ -11,4 +13,15 @@ public interface IPatientsRepository : IRepository<Patient>
public Task<Result<ICollection<Patient>>> GetAllFullAsync(int id); public Task<Result<ICollection<Patient>>> GetAllFullAsync(int id);
#endregion #endregion
#region IsEmployee
public Task<Result<bool>> IsEmployeeByIdAsync(int id);
public Task<Result<Employee>> GetEmployeeByIdAsync(int id);
#endregion
#region FamilyMember
public Task<Result<bool>> IsFamilyMemberByIdAsync(int id);
public Task<Result<FamilyMember>> GetFamilyMemberByIdAsync(int id);
#endregion
} }
using Domain.Entities.WaitingList;
using Domain.Repositories.Base;
using Domain.Shared;
namespace Domain.Repositories;
public interface IWaitingListRepository : IRepository<WaitingListRecord>
{
public Task<Result<bool>> IsEmployeeInWaitingListAsync(string serialNumber);
}
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Persistence.Migrations
{
/// <inheritdoc />
public partial class Fix_Waiting_List : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<DateTime>(
name: "ArrivalTime",
table: "WaitingListRecord",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ArrivalTime",
table: "WaitingListRecord");
}
}
}
...@@ -695,6 +695,9 @@ namespace Persistence.Migrations ...@@ -695,6 +695,9 @@ namespace Persistence.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id")); SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("ArrivalTime")
.HasColumnType("datetime2");
b.Property<int>("PatientId") b.Property<int>("PatientId")
.HasColumnType("int"); .HasColumnType("int");
......
using Domain.Entities.People.Doctors;
using Domain.Errors;
using Domain.Repositories;
using Domain.Shared;
using Microsoft.EntityFrameworkCore;
using Persistence.Context;
using Persistence.Repositories.Base;
using Persistence.Repositories.Doctors.Specifications;
using System.Collections.Generic;
namespace Persistence.Repositories.Doctors;
public class DoctorsRepository : Repositroy<Doctor>, IDoctorsRepository
{
#region CTOR DI
public DoctorsRepository(ClinicsDbContext context) : base(context)
{
}
#endregion
#region Read methods
public override async Task<Result<ICollection<Doctor>>> GetAllAsync()
{
try
{
var query = ApplySpecification(new FullDoctorSpecification(doctor => true));
return await query.ToListAsync();
}
catch (Exception)
{
return Result.Failure<ICollection<Doctor>>(PersistenceErrors.Unknown);
}
}
#endregion
}
using Domain.Entities.People.Doctors;
using Persistence.Repositories.Specifications.Base;
using System.Linq.Expressions;
namespace Persistence.Repositories.Doctors.Specifications;
public class FullDoctorSpecification : Specification<Doctor>
{
public FullDoctorSpecification(Expression<Func<Doctor, bool>>? criteria) : base(criteria)
{
AddInclude(doctor => doctor.PersonalInfo);
AddInclude(doctor => doctor.Status);
AddInclude(doctor => doctor.Phones);
}
}
...@@ -24,10 +24,17 @@ public class EmployeesRepository : Repositroy<Employee>, IEmployeesRepository ...@@ -24,10 +24,17 @@ public class EmployeesRepository : Repositroy<Employee>, IEmployeesRepository
#region Get by serial Number #region Get by serial Number
public async Task<Result<Employee>> GetEmployeeBySerialNumberAsync(string serialNumber) public async Task<Result<Employee>> GetEmployeeBySerialNumberAsync(string serialNumber)
{ {
var all = await _context.Set<Employee>().Where(employee => employee.SerialNumber == serialNumber).ToListAsync(); var query = _context.Set<Employee>()
if (all.Count != 1) .Where(employee => employee.SerialNumber == serialNumber)
return Result.Failure<Employee>(PersistenceErrors.NotFound); .Include(employee => employee.Patient)
return Result.Success(all.First()); .ThenInclude(patient => patient.PersonalInfo)
.Include(employee => employee.Patient)
.ThenInclude(patient => patient.Gender);
var result = await query.ToListAsync();
if (result.Count != 1)
return Result.Failure<Employee>(DomainErrors.SerialNumberNotFound);
return Result.Success(result.First());
} }
#endregion #endregion
} }
using Domain.Entities.People.Patients; using Domain.Entities.People.Employees;
using Domain.Entities.People.FamilyMembers;
using Domain.Entities.People.Patients;
using Domain.Errors; using Domain.Errors;
using Domain.Repositories; using Domain.Repositories;
using Domain.Shared; using Domain.Shared;
...@@ -47,5 +49,101 @@ public class PatientsRepository : Repositroy<Patient>, IPatientsRepository ...@@ -47,5 +49,101 @@ public class PatientsRepository : Repositroy<Patient>, IPatientsRepository
} }
#endregion #endregion
#region Create operation
public override Task<Result<Patient>> CreateAsync(Patient entity)
{
_context.Entry(entity.Gender).State = EntityState.Unchanged;
return base.CreateAsync(entity);
}
#endregion
#region IsEmployee
public async Task<Result<bool>> IsEmployeeByIdAsync(int id)
{
try
{
var query = _context.Set<Employee>()
.Where(employee => employee.Id == id);
var result = await query.ToListAsync();
return result.Count == 1;
}
catch (Exception)
{
return Result.Failure<bool>(PersistenceErrors.NotFound);
}
}
public async Task<Result<Employee>> GetEmployeeByIdAsync(int id)
{
try
{
var query = _context.Set<Employee>()
.Where(employee => employee.Id == id) // Note that this is only one row
.Include(employee => employee.Patient) // so, join is effecient
.ThenInclude(patient => patient.PersonalInfo)
.Include(employee => employee.Patient)
.ThenInclude(patient => patient.Gender)
.Include(employee => employee.Patient)
.ThenInclude(patient => patient.Diseases)
.Include(employee => employee.Patient)
.ThenInclude(patient => patient.Medicines)
.Include(employee => employee.Patient)
.ThenInclude(patient => patient.Visits)
.Include(employee => employee.AdditionalInfo)
.Include(employee => employee.FamilyMembers)
.Include(employee => employee.RelatedEmployees)
.Include(employee => employee.RelatedTo);
return await query.FirstAsync();
}
catch (Exception)
{
return Result.Failure<Employee>(PersistenceErrors.NotFound);
}
}
#endregion
#region FamilyMember
public async Task<Result<bool>> IsFamilyMemberByIdAsync(int id)
{
try
{
var query = _context.Set<FamilyMember>()
.Where(familyMember => familyMember.Id == id);
var result = await query.ToListAsync();
return result.Count == 1;
}
catch (Exception)
{
return Result.Failure<bool>(PersistenceErrors.NotFound);
}
}
public async Task<Result<FamilyMember>> GetFamilyMemberByIdAsync(int id)
{
try
{
var query = _context.Set<FamilyMember>()
.Where(familyMember => familyMember.Id == id) // Note that this is only one row
.Include(familyMember => familyMember.Patient) // so, join is effecient
.ThenInclude(patient => patient.PersonalInfo)
.Include(familyMember => familyMember.Patient)
.ThenInclude(patient => patient.Gender)
.Include(familyMember => familyMember.Patient)
.ThenInclude(patient => patient.Diseases)
.Include(familyMember => familyMember.Patient)
.ThenInclude(patient => patient.Medicines)
.Include(familyMember => familyMember.Patient)
.ThenInclude(patient => patient.Visits);
return await query.FirstAsync();
}
catch (Exception)
{
return Result.Failure<FamilyMember>(PersistenceErrors.NotFound);
}
}
#endregion
} }
using Domain.Entities.People.Employees;
using Domain.Entities.WaitingList;
using Domain.Errors;
using Domain.Repositories;
using Domain.Shared;
using Microsoft.EntityFrameworkCore;
using Persistence.Context;
using Persistence.Repositories.Base;
namespace Persistence.Repositories.WaitingList;
public class WaitingListRepository : Repositroy<WaitingListRecord>, IWaitingListRepository
{
#region CTOR DI
public WaitingListRepository(ClinicsDbContext context) : base(context)
{
}
#endregion
#region Read methods
public override async Task<Result<WaitingListRecord>> GetByIdAsync(int id)
{
try
{
var query = _context.Set<WaitingListRecord>()
.Where(waitingListRecord => waitingListRecord.Id == id)
.Include(witingListRecord => witingListRecord.Patient)
.ThenInclude(patient => patient.PersonalInfo)
.Include(witingListRecord => witingListRecord.Patient)
.ThenInclude(patient => patient.Gender);
return await query.FirstAsync();
}
catch (Exception)
{
return Result.Failure<WaitingListRecord>(PersistenceErrors.NotFound);
}
}
public override async Task<Result<ICollection<WaitingListRecord>>> GetAllAsync()
{
try
{
var query = _context.Set<WaitingListRecord>()
.Include(waitingListRecord => waitingListRecord.Patient)
.ThenInclude(patient => patient.PersonalInfo)
.Include(waitingListRecord => waitingListRecord.Patient)
.ThenInclude(patient => patient.Gender);
return await query.ToListAsync();
}
catch (Exception)
{
return Result.Failure<ICollection<WaitingListRecord>>(PersistenceErrors.Unknown);
}
}
#endregion
#region Is employee in list
public async Task<Result<bool>> IsEmployeeInWaitingListAsync(string serialNumber)
{
try
{
var employee = await _context.Set<Employee>()
.Where(employee => employee.SerialNumber == serialNumber)
.FirstAsync();
var query = _context.Set<WaitingListRecord>()
.Where(waitingListRecord => waitingListRecord.PatientId == employee.Id);
var result = await query.ToListAsync();
return result.Count == 1;
}
catch (Exception)
{
return Result.Failure<bool>(PersistenceErrors.NotFound);
}
}
#endregion
}
using Application.Doctors.Queries.GetAllDoctors;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Presentation.Controllers.Base;
namespace Presentation.Controllers;
[Route("api/Doctors")]
public class DoctorsController : ApiController
{
#region DI for MeditR sender
public DoctorsController(ISender sender) : base(sender)
{
}
#endregion
//[Authorize(Roles = Roles.ReceptionistName)]
[HttpGet]
public async Task<IActionResult> GetAll()
{
var query = new GetAllDoctorsQuery();
var result = await _sender.Send(query);
if (result.IsFailure)
return HandleFailure(result);
return Ok(result.Value);
}
}
using Application.Employees.Commands.AttachFamilyMemberToEmployee; using Application.Employees.Commands.AttachFamilyMemberToEmployee;
using Application.Employees.Commands.CreateEmployee; using Application.Employees.Commands.CreateEmployee;
using Application.Employees.Queries.GetBySerialNumber;
using Domain.Entities.Identity.UserRoles; using Domain.Entities.Identity.UserRoles;
using MediatR; using MediatR;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
...@@ -18,7 +19,7 @@ public class EmployeesController : ApiController ...@@ -18,7 +19,7 @@ public class EmployeesController : ApiController
} }
#endregion #endregion
[Authorize(Roles = Roles.AdminName)] //[Authorize(Roles = Roles.ReceptionistName)]
[HttpPost] [HttpPost]
public async Task<IActionResult> Create([FromBody] CreateEmployeeCommand command) public async Task<IActionResult> Create([FromBody] CreateEmployeeCommand command)
{ {
...@@ -27,7 +28,18 @@ public class EmployeesController : ApiController ...@@ -27,7 +28,18 @@ public class EmployeesController : ApiController
return HandleFailure(result); return HandleFailure(result);
return Created(); return Created();
} }
[Authorize(Roles = Roles.DoctorName)]
//[Authorize(Roles = Roles.ReceptionistName)]
[HttpPost("SerialNumber")] // It's a get, but serial number shouldn't be sent via routing, so we'll use post
public async Task<IActionResult> GetBySerialNumber([FromBody] GetEmployeeBySerialNumberQuery query)
{
var result = await _sender.Send(query);
if (result.IsFailure)
return HandleFailure(result);
return Ok(result.Value);
}
//[Authorize(Roles = Roles.ReceptionistName)]
[HttpPut("FamilyMembers")] [HttpPut("FamilyMembers")]
public async Task<IActionResult> AttachFamilyMember([FromBody] AttachFamilyMemberToEmployeeCommand command) public async Task<IActionResult> AttachFamilyMember([FromBody] AttachFamilyMemberToEmployeeCommand command)
{ {
......
...@@ -39,7 +39,7 @@ public class UsersController : ApiController ...@@ -39,7 +39,7 @@ public class UsersController : ApiController
#endregion #endregion
#region Doctors #region Doctors
[Authorize(Roles = Roles.AdminName)] //[Authorize(Roles = Roles.AdminName)]
[HttpPost("Doctors")] [HttpPost("Doctors")]
public async Task<IActionResult> RegisterDoctor([FromBody] RegisterDoctorCommand command) public async Task<IActionResult> RegisterDoctor([FromBody] RegisterDoctorCommand command)
{ {
...@@ -51,7 +51,7 @@ public class UsersController : ApiController ...@@ -51,7 +51,7 @@ public class UsersController : ApiController
return Created(); return Created();
} }
[Authorize(Roles = Roles.AdminName)] //[Authorize(Roles = Roles.AdminName)]
[HttpGet("Doctors")] [HttpGet("Doctors")]
public async Task<IActionResult> GetAllDoctorUsers() public async Task<IActionResult> GetAllDoctorUsers()
{ {
...@@ -62,7 +62,7 @@ public class UsersController : ApiController ...@@ -62,7 +62,7 @@ public class UsersController : ApiController
return Ok(result.Value); return Ok(result.Value);
} }
[Authorize(Roles = Roles.AdminName)] //[Authorize(Roles = Roles.AdminName)]
[HttpGet("Doctors/{id:int}")] [HttpGet("Doctors/{id:int}")]
public async Task<IActionResult> GetDoctorUserById([FromRoute(Name ="id")] int id ) public async Task<IActionResult> GetDoctorUserById([FromRoute(Name ="id")] int id )
{ {
...@@ -73,7 +73,7 @@ public class UsersController : ApiController ...@@ -73,7 +73,7 @@ public class UsersController : ApiController
return Ok(result.Value); return Ok(result.Value);
} }
[Authorize(Roles = Roles.AdminName)] //[Authorize(Roles = Roles.AdminName)]
[HttpPut("Doctors")] [HttpPut("Doctors")]
public async Task<IActionResult> UpdateDoctorPersonalInfo([FromBody] UpdateDoctorPersonalInfoCommand command) public async Task<IActionResult> UpdateDoctorPersonalInfo([FromBody] UpdateDoctorPersonalInfoCommand command)
{ {
...@@ -83,7 +83,7 @@ public class UsersController : ApiController ...@@ -83,7 +83,7 @@ public class UsersController : ApiController
return Ok(); return Ok();
} }
[Authorize(Roles = Roles.AdminName)] //[Authorize(Roles = Roles.AdminName)]
[HttpPut("Doctors/Users")] [HttpPut("Doctors/Users")]
public async Task<IActionResult> UpdateDoctorUser([FromBody] UpdateDoctorUserCommand command) public async Task<IActionResult> UpdateDoctorUser([FromBody] UpdateDoctorUserCommand command)
{ {
...@@ -96,7 +96,7 @@ public class UsersController : ApiController ...@@ -96,7 +96,7 @@ public class UsersController : ApiController
#endregion #endregion
#region Receptionist #region Receptionist
[Authorize(Roles = Roles.AdminName)] //[Authorize(Roles = Roles.AdminName)]
[HttpPost("Receptionists")] [HttpPost("Receptionists")]
public async Task<IActionResult> RegisterReceptionist([FromBody] RegisterReceptionistCommand command) public async Task<IActionResult> RegisterReceptionist([FromBody] RegisterReceptionistCommand command)
{ {
...@@ -107,7 +107,7 @@ public class UsersController : ApiController ...@@ -107,7 +107,7 @@ public class UsersController : ApiController
return Created(); return Created();
} }
[Authorize(Roles = Roles.AdminName)] //[Authorize(Roles = Roles.AdminName)]
[HttpGet("Receptionists")] [HttpGet("Receptionists")]
public async Task<IActionResult> GetAllReceptionistUsers() public async Task<IActionResult> GetAllReceptionistUsers()
{ {
......
using Application.Employees.Commands.AttachFamilyMemberToEmployee;
using Application.Employees.Commands.CreateEmployee;
using Application.WaitingList.Commands.CreateWaitingListRecord;
using Application.WaitingList.Commands.DeleteWaitingListRecord;
using Application.WaitingList.Queries;
using Domain.Entities.Identity.UserRoles;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Presentation.Controllers.Base;
namespace Presentation.Controllers;
[Route("api/WaitingList")]
public class WaitingListController : ApiController
{
#region DI for MeditR sender
public WaitingListController(ISender sender) : base(sender)
{
}
#endregion
//[Authorize(Roles = Roles.ReceptionistName)]
[HttpPost]
public async Task<IActionResult> Create([FromBody] CreateWaitingListRecordCommand command)
{
var result = await _sender.Send(command);
if (result.IsFailure)
return HandleFailure(result);
return Created();
}
//[Authorize(Roles = Roles.ReceptionistName)]
[HttpGet]
public async Task<IActionResult> GetAll()
{
var query = new GetAllWaitingListRecordsQuery();
var result = await _sender.Send(query);
if (result.IsFailure)
return HandleFailure(result);
return Ok(result.Value);
}
//[Authorize(Roles = Roles.ReceptionistName)]
[HttpDelete("/{id:int}")]
public async Task<IActionResult> Delete([FromRoute(Name ="id")] int id)
{
var command = new DeleteWaitingListRecordCommand
{
Id = id
};
var result = await _sender.Send(command);
if (result.IsFailure)
return HandleFailure(result);
return Ok();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment