Skip to content

Commit

Permalink
[SOA-007][Feature] Build the Business module (Services) (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
LyQuocCuong authored Jul 19, 2023
1 parent 43f0a51 commit f878d47
Show file tree
Hide file tree
Showing 22 changed files with 379 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Cores/Contracts.Business/Abstracts/IAbstractService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Contracts.Business.Abstracts
{
public interface IAbstractService
{
}
}
13 changes: 13 additions & 0 deletions Cores/Contracts.Business/Contracts.Business.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions Cores/Contracts.Business/Entities/ICompanyService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Contracts.Business.Entities
{
public interface ICompanyService
{
CompanyDto? GetById(bool isTrackChanges, Guid id);
}
}
15 changes: 15 additions & 0 deletions Cores/Contracts.Business/Entities/ICustomerService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Contracts.Business.Entities
{
public interface ICustomerService
{
CustomerDto? GetById(bool isTrackChanges, Guid id);

IEnumerable<CustomerDto> GetAll(bool isTrackChanges);

void Create(CustomerForCreationDto creationDto);

void SoftDelete(Guid id);

void HardDelete(Guid id);
}
}
15 changes: 15 additions & 0 deletions Cores/Contracts.Business/Entities/IEmployeeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Contracts.Business.Entities
{
public interface IEmployeeService
{
EmployeeDto? GetById(bool isTrackChanges, Guid id);

IEnumerable<EmployeeDto> GetAll(bool isTrackChanges);

void Create(EmployeeForCreationDto creationDto);

void SoftDelete(Guid id);

void HardDelete(Guid id);
}
}
15 changes: 15 additions & 0 deletions Cores/Contracts.Business/Entities/IProductService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Contracts.Business.Entities
{
public interface IProductService
{
ProductDto? GetById(bool isTrackChanges, Guid id);

IEnumerable<ProductDto> GetAll(bool isTrackChanges);

void Create(ProductForCreationDto creationDto);

void SoftDelete(Guid id);

void HardDelete(Guid id);
}
}
15 changes: 15 additions & 0 deletions Cores/Contracts.Business/Entities/IStoreService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Contracts.Business.Entities
{
public interface IStoreService
{
StoreDto? GetById(bool isTrackChanges, Guid id);

IEnumerable<StoreDto> GetAll(bool isTrackChanges);

void Create(StoreForCreationDto creationDto);

void SoftDelete(Guid id);

void HardDelete(Guid id);
}
}
17 changes: 17 additions & 0 deletions Cores/Contracts.Business/Managers/IServiceManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Contracts.Business.Entities;

namespace Contracts.Business.Managers
{
public interface IServiceManager
{
ICompanyService Company { get; }

ICustomerService Customer { get; }

IEmployeeService Employee { get; }

IProductService Product { get; }

IStoreService Store { get; }
}
}
2 changes: 2 additions & 0 deletions Cores/Contracts.Business/Using.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
global using Shared.DTOs.Inputs.FromBody.CreationDtos;
global using Shared.DTOs.Outputs.EntityDtos;
19 changes: 19 additions & 0 deletions Implementations/eShopOnlineBusiness/Abstracts/AbstractService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Contracts.Business.Abstracts;
using Contracts.Repositories.Managers;
using Contracts.Utilities.Mapper;

namespace eShopOnlineBusiness.Abstracts
{
public abstract class AbstractService : IAbstractService
{
protected readonly IRepositoryManager _repositoryManager;
protected readonly IMapperService _mapperService;

protected AbstractService(ServiceParams serviceParams)
{
_repositoryManager = serviceParams.RepositoryManager;
_mapperService = serviceParams.MapperService;
}

}
}
19 changes: 19 additions & 0 deletions Implementations/eShopOnlineBusiness/Entities/CompanyService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace eShopOnlineBusiness.Entities
{
internal sealed class CompanyService : AbstractService, ICompanyService
{
public CompanyService(ServiceParams serviceParams) : base(serviceParams)
{
}

public CompanyDto? GetById(bool isTrackChanges, Guid id)
{
Company? company = _repositoryManager.Company.GetById(isTrackChanges, id);
if (company == null)
{
return null;
}
return _mapperService.Execute<Company, CompanyDto>(company);
}
}
}
41 changes: 41 additions & 0 deletions Implementations/eShopOnlineBusiness/Entities/CustomerService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace eShopOnlineBusiness.Entities
{
internal sealed class CustomerService : AbstractService, ICustomerService
{
public CustomerService(ServiceParams serviceParams) : base(serviceParams)
{
}

public IEnumerable<CustomerDto> GetAll(bool isTrackChanges)
{
IEnumerable<Customer> customers = _repositoryManager.Customer.GetAll(isTrackChanges);
return _mapperService.Execute<IEnumerable<Customer>, IEnumerable<CustomerDto>>(customers);
}

public CustomerDto? GetById(bool isTrackChanges, Guid id)
{
Customer? customer = _repositoryManager.Customer.GetById(isTrackChanges, id);
if (customer == null)
{
return null;
}
return _mapperService.Execute<Customer, CustomerDto>(customer);
}

public void Create(CustomerForCreationDto creationDto)
{
Customer newCustomer = _mapperService.Execute<CustomerForCreationDto, Customer>(creationDto);
_repositoryManager.Customer.Create(newCustomer);
}

public void SoftDelete(Guid id)
{
throw new NotImplementedException();
}

public void HardDelete(Guid id)
{
throw new NotImplementedException();
}
}
}
34 changes: 34 additions & 0 deletions Implementations/eShopOnlineBusiness/Entities/EmployeeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace eShopOnlineBusiness.Entities
{
internal sealed class EmployeeService : AbstractService, IEmployeeService
{
public EmployeeService(ServiceParams serviceParams) : base(serviceParams)
{
}

public IEnumerable<EmployeeDto> GetAll(bool isTrackChanges)
{
throw new NotImplementedException();
}

public EmployeeDto? GetById(bool isTrackChanges, Guid id)
{
throw new NotImplementedException();
}

public void Create(EmployeeForCreationDto creationDto)
{
throw new NotImplementedException();
}

public void SoftDelete(Guid id)
{
throw new NotImplementedException();
}

public void HardDelete(Guid id)
{
throw new NotImplementedException();
}
}
}
34 changes: 34 additions & 0 deletions Implementations/eShopOnlineBusiness/Entities/ProductService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace eShopOnlineBusiness.Entities
{
internal sealed class ProductService : AbstractService, IProductService
{
public ProductService(ServiceParams serviceParams) : base(serviceParams)
{
}

public IEnumerable<ProductDto> GetAll(bool isTrackChanges)
{
throw new NotImplementedException();
}

public ProductDto? GetById(bool isTrackChanges, Guid id)
{
throw new NotImplementedException();
}

public void Create(ProductForCreationDto creationDto)
{
throw new NotImplementedException();
}

public void SoftDelete(Guid id)
{
throw new NotImplementedException();
}

public void HardDelete(Guid id)
{
throw new NotImplementedException();
}
}
}
34 changes: 34 additions & 0 deletions Implementations/eShopOnlineBusiness/Entities/StoreService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
namespace eShopOnlineBusiness.Entities
{
internal sealed class StoreService : AbstractService, IStoreService
{
public StoreService(ServiceParams serviceParams) : base(serviceParams)
{
}

public IEnumerable<StoreDto> GetAll(bool isTrackChanges)
{
throw new NotImplementedException();
}

public StoreDto? GetById(bool isTrackChanges, Guid id)
{
throw new NotImplementedException();
}

public void Create(StoreForCreationDto creationDto)
{
throw new NotImplementedException();
}

public void SoftDelete(Guid id)
{
throw new NotImplementedException();
}

public void HardDelete(Guid id)
{
throw new NotImplementedException();
}
}
}
33 changes: 33 additions & 0 deletions Implementations/eShopOnlineBusiness/Managers/ServiceManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Contracts.Business.Managers;
using eShopOnlineBusiness.Entities;

namespace eShopOnlineBusiness.Managers
{
public sealed class ServiceManager : IServiceManager
{
private readonly Lazy<ICompanyService> _company;
private readonly Lazy<ICustomerService> _customer;
private readonly Lazy<IEmployeeService> _employee;
private readonly Lazy<IProductService> _product;
private readonly Lazy<IStoreService> _store;

public ServiceManager(ServiceParams serviceParams)
{
_company = new Lazy<ICompanyService>(() => new CompanyService(serviceParams));
_customer = new Lazy<ICustomerService>(() => new CustomerService(serviceParams));
_employee = new Lazy<IEmployeeService>(() => new EmployeeService(serviceParams));
_product = new Lazy<IProductService>(() => new ProductService(serviceParams));
_store = new Lazy<IStoreService>(() => new StoreService(serviceParams));
}

public ICompanyService Company => _company.Value;

public ICustomerService Customer => _customer.Value;

public IEmployeeService Employee => _employee.Value;

public IProductService Product => _product.Value;

public IStoreService Store => _store.Value;
}
}
18 changes: 18 additions & 0 deletions Implementations/eShopOnlineBusiness/Parameters/ServiceParams.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Contracts.Repositories.Managers;
using Contracts.Utilities.Mapper;

namespace eShopOnlineBusiness.Parameters
{
public sealed class ServiceParams
{
public readonly IRepositoryManager RepositoryManager;
public readonly IMapperService MapperService;

public ServiceParams(IRepositoryManager repositoryManager,
IMapperService mapperService)
{
RepositoryManager = repositoryManager;
MapperService = mapperService;
}
}
}
6 changes: 6 additions & 0 deletions Implementations/eShopOnlineBusiness/Using.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
global using Contracts.Business.Entities;
global using Domains.Entities;
global using eShopOnlineBusiness.Abstracts;
global using eShopOnlineBusiness.Parameters;
global using Shared.DTOs.Inputs.FromBody.CreationDtos;
global using Shared.DTOs.Outputs.EntityDtos;
15 changes: 15 additions & 0 deletions Implementations/eShopOnlineBusiness/eShopOnlineBusiness.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Cores\Contracts.Business\Contracts.Business.csproj" />
<ProjectReference Include="..\..\Cores\Contracts.Repositories\Contracts.Repositories.csproj" />
<ProjectReference Include="..\..\Cores\Contracts\Contracts.csproj" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions eShopOnlineApiHost/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Contracts.Business.Managers;
using Contracts.Utilities.Mapper;
using eShopOnlineBusiness.Managers;
using eShopOnlineEFCore.Context;
using eShopOnlineUtilities.AutoMapper;
using Microsoft.EntityFrameworkCore;
Expand All @@ -18,6 +20,7 @@ public static void Main(string[] args)

builder.Services.AddControllers();
builder.Services.AddScoped<IMapperService, AutoMapperService>();
builder.Services.AddScoped<IServiceManager, ServiceManager>();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
Expand Down
1 change: 1 addition & 0 deletions eShopOnlineApiHost/eShopOnlineApiHost.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Implementations\eShopOnlineBusiness\eShopOnlineBusiness.csproj" />
<ProjectReference Include="..\Implementations\eShopOnlineRepositories\eShopOnlineRepositories.csproj" />
<ProjectReference Include="..\Implementations\eShopOnlineUtilities\eShopOnlineUtilities.csproj" />
</ItemGroup>
Expand Down
Loading

0 comments on commit f878d47

Please sign in to comment.