Skip to content

Commit

Permalink
Clean Code and minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ruisantos committed Feb 19, 2023
1 parent 9cffdf7 commit da58bd9
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 41 deletions.
6 changes: 3 additions & 3 deletions RuiSantos.ZocDoc.Api/Contracts/AppointmentContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class AppointmentContract

public AppointmentContract()
{
this.MedicalLicense = string.Empty;
this.PatientSecuritySocialNumber = string.Empty;
this.Date = DateTime.MinValue;
MedicalLicense = string.Empty;
PatientSecuritySocialNumber = string.Empty;
Date = DateTime.MinValue;
}
}
8 changes: 4 additions & 4 deletions RuiSantos.ZocDoc.Api/Contracts/PatientAppointmentsContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ public class PatientAppointmentsContract

public PatientAppointmentsContract()
{
this.Doctor = new DoctorContract();
this.Date = DateTime.Now;
Doctor = new DoctorContract();
Date = DateTime.Now;
}

public PatientAppointmentsContract(Doctor doctor, DateTime date)
{
this.Doctor = new DoctorContract(doctor);
this.Date = date;
Doctor = new DoctorContract(doctor);
Date = date;
}
}
2 changes: 1 addition & 1 deletion RuiSantos.ZocDoc.Api/Controllers/SpecialtiesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SpecialtiesController(MedicalSpecialtiesManagement management)
/// <response code="404">No medical specialties found.</response>
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<ActionResult<IEnumerable<string>>> GetAsync()
{
var result = await management.GetMedicalSpecialitiesAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace RuiSantos.ZocDoc.Api.Core;

internal class ReApplyOptionalRouteParameterOperationFilter : IOperationFilter
{
const string captureName = "routeParameter";
private const string captureName = "routeParameter";

public void Apply(OpenApiOperation operation, OperationFilterContext context)
{
Expand Down
2 changes: 1 addition & 1 deletion RuiSantos.ZocDoc.Core.Tests/Core/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ internal static class TaskExtensions
public static async Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> enumerable)
{
var result = new List<T>();
await foreach (var item in enumerable) result.Add(item);
await foreach (var item in enumerable) result.Add(item);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace RuiSantos.ZocDoc.Core.Tests.Factories;

internal static class AppointmentsFactory
{
static readonly DateTime StartTime = new(2022, 1, 3, 8, 0, 0);
private static readonly DateTime StartTime = new(2022, 1, 3, 8, 0, 0);
public static IEnumerable<Appointment> Create(int elements = 1)
=> Enumerable.Range(0, elements).Select(i => new Appointment(StartTime.AddHours(i)));
}
4 changes: 2 additions & 2 deletions RuiSantos.ZocDoc.Core.Tests/Factories/DoctorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public static Doctor SetSpecialties(this Doctor doctor, params string[] specialt
public static Doctor SetOfficeHours(this Doctor doctor, params OfficeHour[] officeHours)
{
doctor.OfficeHours.Clear();

if (officeHours.Any())
doctor.OfficeHours.AddRange(officeHours);

return doctor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace RuiSantos.ZocDoc.Core.Tests;
public class MedicalSpecialtiesManagementTests
{
private readonly Mock<IDataContext> mockDataContext = new();
private readonly Mock<ILogger<MedicalSpecialtiesManagement>> mockLogger = new( );
private readonly Mock<ILogger<MedicalSpecialtiesManagement>> mockLogger = new();

[Fact]
public async Task CreateMedicalSpecialtiesAsync_WithValidInput_ShouldStoreMedicalSpecialties()
Expand Down
2 changes: 1 addition & 1 deletion RuiSantos.ZocDoc.Core/Data/IDataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace RuiSantos.ZocDoc.Core.Data;

public interface IDataContext
{
{
Task<bool> ExistsAsync<TModel>(Expression<Func<TModel, bool>> expression);
Task<TModel?> FindAsync<TModel>(Guid id);
Task<TModel?> FindAsync<TModel>(Expression<Func<TModel, bool>> expression);
Expand Down
4 changes: 4 additions & 0 deletions RuiSantos.ZocDoc.Core/Managers/AppointmentManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public async Task DeleteAppointmentAsync(string socialNumber, string medicalLice
if (doctor.Appointments.RemoveAll(app => app.Id == appointment.Id) > 0)
await context.StoreAsync(doctor);
}
catch (ValidationFailException)
{
throw;
}
catch (Exception ex)
{
logger?.LogException(nameof(AppointmentManagement), nameof(DeleteAppointmentAsync), ex);
Expand Down
4 changes: 2 additions & 2 deletions RuiSantos.ZocDoc.Core/Models/Appointment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ public class Appointment
{
public Guid Id { get; }
public DayOfWeek Week { get; set; }
public DateOnly Date { get; set; }
public TimeSpan Time { get; set; }
public DateOnly Date { get; set; }
public TimeSpan Time { get; set; }

public Appointment()
{
Expand Down
20 changes: 10 additions & 10 deletions RuiSantos.ZocDoc.Core/Models/MedicalSpeciality.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ public class MedicalSpeciality
public Guid Id { get; }
public string Description { get; set; }

public MedicalSpeciality()
{
this.Id = Guid.NewGuid();
this.Description = String.Empty;
}
public MedicalSpeciality()
{
Id = Guid.NewGuid();
Description = String.Empty;
}

public MedicalSpeciality(string description)
{
this.Id = Guid.NewGuid();
this.Description = description;
}
public MedicalSpeciality(string description)
{
Id = Guid.NewGuid();
Description = description;
}
}

4 changes: 2 additions & 2 deletions RuiSantos.ZocDoc.Core/Models/OfficeHour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ public class OfficeHour

public OfficeHour()
{
this.Week = DayOfWeek.Monday;
this.Hours = Enumerable.Empty<TimeSpan>();
Week = DayOfWeek.Monday;
Hours = Enumerable.Empty<TimeSpan>();
}

public OfficeHour(DayOfWeek week, IEnumerable<TimeSpan> hours)
Expand Down
22 changes: 11 additions & 11 deletions RuiSantos.ZocDoc.Core/Models/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

public class Person
{
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public IEnumerable<string> ContactNumbers { get; set; }
public string Email { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public IEnumerable<string> ContactNumbers { get; set; }

public Person()
{
this.FirstName = string.Empty;
this.LastName = string.Empty;
this.Email = string.Empty;
this.ContactNumbers = Enumerable.Empty<string>();
}
public Person()
{
FirstName = string.Empty;
LastName = string.Empty;
Email = string.Empty;
ContactNumbers = Enumerable.Empty<string>();
}

public Person(string email, string firstName, string lastName, IEnumerable<string> contactNumbers)
{
Expand Down
2 changes: 1 addition & 1 deletion RuiSantos.ZocDoc.Data.Mongodb/MongoContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public MongoContext(string connectionString)
{
var mongoUrl = MongoUrl.Create(connectionString);
var client = new MongoClient(mongoUrl);
this.database = client.GetDatabase(mongoUrl.DatabaseName);
database = client.GetDatabase(mongoUrl.DatabaseName);

Mediator.RegisterClassMaps();
}
Expand Down

0 comments on commit da58bd9

Please sign in to comment.