Skip to content

Commit

Permalink
chore: update various aspects of the application for better maintaina…
Browse files Browse the repository at this point in the history
…bility

- Issues of navigating through different views (pages) of the application have been addressed in "AppViewModel.cs".

- For the "IAuthenticationService.cs" file, functions 'Register' and 'Update' have been revamped to include an additional parameter 'roles'.

- Registered "AccountViewModel.cs", "InventoryViewModel.cs", "PetViewModel.cs", "CustomerViewModel.cs", "EmployeeViewModel.cs", "GroomingServiceViewModel.cs" to IoC container.

Signed-off-by: Russell Camo <[email protected]>
  • Loading branch information
russkyc committed Aug 28, 2023
1 parent 0e1a8a4 commit 1e31cf4
Show file tree
Hide file tree
Showing 24 changed files with 241 additions and 97 deletions.
3 changes: 1 addition & 2 deletions GroomWise.Application/Enums/AppViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ namespace GroomWise.Application.Enums;
public enum AppViews
{
Login,
Main,
Dashboard
Main
}
20 changes: 18 additions & 2 deletions GroomWise.Application/ViewModels/AppViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using GroomWise.Domain.Enums;
using GroomWise.Infrastructure.Authentication.Enums;
using GroomWise.Infrastructure.Authentication.Interfaces;
using GroomWise.Infrastructure.IoC.Interfaces;
using GroomWise.Infrastructure.Navigation.Interfaces;
using Injectio.Attributes;
using MvvmGen;
Expand All @@ -17,9 +18,9 @@ namespace GroomWise.Application.ViewModels;
[Inject(typeof(IAuthenticationService))]
[Inject(typeof(IDialogFactory))]
[Inject(typeof(INavigationService))]
[Inject(typeof(IAppServicesContainer))]
[Inject(typeof(DashboardViewModel))]
[ViewModel]
[ViewModelGenerateInterface]
[RegisterSingleton]
public partial class AppViewModel
{
Expand Down Expand Up @@ -50,12 +51,27 @@ private async Task Logout()
{
var result = AuthenticationService.Logout();
await Task.Delay(500);
await Task.Delay(300);
if (result.Equals(AuthenticationStatus.NotAuthenticated))
{
NavigationService.Navigate(AppViews.Login);
}
}
});
}

[Command]
private async Task NavigateToPage(object param)
{
await Task.Run(() =>
{
if (param is Type type)
{
if (AppServicesContainer.GetService(type) is ViewModelBase viewModel)
{
PageContext = viewModel;
}
}
});
}
}
4 changes: 3 additions & 1 deletion GroomWise.Application/ViewModels/AppointmentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using GroomWise.Infrastructure.Database;
using GroomWise.Infrastructure.Logging.Interfaces;
using GroomWise.Infrastructure.Storage.Interfaces;
using Injectio.Attributes;
using MvvmGen;

namespace GroomWise.Application.ViewModels;
Expand All @@ -18,6 +19,7 @@ namespace GroomWise.Application.ViewModels;
[Inject(typeof(ILogger))]
[Inject(typeof(IFileStorage))]
[Inject(typeof(GroomWiseDbContext))]
[RegisterSingleton]
public partial class AppointmentViewModel
{
[Property]
Expand All @@ -31,7 +33,7 @@ public partial class AppointmentViewModel

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

private void PopulateCollections()
Expand Down
5 changes: 3 additions & 2 deletions GroomWise.Application/ViewModels/CustomerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
using System.Collections.ObjectModel;
using GroomWise.Application.Mappers;
using GroomWise.Application.Observables;
using GroomWise.Domain.Entities;
using GroomWise.Infrastructure.Database;
using GroomWise.Infrastructure.Logging.Interfaces;
using GroomWise.Infrastructure.Storage.Interfaces;
using Injectio.Attributes;
using MvvmGen;

namespace GroomWise.Application.ViewModels;
Expand All @@ -19,6 +19,7 @@ namespace GroomWise.Application.ViewModels;
[Inject(typeof(ILogger))]
[Inject(typeof(IFileStorage))]
[Inject(typeof(GroomWiseDbContext))]
[RegisterSingleton]
public partial class CustomerViewModel
{
[Property]
Expand All @@ -29,7 +30,7 @@ public partial class CustomerViewModel

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

private void PopulateCollections()
Expand Down
1 change: 0 additions & 1 deletion GroomWise.Application/ViewModels/DashboardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
namespace GroomWise.Application.ViewModels;

[ViewModel]
[ViewModelGenerateInterface]
[RegisterSingleton]
public partial class DashboardViewModel { }
12 changes: 7 additions & 5 deletions GroomWise.Application/ViewModels/EmployeeViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// 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;

namespace GroomWise.Application.ViewModels;

public class EmployeeViewModel
{

}
[ViewModel]
[RegisterSingleton]
public partial class EmployeeViewModel { }
12 changes: 7 additions & 5 deletions GroomWise.Application/ViewModels/GroomingServiceViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// 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;

namespace GroomWise.Application.ViewModels;

public class GroomingServiceViewModel
{

}
[ViewModel]
[RegisterSingleton]
public partial class GroomingServiceViewModel { }
12 changes: 7 additions & 5 deletions GroomWise.Application/ViewModels/InventoryViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// 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;

namespace GroomWise.Application.ViewModels;

public class InventoryViewModel
{

}
[ViewModel]
[RegisterSingleton]
public partial class InventoryViewModel { }
4 changes: 2 additions & 2 deletions GroomWise.Application/ViewModels/LoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ private async Task Login()
}
);
Username = string.Empty;
Password = string.Empty;
Username = string.Empty;
await Task.Delay(1000);
await Task.Delay(300);
Notifications.RemoveLast();
NavigationService.Navigate(AppViews.Main);
});
Expand Down
12 changes: 7 additions & 5 deletions GroomWise.Application/ViewModels/PetViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// 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;

namespace GroomWise.Application.ViewModels;

public class PetViewModel
{

}
[ViewModel]
[RegisterSingleton]
public partial class PetViewModel { }
13 changes: 13 additions & 0 deletions GroomWise.Application/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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;

namespace GroomWise.Application.ViewModels;

[ViewModel]
[RegisterSingleton]
public partial class SettingsViewModel { }
23 changes: 19 additions & 4 deletions GroomWise.Infrastructure/Authentication/AuthenticationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,18 @@ public AuthenticationService(GroomWiseDbContext dbContext, IEncryptionService en
public void Register(
string username,
string password,
Role role = Role.User,
Guid? employeeId = null
Guid? employeeId = null,
params Role[] roles
)
{
var account = new Account();
account.Username = _encryptionService.Hash(username);
account.Password = _encryptionService.Hash(password);
account.Roles.Add(role);

foreach (var role in roles)
{
account.Roles.Add(role);
}

if (employeeId is not null)
{
Expand All @@ -53,6 +57,11 @@ public AuthenticationService(GroomWiseDbContext dbContext, IEncryptionService en
_dbContext.Accounts.Insert(account);
}

public void Register(string username, string password, params Role[] roles)
{
Register(username, password, null, roles);
}

public AuthenticationStatus Login(string username, string password)
{
var account = _dbContext.Accounts.Get(
Expand Down Expand Up @@ -80,7 +89,8 @@ public AuthenticationStatus Login(string username, string password)
string username,
string password,
string newUsername,
string newPassword
string newPassword,
params Role[] roles
)
{
var account = _dbContext.Accounts.Get(
Expand Down Expand Up @@ -111,6 +121,11 @@ string newPassword
return UpdateStatus.Success;
}

foreach (var role in roles)
{
account.Roles.Add(role);
}

return UpdateStatus.Fail;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,23 @@ namespace GroomWise.Infrastructure.Authentication.Interfaces;

public interface IAuthenticationService
{
void Register(string username, string password, Role role = Role.User, Guid? employeeId = null);
void Register(
string username,
string password,
Guid? employeeId = null,
params Role[] roles
);

void Register(string username, string password, params Role[] roles);
AuthenticationStatus Login(string username, string password);

UpdateStatus Update(string username, string password, string newUsername, string newPassword);
UpdateStatus Update(
string username,
string password,
string newUsername,
string newPassword,
params Role[] roles
);

AuthenticationStatus Logout();
SessionInfo? GetSession();
Expand Down
4 changes: 4 additions & 0 deletions GroomWise.Infrastructure/GroomWise.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@

<ItemGroup>
<None Remove=".env" />




</ItemGroup>


Expand Down
31 changes: 31 additions & 0 deletions GroomWise.Infrastructure/IoC/AppServicesContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 GroomWise.Infrastructure.IoC.Interfaces;
using Injectio.Attributes;
using Microsoft.Extensions.DependencyInjection;

namespace GroomWise.Infrastructure.IoC;

[RegisterSingleton<IAppServicesContainer, AppServicesContainer>]
public class AppServicesContainer : IAppServicesContainer
{
private IServiceProvider? _serviceProvider;

public void AddContainer(IServiceProvider container)
{
_serviceProvider = container;
}

public T? GetService<T>()
{
return _serviceProvider!.GetService<T>();
}

public object? GetService(Type type)
{
return _serviceProvider!.GetService(type);
}
}
13 changes: 13 additions & 0 deletions GroomWise.Infrastructure/IoC/Interfaces/IAppServicesContainer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

namespace GroomWise.Infrastructure.IoC.Interfaces;

public interface IAppServicesContainer
{
void AddContainer(IServiceProvider container);
T? GetService<T>();
object? GetService(Type type);
}
5 changes: 2 additions & 3 deletions GroomWise.Infrastructure/Logging/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
// without written, signed consent from the author is strictly prohibited.

using GroomWise.Infrastructure.Logging.Interfaces;
using Russkyc.DependencyInjection.Attributes;
using Russkyc.DependencyInjection.Enums;
using Injectio.Attributes;

namespace GroomWise.Infrastructure.Logging;

[Service(Scope.Singleton, Registration.AsInterfaces)]
[RegisterSingleton<ILogger, ConsoleLogger>]
public class ConsoleLogger : ILogger
{
public void Log(string message, string? sender = null)
Expand Down
Loading

0 comments on commit 1e31cf4

Please sign in to comment.