Skip to content

Commit

Permalink
refactor: use generic repository implementation
Browse files Browse the repository at this point in the history
Signed-off-by: russkyc <[email protected]>
  • Loading branch information
russkyc committed Jun 11, 2023
1 parent b10d06a commit 6e48466
Show file tree
Hide file tree
Showing 22 changed files with 73 additions and 290 deletions.
2 changes: 1 addition & 1 deletion Russkyc.GroomWise/Models/Abstractions/Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace GroomWise.Models.Abstractions;

public abstract class Repository<T> : Interfaces.Repository.IRepository<T>
public class Repository<T> : Interfaces.Repository.IRepository<T>
where T : class, IEquatable<T>, new()
{
private readonly IDatabaseServiceAsync _databaseService;
Expand Down
36 changes: 18 additions & 18 deletions Russkyc.GroomWise/Models/Interfaces/Service/IUnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,92 +13,92 @@ public interface IUnitOfWork
/// <summary>
/// Gets the repository for managing accounts.
/// </summary>
AccountRepository AccountsRepository { get; }
Repository<Account> AccountsRepository { get; }

/// <summary>
/// Gets the repository for managing addresses.
/// </summary>
AddressRepository AddressRepository { get; }
Repository<Address> AddressRepository { get; }

/// <summary>
/// Gets the repository for managing appointment employees.
/// </summary>
AppointmentEmployeeRepository AppointmentEmployeeRepository { get; }
Repository<AppointmentEmployee> AppointmentEmployeeRepository { get; }

/// <summary>
/// Gets the repository for managing appointment pets.
/// </summary>
AppointmentPetRepository AppointmentPetRepository { get; }
Repository<AppointmentPet> AppointmentPetRepository { get; }

/// <summary>
/// Gets the repository for managing appointments.
/// </summary>
AppointmentRepository AppointmentRepository { get; }
Repository<Appointment> AppointmentRepository { get; }

/// <summary>
/// Gets the repository for managing appointment service products.
/// </summary>
AppointmentServiceProductRepository AppointmentServiceProductRepository { get; }
Repository<AppointmentServiceProduct> AppointmentServiceProductRepository { get; }

/// <summary>
/// Gets the repository for managing appointment services.
/// </summary>
AppointmentServiceRepository AppointmentServiceRepository { get; }
Repository<AppointmentService> AppointmentServiceRepository { get; }

/// <summary>
/// Gets the repository for managing customer addresses.
/// </summary>
CustomerAddressRepository CustomerAddressRepository { get; }
Repository<CustomerAddress> CustomerAddressRepository { get; }

/// <summary>
/// Gets the repository for managing customer pets.
/// </summary>
CustomerPetRepository CustomerPetRepository { get; }
Repository<CustomerPet> CustomerPetRepository { get; }

/// <summary>
/// Gets the repository for managing customers.
/// </summary>
CustomerRepository CustomerRepository { get; }
Repository<Customer> CustomerRepository { get; }

/// <summary>
/// Gets the repository for managing employee accounts.
/// </summary>
EmployeeAccountRepository EmployeeAccountRepository { get; }
Repository<EmployeeAccount> EmployeeAccountRepository { get; }

/// <summary>
/// Gets the repository for managing employee addresses.
/// </summary>
EmployeeAddressRepository EmployeeAddressRepository { get; }
Repository<EmployeeAddress> EmployeeAddressRepository { get; }

/// <summary>
/// Gets the repository for managing employees.
/// </summary>
EmployeeRepository EmployeeRepository { get; }
Repository<Employee> EmployeeRepository { get; }

/// <summary>
/// Gets the repository for managing employee roles.
/// </summary>
EmployeeRoleRepository EmployeeRoleRepository { get; }
Repository<EmployeeRole> EmployeeRoleRepository { get; }

/// <summary>
/// Gets the repository for managing grooming services.
/// </summary>
GroomingServiceRepository GroomingServiceRepository { get; }
Repository<GroomingService> GroomingServiceRepository { get; }

/// <summary>
/// Gets the repository for managing pets.
/// </summary>
PetRepository PetRepository { get; }
Repository<Pet> PetRepository { get; }

/// <summary>
/// Gets the repository for managing products.
/// </summary>
ProductRepository ProductRepository { get; }
Repository<Product> ProductRepository { get; }

/// <summary>
/// Gets the repository for managing roles.
/// </summary>
RoleRepository RoleRepository { get; }
Repository<Role> RoleRepository { get; }

/// <summary>
/// Saves all changes made in this context to the underlying database.
Expand Down
107 changes: 54 additions & 53 deletions Russkyc.GroomWise/Services/Data/UnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,114 +15,115 @@ public UnitOfWork(IDatabaseServiceAsync databaseService)
_databaseService = databaseService;
}

