Skip to content

Commit

Permalink
Added Products and Categories to DB of Warehouse module
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmackay committed Jan 6, 2024
1 parent 2f179e0 commit 5c60031
Show file tree
Hide file tree
Showing 52 changed files with 508 additions and 184 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SharedKernel.Domain.Interfaces;
using Common.SharedKernel.Domain.Interfaces;
using System.ComponentModel.DataAnnotations.Schema;

namespace SharedKernel.Domain.Base;
namespace Common.SharedKernel.Domain.Base;

public abstract class AggregateRoot<TId> : Entity<TId>, IDomainEvents
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SharedKernel.Domain.Base;
namespace Common.SharedKernel.Domain.Base;

//public record DomainEvent : INotification { }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SharedKernel.Domain.Interfaces;
using Common.SharedKernel.Domain.Interfaces;

namespace SharedKernel.Domain.Base;
namespace Common.SharedKernel.Domain.Base;

public abstract class Entity<TId> : IAuditableEntity
{
Expand Down
3 changes: 3 additions & 0 deletions src/Common/Common.SharedKernel/Domain/Base/ValueObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Common.SharedKernel.Domain.Base;

public record ValueObject { }
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SharedKernel.Domain.Exceptions;
using Common.SharedKernel.Domain.Exceptions;

namespace SharedKernel.Domain.Entities;
namespace Common.SharedKernel.Domain.Entities;

public record Currency
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SharedKernel.Domain.Entities;
namespace Common.SharedKernel.Domain.Entities;

public record Money(Currency Currency, decimal Amount)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SharedKernel.Domain.Exceptions;
namespace Common.SharedKernel.Domain.Exceptions;

public class DomainException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Runtime.CompilerServices;
using Ardalis.GuardClauses;
using System.Runtime.CompilerServices;

namespace Ardalis.GuardClauses;
namespace Common.SharedKernel.Domain.Exceptions;

public static class FooGuard
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Common.SharedKernel.Domain.Identifiers;

public record ProductId(Guid Value);
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace SharedKernel.Domain.Interfaces;
namespace Common.SharedKernel.Domain.Interfaces;

public interface IAuditableEntity
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using SharedKernel.Domain.Base;
using Common.SharedKernel.Domain.Base;

namespace SharedKernel.Domain.Interfaces;
namespace Common.SharedKernel.Domain.Interfaces;

public interface IDomainEvents
{
Expand Down
3 changes: 0 additions & 3 deletions src/Common/SharedKernel/Domain/Base/ValueObject.cs

This file was deleted.

3 changes: 0 additions & 3 deletions src/Common/SharedKernel/Domain/Identifiers/ProductId.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Ardalis.GuardClauses;
using SharedKernel.Domain.Base;
using Common.SharedKernel.Domain.Base;

namespace Modules.Orders.Domain.Customers;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SharedKernel.Domain.Base;
using Common.SharedKernel.Domain.Base;

namespace Modules.Orders.Domain.Customers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Common\SharedKernel\SharedKernel.csproj"/>
<ProjectReference Include="..\..\..\Common\Common.SharedKernel\Common.SharedKernel.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions src/Modules/Orders/Modules.Orders.Domain/Orders/LineItem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Ardalis.GuardClauses;
using SharedKernel.Domain.Base;
using SharedKernel.Domain.Entities;
using SharedKernel.Domain.Identifiers;
using Common.SharedKernel.Domain.Base;
using Common.SharedKernel.Domain.Entities;
using Common.SharedKernel.Domain.Exceptions;
using Common.SharedKernel.Domain.Identifiers;

namespace Modules.Orders.Domain.Orders;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SharedKernel.Domain.Base;
using Common.SharedKernel.Domain.Base;

namespace Modules.Orders.Domain.Orders;

Expand All @@ -7,4 +7,4 @@ public record LineItemCreatedEvent(LineItemId LineItemId, OrderId Order) : Domai
public LineItemCreatedEvent(LineItem lineItem) : this(lineItem.Id, lineItem.OrderId) { }

public static LineItemCreatedEvent Create(LineItem lineItem) => new(lineItem.Id, lineItem.OrderId);
}
}
8 changes: 4 additions & 4 deletions src/Modules/Orders/Modules.Orders.Domain/Orders/Order.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Ardalis.GuardClauses;
using Common.SharedKernel.Domain.Base;
using Common.SharedKernel.Domain.Entities;
using Common.SharedKernel.Domain.Exceptions;
using Common.SharedKernel.Domain.Identifiers;
using Modules.Orders.Domain.Customers;
using SharedKernel.Domain.Base;
using SharedKernel.Domain.Entities;
using SharedKernel.Domain.Exceptions;
using SharedKernel.Domain.Identifiers;

namespace Modules.Orders.Domain.Orders;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Modules.Orders.Domain.Customers;
using SharedKernel.Domain.Base;
using Common.SharedKernel.Domain.Base;
using Modules.Orders.Domain.Customers;

namespace Modules.Orders.Domain.Orders;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using SharedKernel.Domain.Base;
using Common.SharedKernel.Domain.Base;

namespace Modules.Orders.Domain.Orders;

Expand Down
63 changes: 0 additions & 63 deletions src/Modules/Orders/Modules.Orders.Domain/Products/Product.cs

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

21 changes: 0 additions & 21 deletions src/Modules/Orders/Modules.Orders.Domain/Products/Sku.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Modules.Warehouse.Application.Common.Interfaces;
using Modules.Warehouse.Domain.Categories;

namespace Modules.Warehouse.Application.Categories;

public class CategoryRepository : ICategoryRepository
{
private readonly IWarehouseDbContext _dbContext;

public CategoryRepository(IWarehouseDbContext dbContext)
{
_dbContext = dbContext;
}

public bool CategoryExists(string categoryName)
{
return _dbContext.Categories.Any(c => c.Name == categoryName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Microsoft.EntityFrameworkCore;
using Modules.Warehouse.Domain.Categories;
using Modules.Warehouse.Domain.Products;

namespace Modules.Warehouse.Application.Common.Interfaces;

public interface IWarehouseDbContext
{
public DbSet<Category> Categories { get; }

public DbSet<Product> Products { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Ardalis.Specification.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.0" />
<PackageReference Include="MediatR" Version="12.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Modules.Warehouse.Domain\Modules.Warehouse.Domain.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using MediatR;
using Microsoft.EntityFrameworkCore;
using Modules.Warehouse.Application.Common.Interfaces;

namespace Modules.Warehouse.Application.Products.Queries.GetProducts;

public record GetProductsQuery : IRequest<IEnumerable<ProductDto>>;

public record ProductDto(Guid Id, string Sku, string Name, decimal Price);

public class GetProductsQueryHandler : IRequestHandler<GetProductsQuery, IEnumerable<ProductDto>>
{
private readonly IWarehouseDbContext _dbContext;

public GetProductsQueryHandler(IWarehouseDbContext dbContext)
{
_dbContext = dbContext;
}

public async Task<IEnumerable<ProductDto>> Handle(GetProductsQuery request, CancellationToken cancellationToken)
{
return await _dbContext.Products
.Select(p => new ProductDto(p.Id.Value, p.Sku.Value, p.Name, p.Price.Amount))
.ToListAsync(cancellationToken: cancellationToken);
}
}
Loading

0 comments on commit 5c60031

Please sign in to comment.