Skip to content

Commit

Permalink
formatting and TODO updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalis committed Apr 27, 2021
1 parent dfbb7ce commit 7c75e26
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@ public class CreateClientRequest : BaseRequest
public string Salutation { get; set; }
public string PreferredName { get; set; }
public int? PreferredDoctorId { get; set; }

//TODO: need to check
//public IList<int> Patients { get; set; } = new List<int>();
}
}
23 changes: 8 additions & 15 deletions FrontDesk/src/FrontDesk.Api/Endpoints/Appointment/Create.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ public class Create : BaseAsyncEndpoint
{
private readonly IRepository<Schedule> _scheduleRepository;
private readonly IReadRepository<Schedule> _scheduleReadRepository;
private readonly IReadRepository<AppointmentType> _appointmentTypeRepository;
private readonly IReadRepository<AppointmentType> _appointmentTypeReadRepository;
private readonly IMapper _mapper;
private readonly ILogger<Create> _logger;

public Create(IRepository<Schedule> scheduleRepository,
IReadRepository<Schedule> scheduleReadRepository,
IReadRepository<AppointmentType> appointmentTypeRepository,
IReadRepository<AppointmentType> appointmentTypeReadRepository,
IMapper mapper,
ILogger<Create> logger)
{
_scheduleRepository = scheduleRepository;
_scheduleReadRepository = scheduleReadRepository;
_appointmentTypeRepository = appointmentTypeRepository;
_appointmentTypeReadRepository = appointmentTypeReadRepository;
_mapper = mapper;
_logger = logger;
}
Expand All @@ -46,31 +46,24 @@ public Create(IRepository<Schedule> scheduleRepository,
OperationId = "appointments.create",
Tags = new[] { "AppointmentEndpoints" })
]
public override async Task<ActionResult<CreateAppointmentResponse>> HandleAsync(CreateAppointmentRequest request, CancellationToken cancellationToken)
public override async Task<ActionResult<CreateAppointmentResponse>> HandleAsync(CreateAppointmentRequest request,
CancellationToken cancellationToken)
{
var response = new CreateAppointmentResponse(request.CorrelationId());

var spec = new ScheduleByIdWithAppointmentsSpec(request.ScheduleId); // TODO: Just get that day's appointments
var schedule = await _scheduleReadRepository.GetBySpecAsync(spec);

var appointmentType = await _appointmentTypeRepository.GetByIdAsync(request.AppointmentTypeId);
var appointmentType = await _appointmentTypeReadRepository.GetByIdAsync(request.AppointmentTypeId);
var appointmentStart = request.DateOfAppointment;
var timeRange = new DateTimeOffsetRange(appointmentStart, TimeSpan.FromMinutes(appointmentType.Duration));

var newAppointment = new Appointment(Guid.NewGuid(), request.AppointmentTypeId, request.ScheduleId, request.ClientId, request.SelectedDoctor, request.PatientId, request.RoomId, timeRange, request.Title);

newAppointment.Id = Guid.NewGuid();
var newAppointment = new Appointment(Guid.NewGuid(), request.AppointmentTypeId, request.ScheduleId,
request.ClientId, request.SelectedDoctor, request.PatientId, request.RoomId, timeRange, request.Title);

schedule.AddNewAppointment(newAppointment);

int conflictedAppointmentsCount = schedule.Appointments
.Count(a => a.IsPotentiallyConflicting);
_logger.LogInformation($"There are now {conflictedAppointmentsCount} conflicted appointments.");

_logger.LogDebug($"Adding appointment to schedule. Total appointments: {schedule.Appointments.Count()}");

await _scheduleRepository.UpdateAsync(schedule);

_logger.LogInformation($"Appointment created for patient {request.PatientId} with Id {newAppointment.Id}");

var dto = _mapper.Map<AppointmentDto>(newAppointment);
Expand Down
3 changes: 2 additions & 1 deletion FrontDesk/src/FrontDesk.Api/Endpoints/Appointment/Update.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public override async Task<ActionResult<UpdateAppointmentResponse>> HandleAsync(
var spec = new ScheduleByIdWithAppointmentsSpec(request.ScheduleId); // TODO: Just get that day's appointments
var schedule = await _scheduleReadRepository.GetBySpecAsync(spec);

var apptToUpdate = schedule.Appointments.FirstOrDefault(a => a.Id == request.Id);
var apptToUpdate = schedule.Appointments
.FirstOrDefault(a => a.Id == request.Id);
apptToUpdate.UpdateAppointmentType(apptType);
apptToUpdate.UpdateRoom(request.RoomId);
apptToUpdate.UpdateStartTime(request.Start, schedule.AppointmentUpdatedHandler);
Expand Down
2 changes: 1 addition & 1 deletion FrontDesk/src/FrontDesk.Api/Endpoints/Client/GetById.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override async Task<ActionResult<GetByIdClientResponse>> HandleAsync([Fro
{
var response = new GetByIdClientResponse(request.CorrelationId());

// TODO: Use specification
// TODO: Use specification and consider including patients
var client = await _repository.GetByIdAsync(request.ClientId);
if (client is null) return NotFound();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public class AuthorizationConstants
{
// TODO: Change this to an environment variable
// NOTE: Use an environment variable in a production app
public const string JWT_SECRET_KEY = "SecretKeyOfDoomThatMustBeAMinimumNumberOfBytes";
}
}
2 changes: 0 additions & 2 deletions FrontDesk/src/FrontDesk.Core/ScheduleAggregate/Schedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public Appointment AddNewAppointment(Appointment appointment)
return appointment;
}



public void DeleteAppointment(Appointment appointment)
{
Guard.Against.Null(appointment, nameof(appointment));
Expand Down
3 changes: 2 additions & 1 deletion FrontDesk/src/FrontDesk.Infrastructure/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
}

// TODO: Use event handler
// TODO: Use DbContext.SavedChanges event and handler to support events
// https://docs.microsoft.com/en-us/ef/core/logging-events-diagnostics/events
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken())
{
int result = await base.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
Expand Down

0 comments on commit 7c75e26

Please sign in to comment.