private AccountRepository? _accountsRepository;
private Repository<Account>? _accountsRepository;

/// <inheritdoc />
public AccountRepository AccountsRepository =>
_accountsRepository ??= new AccountRepository(_databaseService);
public Repository<Account> AccountsRepository =>
_accountsRepository ??= new Repository<Account>(_databaseService);

private AddressRepository? _addressRepository;
private Repository<Address>? _addressRepository;

/// <inheritdoc />
public AddressRepository AddressRepository =>
_addressRepository ??= new AddressRepository(_databaseService);
public Repository<Address> AddressRepository =>
_addressRepository ??= new Repository<Address>(_databaseService);

private AppointmentEmployeeRepository? _appointmentEmployeeRepository;
private Repository<AppointmentEmployee>? _appointmentEmployeeRepository;

/// <inheritdoc />
public AppointmentEmployeeRepository AppointmentEmployeeRepository =>
_appointmentEmployeeRepository ??= new AppointmentEmployeeRepository(_databaseService);
public Repository<AppointmentEmployee> AppointmentEmployeeRepository =>
_appointmentEmployeeRepository ??= new Repository<AppointmentEmployee>(_databaseService);

private AppointmentPetRepository? _appointmentPetRepository;
private Repository<AppointmentPet>? _appointmentPetRepository;

/// <inheritdoc />
public AppointmentPetRepository AppointmentPetRepository =>
_appointmentPetRepository ??= new AppointmentPetRepository(_databaseService);
public Repository<AppointmentPet> AppointmentPetRepository =>
_appointmentPetRepository ??= new Repository<AppointmentPet>(_databaseService);

private AppointmentRepository? _appointmentRepository;
private Repository<Appointment>? _appointmentRepository;

/// <inheritdoc />
public AppointmentRepository AppointmentRepository =>
_appointmentRepository ??= new AppointmentRepository(_databaseService);
public Repository<Appointment> AppointmentRepository =>
_appointmentRepository ??= new Repository<Appointment>(_databaseService);

private AppointmentServiceProductRepository? _appointmentServiceProductRepository;
private Repository<AppointmentServiceProduct>? _appointmentServiceProductRepository;

/// <inheritdoc />
public AppointmentServiceProductRepository AppointmentServiceProductRepository =>
_appointmentServiceProductRepository ??= new AppointmentServiceProductRepository(
public Repository<AppointmentServiceProduct> AppointmentServiceProductRepository =>
_appointmentServiceProductRepository ??= new Repository<AppointmentServiceProduct>(
_databaseService
);

private AppointmentServiceRepository? _appointmentServiceRepository;
private Repository<AppointmentService>? _appointmentServiceRepository;

/// <inheritdoc />
public AppointmentServiceRepository AppointmentServiceRepository =>
_appointmentServiceRepository ??= new AppointmentServiceRepository(_databaseService);
public Repository<AppointmentService> AppointmentServiceRepository =>
_appointmentServiceRepository ??= new Repository<AppointmentService>(_databaseService);

private CustomerAddressRepository? _customerAddressRepository;
private Repository<CustomerAddress>? _customerAddressRepository;

/// <inheritdoc />
public CustomerAddressRepository CustomerAddressRepository =>
_customerAddressRepository ??= new CustomerAddressRepository(_databaseService);
public Repository<CustomerAddress> CustomerAddressRepository =>
_customerAddressRepository ??= new Repository<CustomerAddress>(_databaseService);

private CustomerPetRepository? _customerPetRepository;
private Repository<CustomerPet>? _customerPetRepository;

/// <inheritdoc />
public CustomerPetRepository CustomerPetRepository =>
_customerPetRepository ??= new CustomerPetRepository(_databaseService);
public Repository<CustomerPet> CustomerPetRepository =>
_customerPetRepository ??= new Repository<CustomerPet>(_databaseService);

private CustomerRepository? _customerRepository;
private Repository<Customer>? _customerRepository;

/// <inheritdoc />
public CustomerRepository CustomerRepository =>
_customerRepository ??= new CustomerRepository(_databaseService);
public Repository<Customer> CustomerRepository =>
_customerRepository ??= new Repository<Customer>(_databaseService);

private EmployeeAccountRepository? _employeeAccountRepository;
private Repository<EmployeeAccount>? _employeeAccountRepository;

/// <inheritdoc />
public EmployeeAccountRepository EmployeeAccountRepository =>
_employeeAccountRepository ??= new EmployeeAccountRepository(_databaseService);
public Repository<EmployeeAccount> EmployeeAccountRepository =>
_employeeAccountRepository ??= new Repository<EmployeeAccount>(_databaseService);

private EmployeeAddressRepository? _employeeAddressRepository;
private Repository<EmployeeAddress>? _employeeAddressRepository;

/// <inheritdoc />
public EmployeeAddressRepository EmployeeAddressRepository =>
_employeeAddressRepository ??= new EmployeeAddressRepository(_databaseService);
public Repository<EmployeeAddress> EmployeeAddressRepository =>
_employeeAddressRepository ??= new Repository<EmployeeAddress>(_databaseService);

private EmployeeRepository? _employeeRepository;
private Repository<Employee>? _employeeRepository;

/// <inheritdoc />
public EmployeeRepository EmployeeRepository =>
_employeeRepository ??= new EmployeeRepository(_databaseService);
public Repository<Employee> EmployeeRepository =>
_employeeRepository ??= new Repository<Employee>(_databaseService);

private EmployeeRoleRepository? _employeeRoleRepository;
private Repository<EmployeeRole>? _employeeRoleRepository;

/// <inheritdoc />
public EmployeeRoleRepository EmployeeRoleRepository =>
_employeeRoleRepository ??= new EmployeeRoleRepository(_databaseService);
public Repository<EmployeeRole> EmployeeRoleRepository =>
_employeeRoleRepository ??= new Repository<EmployeeRole>(_databaseService);

private GroomingServiceRepository? _groomingServiceRepository;
private Repository<GroomingService>? _groomingServiceRepository;

/// <inheritdoc />
public GroomingServiceRepository GroomingServiceRepository =>
_groomingServiceRepository ??= new GroomingServiceRepository(_databaseService);
public Repository<GroomingService> GroomingServiceRepository =>
_groomingServiceRepository ??= new Repository<GroomingService>(_databaseService);

private PetRepository? _petRepository;
private Repository<Pet>? _petRepository;

/// <inheritdoc />
public PetRepository PetRepository => _petRepository ??= new PetRepository(_databaseService);
public Repository<Pet> PetRepository =>
_petRepository ??= new Repository<Pet>(_databaseService);

private ProductRepository? _productRepository;
private Repository<Product>? _productRepository;

/// <inheritdoc />
public ProductRepository ProductRepository =>
_productRepository ??= new ProductRepository(_databaseService);
public Repository<Product> ProductRepository =>
_productRepository ??= new Repository<Product>(_databaseService);

private RoleRepository? _roleRepository;
private Repository<Role>? _roleRepository;

/// <inheritdoc />
public RoleRepository RoleRepository =>
_roleRepository ??= new RoleRepository(_databaseService);
public Repository<Role> RoleRepository =>
_roleRepository ??= new Repository<Role>(_databaseService);

/// <inheritdoc />
public void SaveChanges()
Expand Down
12 changes: 0 additions & 12 deletions Russkyc.GroomWise/Services/Repository/AccountRepository.cs

This file was deleted.

12 changes: 0 additions & 12 deletions Russkyc.GroomWise/Services/Repository/AddressRepository.cs

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions Russkyc.GroomWise/Services/Repository/AppointmentPetRepository.cs

This file was deleted.

12 changes: 0 additions & 12 deletions Russkyc.GroomWise/Services/Repository/AppointmentRepository.cs

This file was deleted.

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions Russkyc.GroomWise/Services/Repository/CustomerAddressRepository.cs

This file was deleted.

Loading

0 comments on commit 6e48466

Please sign in to comment.