feat: Implement Discount Product and Shopping Cart functionalities
- Added UpdateDiscountProductCommandValidator for validating discount product updates. - Created GetDiscountProductByIdQuery and its handler for retrieving discount product details by ID. - Implemented GetDiscountProductsQuery and handler for fetching a list of discount products with filtering options. - Developed AddToCartCommand and handler for adding products to the shopping cart. - Implemented ClearCartCommand and handler for clearing the shopping cart. - Created RemoveFromCartCommand and handler for removing items from the cart. - Added UpdateCartItemCountCommand and handler for updating the quantity of items in the cart. - Developed GetUserCartQuery and handler for retrieving the user's shopping cart details. - Implemented Product Tag functionalities including assigning tags to products, creating, updating, and deleting tags. - Added queries for fetching all tags and products by tag.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
using CMSMicroservice.Protobuf.Protos.Tag;
|
||||
|
||||
namespace BackOffice.BFF.Application.TagCQ.Commands.CreateTag;
|
||||
|
||||
public record CreateTagCommand : IRequest<long>
|
||||
{
|
||||
public string Name { get; init; } = string.Empty;
|
||||
public string Title { get; init; } = string.Empty;
|
||||
public string? Description { get; init; }
|
||||
public bool IsActive { get; init; } = true;
|
||||
public int SortOrder { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using CMSMicroservice.Protobuf.Protos.Tag;
|
||||
|
||||
namespace BackOffice.BFF.Application.TagCQ.Commands.CreateTag;
|
||||
|
||||
public class CreateTagCommandHandler : IRequestHandler<CreateTagCommand, long>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public CreateTagCommandHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<long> Handle(CreateTagCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await _context.Tags.CreateNewTagAsync(
|
||||
new CreateNewTagRequest
|
||||
{
|
||||
Name = request.Name,
|
||||
Title = request.Title,
|
||||
Description = request.Description,
|
||||
IsActive = request.IsActive,
|
||||
SortOrder = request.SortOrder
|
||||
},
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
return response.Id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace BackOffice.BFF.Application.TagCQ.Commands.DeleteTag;
|
||||
|
||||
public record DeleteTagCommand : IRequest
|
||||
{
|
||||
public long Id { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using CMSMicroservice.Protobuf.Protos.Tag;
|
||||
|
||||
namespace BackOffice.BFF.Application.TagCQ.Commands.DeleteTag;
|
||||
|
||||
public class DeleteTagCommandHandler : IRequestHandler<DeleteTagCommand>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public DeleteTagCommandHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(DeleteTagCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
await _context.Tags.DeleteTagAsync(
|
||||
new DeleteTagRequest
|
||||
{
|
||||
Id = request.Id
|
||||
},
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using CMSMicroservice.Protobuf.Protos.Tag;
|
||||
|
||||
namespace BackOffice.BFF.Application.TagCQ.Commands.UpdateTag;
|
||||
|
||||
public record UpdateTagCommand : IRequest
|
||||
{
|
||||
public long Id { get; init; }
|
||||
public string Name { get; init; } = string.Empty;
|
||||
public string Title { get; init; } = string.Empty;
|
||||
public string? Description { get; init; }
|
||||
public bool IsActive { get; init; }
|
||||
public int SortOrder { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using CMSMicroservice.Protobuf.Protos.Tag;
|
||||
|
||||
namespace BackOffice.BFF.Application.TagCQ.Commands.UpdateTag;
|
||||
|
||||
public class UpdateTagCommandHandler : IRequestHandler<UpdateTagCommand>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public UpdateTagCommandHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(UpdateTagCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
await _context.Tags.UpdateTagAsync(
|
||||
new UpdateTagRequest
|
||||
{
|
||||
Id = request.Id,
|
||||
Name = request.Name,
|
||||
Title = request.Title,
|
||||
Description = request.Description,
|
||||
IsActive = request.IsActive,
|
||||
SortOrder = request.SortOrder
|
||||
},
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using CMSMicroservice.Protobuf.Protos.Tag;
|
||||
|
||||
namespace BackOffice.BFF.Application.TagCQ.Queries.GetAllTags;
|
||||
|
||||
public record GetAllTagsQuery : IRequest<GetAllTagByFilterResponse>
|
||||
{
|
||||
public int PageNumber { get; init; } = 1;
|
||||
public int PageSize { get; init; } = 10;
|
||||
public string? SearchTerm { get; init; }
|
||||
public bool? IsActive { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using CMSMicroservice.Protobuf.Protos.Tag;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using CMSMicroservice.Protobuf.Protos;
|
||||
|
||||
namespace BackOffice.BFF.Application.TagCQ.Queries.GetAllTags;
|
||||
|
||||
public class GetAllTagsQueryHandler : IRequestHandler<GetAllTagsQuery, GetAllTagByFilterResponse>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public GetAllTagsQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetAllTagByFilterResponse> Handle(GetAllTagsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var grpcRequest = new GetAllTagByFilterRequest
|
||||
{
|
||||
PaginationState = new CMSMicroservice.Protobuf.Protos.PaginationState
|
||||
{
|
||||
PageNumber = request.PageNumber,
|
||||
PageSize = request.PageSize
|
||||
},
|
||||
Filter = new GetAllTagByFilterFilter()
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(request.SearchTerm))
|
||||
{
|
||||
grpcRequest.Filter.Name = request.SearchTerm;
|
||||
}
|
||||
|
||||
if (request.IsActive.HasValue)
|
||||
{
|
||||
grpcRequest.Filter.IsActive = request.IsActive.Value;
|
||||
}
|
||||
|
||||
var response = await _context.Tags.GetAllTagByFilterAsync(grpcRequest, cancellationToken: cancellationToken);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using CMSMicroservice.Protobuf.Protos.Tag;
|
||||
|
||||
namespace BackOffice.BFF.Application.TagCQ.Queries.GetProductsByTag;
|
||||
|
||||
public record GetProductsByTagQuery : IRequest<GetProductsByTagResponse>
|
||||
{
|
||||
public long TagId { get; init; }
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Protobuf.Protos.Tag;
|
||||
|
||||
namespace BackOffice.BFF.Application.TagCQ.Queries.GetProductsByTag;
|
||||
|
||||
public class GetProductsByTagQueryHandler : IRequestHandler<GetProductsByTagQuery, GetProductsByTagResponse>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public GetProductsByTagQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetProductsByTagResponse> Handle(GetProductsByTagQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await _context.Tags.GetProductsByTagAsync(
|
||||
new GetProductsByTagRequest { TagId = request.TagId },
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using CMSMicroservice.Protobuf.Protos.Tag;
|
||||
|
||||
namespace BackOffice.BFF.Application.TagCQ.Queries.GetTag;
|
||||
|
||||
public record GetTagQuery : IRequest<GetTagResponse>
|
||||
{
|
||||
public long Id { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using CMSMicroservice.Protobuf.Protos.Tag;
|
||||
|
||||
namespace BackOffice.BFF.Application.TagCQ.Queries.GetTag;
|
||||
|
||||
public class GetTagQueryHandler : IRequestHandler<GetTagQuery, GetTagResponse>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public GetTagQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetTagResponse> Handle(GetTagQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var response = await _context.Tags.GetTagAsync(
|
||||
new GetTagRequest { Id = request.Id },
|
||||
cancellationToken: cancellationToken);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user