Skip to content

Commit

Permalink
chore: refactored the entity, Observable, ViewModel and Infrastructur…
Browse files Browse the repository at this point in the history
…e classes for performance and consistency

- Changed the Employee, Customer and ObservableCustomer model class's distinct FirstName, MiddleName, LastName to a single FullName field. This simplifies the model and aligns with some systems that store/display full names instead of individual name parts.

 - Removed redundant BSON reference tags.

- Switched to ConcurrentObservableCollection from ObservableCollection in all view models for better thread-safety and performance in multi-threaded scenarios.

- Introduced a new class MessageAggregator in Infrastructure layer for event publishing and subscription.

Signed-off-by: Russell Camo <[email protected]>
  • Loading branch information
russkyc committed Aug 28, 2023
1 parent 26d9b82 commit c8235d1
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 45 deletions.
9 changes: 1 addition & 8 deletions GroomWise.Application/Observables/ObservableCustomer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,9 @@ public partial class ObservableCustomer
{
[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
private Guid _id;
public string FullName => $"{FirstName} {LastName}";

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
private string _firstName;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
private string _middleName;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
private string _lastName;
private string _fullName;

[Property(PropertyChangeType = PropertyChangeType.PropertyChanged)]
private string _address;
Expand Down
13 changes: 8 additions & 5 deletions GroomWise.Application/ViewModels/AppointmentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using GroomWise.Infrastructure.Storage.Interfaces;
using Injectio.Attributes;
using MvvmGen;
using Swordfish.NET.Collections;

namespace GroomWise.Application.ViewModels;

Expand All @@ -26,14 +27,14 @@ public partial class AppointmentViewModel
private ObservableAppointment _activeAppointment;

[Property]
private ObservableCollection<ObservableAppointment> _appointments;
private ConcurrentObservableCollection<ObservableAppointment> _appointments;

[Property]
private ObservableCollection<ObservableGroomingService> _groomingServices;
private ConcurrentObservableCollection<ObservableGroomingService> _groomingServices;

partial void OnInitialize()
{
// PopulateCollections();
PopulateCollections();
}

private void PopulateCollections()
Expand All @@ -46,7 +47,9 @@ private void PopulateCollections()
.GetAll()
.Select(GroomingServiceMapper.ToObservable);

Appointments = new ObservableCollection<ObservableAppointment>(appointments);
GroomingServices = new ObservableCollection<ObservableGroomingService>(groomingServices);
Appointments = new ConcurrentObservableCollection<ObservableAppointment>(appointments);
GroomingServices = new ConcurrentObservableCollection<ObservableGroomingService>(
groomingServices
);
}
}
10 changes: 5 additions & 5 deletions GroomWise.Application/ViewModels/CustomerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using GroomWise.Infrastructure.Storage.Interfaces;
using Injectio.Attributes;
using MvvmGen;
using Swordfish.NET.Collections;

namespace GroomWise.Application.ViewModels;

Expand All @@ -26,23 +27,22 @@ public partial class CustomerViewModel
private ObservableCustomer _activeCustomer;

[Property]
private ObservableCollection<ObservableCustomer> _customers;
private ConcurrentObservableCollection<ObservableCustomer> _customers;

partial void OnInitialize()
{
// PopulateCollections();
PopulateCollections();
}

private void PopulateCollections()
{
var customers = GroomWiseDbContext!.Customers.GetAll().Select(CustomerMapper.ToObservable);
Customers = new ObservableCollection<ObservableCustomer>(customers);
Customers = new ConcurrentObservableCollection<ObservableCustomer>(customers);
}

private async Task CreateCustomer()
{
ActiveCustomer = new();
await Task.CompletedTask;
await Task.Run(() => ActiveCustomer = new());
}

[Command]
Expand Down
8 changes: 0 additions & 8 deletions GroomWise.Domain/Entities/Appointment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,8 @@ public class Appointment : IEntity
public Guid Id { get; set; }
public DateTime? Date { get; set; }
public AppointmentStatus? Status { get; set; }

[BsonRef("groomingServices")]
public GroomingService? Service { get; set; }

[BsonRef("pets")]
public Pet? Pet { get; set; }

[BsonRef("customers")]
public Customer? Customer { get; set; }

[BsonRef("employees")]
public IList<Employee>? Employees { get; set; }
}
11 changes: 1 addition & 10 deletions GroomWise.Domain/Entities/Customer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,10 @@ namespace GroomWise.Domain.Entities;
public class Customer : IEntity
{
public Guid Id { get; set; }

public string? Prefix { get; set; }
public string? FirstName { get; set; }
public string? MiddleName { get; set; }
public string? LastName { get; set; }
public string? Suffix { get; set; }
public string? FullName { get; set; }
public string? Address { get; set; }
public string? ContactNumber { get; set; }
public string? Email { get; set; }

[BsonRef("pets")]
public IList<Pet>? Pets { get; set; }

[BsonRef("appointments")]
public IList<Appointment>? Appointments { get; set; }
}
8 changes: 1 addition & 7 deletions GroomWise.Domain/Entities/Employee.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@ public record Employee : IEntity
public Guid Id { get; set; }

public string? Prefix { get; set; }
public string? FirstName { get; set; }
public string? MiddleName { get; set; }
public string? LastName { get; set; }
public string? FullName { get; set; }
public string? Suffix { get; set; }
public string? Address { get; set; }
public string? ContactNumber { get; set; }
public string? Email { get; set; }

[BsonRef("pets")]
public IList<Pet>? Pets { get; set; }

[BsonRef("appointments")]
public IList<Appointment>? Appointments { get; set; }
}
2 changes: 0 additions & 2 deletions GroomWise.Domain/Entities/Pet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@ public class Pet : IEntity
public int? Age { get; set; }
public string? Breed { get; set; }
public int? Gender { get; set; }

[BsonRef("customers")]
public IList<Customer> Owner { get; set; }

Check warning on line 18 in GroomWise.Domain/Entities/Pet.cs

View workflow job for this annotation

GitHub Actions / build (Debug)

Non-nullable property 'Owner' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.

Check warning on line 18 in GroomWise.Domain/Entities/Pet.cs

View workflow job for this annotation

GitHub Actions / build (Release)

Non-nullable property 'Owner' must contain a non-null value when exiting constructor. Consider declaring the property as nullable.
}
6 changes: 6 additions & 0 deletions GroomWise.Infrastructure/GroomWise.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
<PackageReference Include="LiteDB" Version="5.0.17" />
<PackageReference Include="Lombok.NET" Version="2.1.3" />
<PackageReference Include="Mapster" Version="7.3.0" />
<PackageReference Include="MvvmGen.PureCodeGeneration" Version="1.2.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NETCore.Encrypt" Version="2.1.1" />
<PackageReference Include="Russkyc.Configuration" Version="1.0.0" />
<PackageReference Include="Russkyc.DependencyInjection" Version="2.1.0" />
Expand All @@ -36,6 +40,8 @@





</ItemGroup>


Expand Down
12 changes: 12 additions & 0 deletions GroomWise.Infrastructure/Messaging/MessageAggregator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (C) 2023 Russell Camo (Russkyc).- All Rights Reserved
//
// Unauthorized copying or redistribution of all files, in source and binary forms via any medium
// without written, signed consent from the author is strictly prohibited.

using Injectio.Attributes;
using MvvmGen.Events;

namespace GroomWise.Infrastructure.Messaging;

[RegisterSingleton<IEventAggregator, MessageAggregator>]
public class MessageAggregator : EventAggregator { }

0 comments on commit c8235d1

Please sign in to comment.