Skip to content

Instantly share code, notes, and snippets.

View thangchung's full-sized avatar
:electron:
Sharing is caring

Thang Chung thangchung

:electron:
Sharing is caring
View GitHub Profile
@thangchung
thangchung / ProductController.cs
Created August 5, 2018 11:17
This is a simple controller follows OASIS standard
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Swashbuckle.AspNetCore.Annotations;
using VND.CoolStore.Services.ApiGateway.Infrastructure.Service;
using VND.CoolStore.Services.ApiGateway.Model;
using VND.CoolStore.Shared.Catalog.GetProductById;
@thangchung
thangchung / Cart.cs
Last active September 7, 2018 03:46
Clean Domain-driven Design article
public sealed class Cart : AggregateRootBase
{
private Cart() : base(GenerateId())
{
}
private Cart(Guid id) : base(id)
{
}
@thangchung
thangchung / CartItem.cs
Created September 7, 2018 03:47
Clean Domain-driven Design article
public sealed class CartItem : EntityBase
{
private CartItem() : base(GenerateId())
{
}
private CartItem(Guid id, int quantity, double price = 0.0D, double promoSavings = 0.0D) : base(id)
{
Quantity = quantity;
Price = price;
@thangchung
thangchung / Product.cs
Created September 7, 2018 03:48
Clean Domain-driven Design article
public sealed class Product : IdentityBase
{
private Product() : base()
{
}
private Product(Guid productId)
: this(productId, string.Empty, 0.0D, string.Empty)
{
}
@thangchung
thangchung / RequestHandler.cs
Created September 7, 2018 03:52
Clean Domain-driven Design article - Get Cart with Products
public class RequestHandler : RequestHandlerBase<GetCartRequest, GetCartResponse>
{
private readonly ICatalogGateway _catalogGateway;
private readonly IShippingGateway _shippingGateway;
private readonly IPromoGateway _promoGateway;
public RequestHandler(ICatalogGateway cgw, IQueryRepositoryFactory qrf,
IShippingGateway shippingGateway, IPromoGateway promoGateway)
: base(qrf)
{
@thangchung
thangchung / RequestHandler.cs
Created September 7, 2018 03:54
Clean Domain-driven Design article - Add Product to a Cart
public class RequestHandler : TxRequestHandlerBase<InsertItemToNewCartRequest, InsertItemToNewCartResponse>
{
private readonly ICatalogGateway _catalogGateway;
private readonly IShippingGateway _shippingGateway;
private readonly IPromoGateway _promoGateway;
public RequestHandler(
IUnitOfWorkAsync uow, IQueryRepositoryFactory qrf,
ICatalogGateway catalogGateway, IShippingGateway shippingGateway,
IPromoGateway promoGateway) : base(uow, qrf)
@thangchung
thangchung / RequestHandler.cs
Created September 7, 2018 03:56
Clean Domain-driven Design article - Update Product in the Cart
public class RequestHandler : TxRequestHandlerBase<UpdateItemInCartRequest, UpdateItemInCartResponse>
{
private readonly ICatalogGateway _catalogGateway;
private readonly IShippingGateway _shippingGateway;
private readonly IPromoGateway _promoGateway;
public RequestHandler(IUnitOfWorkAsync uow, IQueryRepositoryFactory qrf,
ICatalogGateway catalogGateway, IShippingGateway shippingGateway,
IPromoGateway promoGateway) : base(uow, qrf)
{
@thangchung
thangchung / RequestHandler.cs
Created September 7, 2018 03:58
Clean Domain-driven Design article - Delete Product in the Cart
public class RequestHandler : TxRequestHandlerBase<DeleteItemRequest, DeleteItemResponse>
{
private readonly ICatalogGateway _catalogGateway;
private readonly IShippingGateway _shippingGateway;
private readonly IPromoGateway _promoGateway;
public RequestHandler(IUnitOfWorkAsync uow, IQueryRepositoryFactory qf,
ICatalogGateway cgw, IShippingGateway shippingGateway, IPromoGateway promoGateway)
: base(uow, qf)
{
@thangchung
thangchung / RequestHandler.cs
Created September 7, 2018 04:01
Clean Domain-driven Design article - Checkout
public class RequestHandler : TxRequestHandlerBase<CheckoutRequest, CheckoutResponse>
{
public RequestHandler(IUnitOfWorkAsync uow, IQueryRepositoryFactory qrf)
: base(uow, qrf)
{
}
public override async Task<CheckoutResponse> Handle(CheckoutRequest request, CancellationToken cancellationToken)
{
var cartCommander = UnitOfWork.Repository<Domain.Cart>();
@thangchung
thangchung / CartController.cs
Created September 7, 2018 04:03
Clean Domain-driven Design article - CartController.cs
[ApiController]
[ApiVersion("1.0")]
[Route("api/carts")]
public class CartController : Controller
{
[HttpGet]
[Route("{id}")]
[Auth(Policy = "access_cart_api")]
public async Task<IActionResult> Get([FromServices] IMediator eventor, Guid id, CancellationToken cancellationToken)
{