From 744ad72e0fbc2f3672fbec7c59c493249d20da99 Mon Sep 17 00:00:00 2001 From: Abubakr Date: Sun, 25 Feb 2024 00:13:21 +0700 Subject: [PATCH] added subCategories command --- .../Controllers/CategoriesController.cs | 2 +- .../Controllers/SubCategoriesController.cs | 20 +++++++++++++++++++ .../Controllers/SubCategoryController.cs | 10 ---------- .../GetCategoriesDefaultLinksCommand.cs | 8 ++++---- .../SubCategories/GetSubCategoriesCommand.cs | 20 +++++++++++++++++++ .../Dtos/Categories/DefaultLinkDto.cs | 2 +- .../Dtos/SubCategories/SubCategoryDTO.cs | 5 +++++ .../Mint.WebApp.Admin/Utils/AdminMapper.cs | 2 +- 8 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 src/modules/Admin/Mint.WebApp.Admin/Controllers/SubCategoriesController.cs delete mode 100644 src/modules/Admin/Mint.WebApp.Admin/Controllers/SubCategoryController.cs create mode 100644 src/modules/Admin/Mint.WebApp.Admin/Operations/Commands/SubCategories/GetSubCategoriesCommand.cs create mode 100644 src/modules/Admin/Mint.WebApp.Admin/Operations/Dtos/SubCategories/SubCategoryDTO.cs diff --git a/src/modules/Admin/Mint.WebApp.Admin/Controllers/CategoriesController.cs b/src/modules/Admin/Mint.WebApp.Admin/Controllers/CategoriesController.cs index 9226c72..3600a41 100644 --- a/src/modules/Admin/Mint.WebApp.Admin/Controllers/CategoriesController.cs +++ b/src/modules/Admin/Mint.WebApp.Admin/Controllers/CategoriesController.cs @@ -21,7 +21,7 @@ public async Task>> GetCateg [HttpGet("links")] [Authorize(Roles = "admin")] - public async Task>> GetCategoriesDefaultLinks( + public async Task>> GetCategoriesDefaultLinks( [FromQuery] string? search, CancellationToken cancellationToken = default) { diff --git a/src/modules/Admin/Mint.WebApp.Admin/Controllers/SubCategoriesController.cs b/src/modules/Admin/Mint.WebApp.Admin/Controllers/SubCategoriesController.cs new file mode 100644 index 0000000..7400e69 --- /dev/null +++ b/src/modules/Admin/Mint.WebApp.Admin/Controllers/SubCategoriesController.cs @@ -0,0 +1,20 @@ +using MediatR; +using Microsoft.AspNetCore.Mvc; +using Mint.Domain.Helpers; +using Mint.WebApp.Admin.Operations.Commands.SubCategories; +using Mint.WebApp.Admin.Operations.Dtos.SubCategories; + +namespace Mint.WebApp.Admin.Controllers; + +[ApiController] +[Route("api/[controller]")] +public class SubCategoriesController(IMediator mediator) : ControllerBase +{ + [HttpGet] + public async Task>> Get( + [FromQuery] GetSubCategoriesCommand command, + CancellationToken cancellationToken = default) + { + return await mediator.Send(command, cancellationToken); + } +} diff --git a/src/modules/Admin/Mint.WebApp.Admin/Controllers/SubCategoryController.cs b/src/modules/Admin/Mint.WebApp.Admin/Controllers/SubCategoryController.cs deleted file mode 100644 index c287b07..0000000 --- a/src/modules/Admin/Mint.WebApp.Admin/Controllers/SubCategoryController.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace Mint.WebApp.Admin.Controllers; - -[ApiController] -[Route("api/[controller]")] -public class SubCategoryController : ControllerBase -{ - -} diff --git a/src/modules/Admin/Mint.WebApp.Admin/Operations/Commands/Categories/GetCategoriesDefaultLinksCommand.cs b/src/modules/Admin/Mint.WebApp.Admin/Operations/Commands/Categories/GetCategoriesDefaultLinksCommand.cs index 93139c9..106dc56 100644 --- a/src/modules/Admin/Mint.WebApp.Admin/Operations/Commands/Categories/GetCategoriesDefaultLinksCommand.cs +++ b/src/modules/Admin/Mint.WebApp.Admin/Operations/Commands/Categories/GetCategoriesDefaultLinksCommand.cs @@ -5,20 +5,20 @@ namespace Mint.WebApp.Admin.Operations.Commands.Categories; -public sealed record GetCategoriesDefaultLinksCommand(string? Search) : ICommand>; +public sealed record GetCategoriesDefaultLinksCommand(string? Search) : ICommand>; internal sealed class GetCategoriesDefaultLinksCommandHandler( IMapper mapper, ICategoryRepository categoryRepository -) : ICommandHandler> +) : ICommandHandler> { private readonly IMapper _mapper = mapper; private readonly ICategoryRepository _categoryRepository = categoryRepository; - public async Task> Handle(GetCategoriesDefaultLinksCommand request, CancellationToken cancellationToken) + public async Task> Handle(GetCategoriesDefaultLinksCommand request, CancellationToken cancellationToken) { var categories = await _categoryRepository.GetCategoriesLinkAsync(request.Search, cancellationToken); - return _mapper.Map>(categories); + return _mapper.Map>(categories); } } diff --git a/src/modules/Admin/Mint.WebApp.Admin/Operations/Commands/SubCategories/GetSubCategoriesCommand.cs b/src/modules/Admin/Mint.WebApp.Admin/Operations/Commands/SubCategories/GetSubCategoriesCommand.cs new file mode 100644 index 0000000..78c2cc0 --- /dev/null +++ b/src/modules/Admin/Mint.WebApp.Admin/Operations/Commands/SubCategories/GetSubCategoriesCommand.cs @@ -0,0 +1,20 @@ +using Mint.Domain.Helpers; +using Mint.Infrastructure.MessageBrokers.Interfaces; +using Mint.WebApp.Admin.Operations.Dtos.SubCategories; + +namespace Mint.WebApp.Admin.Operations.Commands.SubCategories; + +public sealed record GetSubCategoriesCommand( + string? Search, + int PageIndex = 0, + int PageSize = 50 +) : ICommand>; + +internal sealed class GetSubCategoriesCommandHandler + : ICommandHandler> +{ + public Task> Handle(GetSubCategoriesCommand request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } +} diff --git a/src/modules/Admin/Mint.WebApp.Admin/Operations/Dtos/Categories/DefaultLinkDto.cs b/src/modules/Admin/Mint.WebApp.Admin/Operations/Dtos/Categories/DefaultLinkDto.cs index cc663e4..9f9a782 100644 --- a/src/modules/Admin/Mint.WebApp.Admin/Operations/Dtos/Categories/DefaultLinkDto.cs +++ b/src/modules/Admin/Mint.WebApp.Admin/Operations/Dtos/Categories/DefaultLinkDto.cs @@ -1,6 +1,6 @@ namespace Mint.WebApp.Admin.Operations.Dtos.Categories; -public class DefaultLinkDto +public class DefaultLinkDTO { public Guid Id { get; set; } diff --git a/src/modules/Admin/Mint.WebApp.Admin/Operations/Dtos/SubCategories/SubCategoryDTO.cs b/src/modules/Admin/Mint.WebApp.Admin/Operations/Dtos/SubCategories/SubCategoryDTO.cs new file mode 100644 index 0000000..4b3ae33 --- /dev/null +++ b/src/modules/Admin/Mint.WebApp.Admin/Operations/Dtos/SubCategories/SubCategoryDTO.cs @@ -0,0 +1,5 @@ +namespace Mint.WebApp.Admin.Operations.Dtos.SubCategories; + +public class SubCategoryDTO +{ +} diff --git a/src/modules/Admin/Mint.WebApp.Admin/Utils/AdminMapper.cs b/src/modules/Admin/Mint.WebApp.Admin/Utils/AdminMapper.cs index d160760..161fd60 100644 --- a/src/modules/Admin/Mint.WebApp.Admin/Utils/AdminMapper.cs +++ b/src/modules/Admin/Mint.WebApp.Admin/Utils/AdminMapper.cs @@ -10,7 +10,7 @@ public class AdminMapper : Profile { public AdminMapper() { - CreateMap(); + CreateMap(); CreateMap(); CreateMap();