Skip to content

Commit

Permalink
Day3 Add CQRS Query
Browse files Browse the repository at this point in the history
  • Loading branch information
engindemirog committed Aug 31, 2022
1 parent 68877c4 commit 6a7e297
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
3 changes: 1 addition & 2 deletions src/demoProjects/rentACar/Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

<ItemGroup>
<Folder Include="Features\Brands\Constants\" />
<Folder Include="Features\Brands\Models\" />
<Folder Include="Features\Brands\Queries\" />
</ItemGroup>

<ItemGroup>
Expand All @@ -18,6 +16,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\corePackages\Core.Application\Core.Application.csproj" />
<ProjectReference Include="..\..\..\corePackages\Core.CrossCuttingConcers\Core.CrossCuttingConcerns.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Features.Brands.Dtos
{
public class BrandListDto
{
public int Id { get; set; }
public string Name { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Application.Features.Brands.Dtos;
using Core.Persistence.Paging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Features.Brands.Models
{
public class BrandListModel:BasePageableModel
{
public IList<BrandListDto> Items { get; set; }

//
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Application.Features.Brands.Commands.CreateBrand;
using Application.Features.Brands.Dtos;
using Application.Features.Brands.Models;
using AutoMapper;
using Core.Persistence.Paging;
using Domain.Entities;
using System;
using System.Collections.Generic;
Expand All @@ -16,6 +18,7 @@ public MappingProfiles()
{
CreateMap<Brand,CreatedBrandDto>().ReverseMap();
CreateMap<Brand,CreateBrandCommand>().ReverseMap();
CreateMap<IPaginate<Brand>, BrandListModel>().ReverseMap();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Application.Features.Brands.Models;
using Application.Services.Repositories;
using AutoMapper;
using Core.Application.Requests;
using Core.Persistence.Paging;
using Domain.Entities;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Features.Brands.Queries.GetListBrand
{
public class GetListBrandQuery:IRequest<BrandListModel>
{
public PageRequest PageRequest { get; set; }
public class GetListBrandQueryHandler : IRequestHandler<GetListBrandQuery, BrandListModel>
{
private readonly IBrandRepository _brandRepository;
private readonly IMapper _mapper;

public GetListBrandQueryHandler(IBrandRepository brandRepository, IMapper mapper)
{
_brandRepository = brandRepository;
_mapper = mapper;
}

public async Task<BrandListModel> Handle(GetListBrandQuery request, CancellationToken cancellationToken)
{
IPaginate<Brand> brands = await _brandRepository.GetListAsync(index: request.PageRequest.Page,size:request.PageRequest.PageSize);

BrandListModel mappedBrandListModel = _mapper.Map<BrandListModel>(brands);

return mappedBrandListModel;
}
}
}

//22.05 Dersteyiz...
}

0 comments on commit 6a7e297

Please sign in to comment.