-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement MediatR in GetAllStock endpoint
- Loading branch information
1 parent
a7063b4
commit 6dc9dfa
Showing
5 changed files
with
52 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using api.DTOs.Stock; | ||
using api.Interfaces; | ||
using api.Mappers; | ||
using api.Queries; | ||
using MediatR; | ||
|
||
namespace api.Handlers | ||
{ | ||
public class GetAllStocksHandler : IRequestHandler<GetAllStocksQuery, List<StockDto>> | ||
{ | ||
private readonly IStockRepo _stockRepo; | ||
public GetAllStocksHandler(IStockRepo stockRepo) | ||
{ | ||
_stockRepo = stockRepo; | ||
} | ||
|
||
public async Task<List<StockDto>> Handle(GetAllStocksQuery request, CancellationToken cancellationToken) | ||
{ | ||
var stocks = await _stockRepo.GetAllAsync(request.QueryObject); | ||
return stocks.Select(s => s.ToStockDto()).ToList(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using api.DTOs.Stock; | ||
using api.Helpers; | ||
using api.Models; | ||
using MediatR; | ||
|
||
namespace api.Queries | ||
{ | ||
public class GetAllStocksQuery : IRequest<List<StockDto>> | ||
{ | ||
public QueryObject QueryObject { get; } | ||
|
||
public GetAllStocksQuery(QueryObject queryObject) | ||
{ | ||
QueryObject = queryObject; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters