Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7572ac8

Browse files
2 parents 8073782 + 1f62bec commit 7572ac8

File tree

19 files changed

+440
-28
lines changed

19 files changed

+440
-28
lines changed

‎src/AspnetRun.Api/Controllers/ProductController.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using AspnetRun.Api.Requests;
22
using AspnetRun.Application.Interfaces;
33
using AspnetRun.Application.Models;
4+
using AspnetRun.Core.Paging;
45
using MediatR;
56
using Microsoft.AspNetCore.Authentication.JwtBearer;
67
using Microsoft.AspNetCore.Authorization;
@@ -36,6 +37,16 @@ public async Task<ActionResult<IEnumerable<ProductModel>>> GetProducts()
3637
return Ok(products);
3738
}
3839

40+
[Route("[action]")]
41+
[HttpPost]
42+
[ProducesResponseType(typeof(IPagedList<ProductModel>), (int)HttpStatusCode.OK)]
43+
public async Task<ActionResult<IPagedList<ProductModel>>> SearchProducts(SearchProductsRequest request)
44+
{
45+
var productPagedList = await _productService.SearchProducts(request.Args);
46+
47+
return Ok(productPagedList);
48+
}
49+
3950
[Route("[action]")]
4051
[HttpPost]
4152
[ProducesResponseType(typeof(ProductModel), (int)HttpStatusCode.OK)]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using AspnetRun.Core.Paging;
2+
3+
namespace AspnetRun.Api.Requests
4+
{
5+
public class SearchProductsRequest
6+
{
7+
public PageSearchArgs Args { get; set; }
8+
}
9+
}

‎src/AspnetRun.Application/Interfaces/IProductService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using AspnetRun.Application.Models;
2+
using AspnetRun.Core.Paging;
23
using System.Collections.Generic;
34
using System.Threading.Tasks;
45

@@ -7,6 +8,7 @@ namespace AspnetRun.Application.Interfaces
78
public interface IProductService
89
{
910
Task<IEnumerable<ProductModel>> GetProductList();
11+
Task<IPagedList<ProductModel>> SearchProducts(PageSearchArgs args);
1012
Task<ProductModel> GetProductById(int productId);
1113
Task<IEnumerable<ProductModel>> GetProductsByName(string name);
1214
Task<IEnumerable<ProductModel>> GetProductsByCategoryId(int categoryId);

‎src/AspnetRun.Application/Services/ProductService.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
using AspnetRun.Application.Models;
77
using AspnetRun.Core.Entities;
88
using AspnetRun.Core.Interfaces;
9+
using AspnetRun.Core.Paging;
910
using AspnetRun.Core.Repositories;
1011
using AspnetRun.Core.Specifications;
12+
using AspnetRun.Infrastructure.Paging;
1113

1214
namespace AspnetRun.Application.Services
1315
{
@@ -31,6 +33,23 @@ public async Task<IEnumerable<ProductModel>> GetProductList()
3133
return productModels;
3234
}
3335

36+
public async Task<IPagedList<ProductModel>> SearchProducts(PageSearchArgs args)
37+
{
38+
var productPagedList = await _productRepository.SearchProductsAsync(args);
39+
40+
//TODO: PagedList<TSource> will be mapped to PagedList<TDestination>;
41+
var productModels = ObjectMapper.Mapper.Map<List<ProductModel>>(productPagedList.Items);
42+
43+
var productModelPagedList = new PagedList<ProductModel>(
44+
productPagedList.PageIndex,
45+
productPagedList.PageSize,
46+
productPagedList.TotalCount,
47+
productPagedList.TotalPages,
48+
productModels);
49+
50+
return productModelPagedList;
51+
}
52+
3453
public async Task<ProductModel> GetProductById(int productId)
3554
{
3655
var product = await _productRepository.GetByIdAsync(productId);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
namespace AspnetRun.Core.Paging
2+
{
3+
public class FilteringOption
4+
{
5+
public string Field { get; set; }
6+
7+
public FilteringOperator Operator { get; set; }
8+
9+
public object Value { get; set; }
10+
11+
public enum FilteringOperator
12+
{
13+
//Empty,
14+
Contains,
15+
Not_Contains,
16+
LT,
17+
LE,
18+
GT,
19+
GE,
20+
NE,
21+
EQ,
22+
StartsWith,
23+
EndsWith,
24+
RangeInclusive,
25+
RangeExclusive,
26+
IN,
27+
NOT_IN,
28+
IN_CONTAINS,
29+
NOT_IN_CONTAINS
30+
}
31+
}
32+
}

‎src/AspnetRun.Core/Paging/IPagedList.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Collections.Generic;
2+
3+
namespace AspnetRun.Core.Paging
4+
{
5+
public interface IPagedList<out T>
6+
{
7+
/// <summary>
8+
/// Page index
9+
/// </summary>
10+
int PageIndex { get; }
11+
12+
/// <summary>
13+
/// Page size
14+
/// </summary>
15+
int PageSize { get; }
16+
17+
/// <summary>
18+
/// Total count
19+
/// </summary>
20+
int TotalCount { get; }
21+
22+
/// <summary>
23+
/// Total pages
24+
/// </summary>
25+
int TotalPages { get; }
26+
27+
/// <summary>
28+
/// Has previous page
29+
/// </summary>
30+
bool HasPreviousPage { get; }
31+
32+
/// <summary>
33+
/// Has next age
34+
/// </summary>
35+
bool HasNextPage { get; }
36+
37+
/// <summary>
38+
/// Items
39+
/// </summary>
40+
IEnumerable<T> Items { get; }
41+
}
42+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System.Collections.Generic;
2+
3+
namespace AspnetRun.Core.Paging
4+
{
5+
public class PageSearchArgs
6+
{
7+
/// <summary>
8+
/// Page index
9+
/// </summary>
10+
public int PageIndex { get; set; }
11+
12+
/// <summary>
13+
/// Page size
14+
/// </summary>
15+
public int PageSize { get; set; }
16+
17+
/// <summary>
18+
/// Paging strategy
19+
/// </summary>
20+
public PagingStrategy PagingStrategy { get; set; }
21+
22+
/// <summary>
23+
/// Sorting options
24+
/// </summary>
25+
public List<SortingOption> SortingOptions { get; set; }
26+
27+
/// <summary>
28+
/// Filtering options
29+
/// </summary>
30+
public List<FilteringOption> FilteringOptions { get; set; }
31+
}
32+
}

‎src/AspnetRun.Core/Paging/PagingArgs.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace AspnetRun.Core.Paging
2+
{
3+
public class PagingArgs
4+
{
5+
public int PageIndex { get; set; }
6+
7+
public int PageSize { get; set; }
8+
9+
public PagingStrategy PagingStrategy { get; set; }
10+
}
11+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace AspnetRun.Core.Paging
2+
{
3+
public enum PagingStrategy
4+
{
5+
WithCount = 0,
6+
NoCount = 1
7+
}
8+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace AspnetRun.Core.Paging
2+
{
3+
public class SortingOption
4+
{
5+
public string Field { get; set; }
6+
7+
public SortingDirection Direction { get; set; }
8+
9+
public int Priority { get; set; }
10+
11+
public enum SortingDirection
12+
{
13+
ASC,
14+
DESC
15+
}
16+
}
17+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /