Skip to content

Commit

Permalink
#186 Maximum value for page size taken from query string (#187)
Browse files Browse the repository at this point in the history
* #186 Maximum value for page size taken from query string

* #186 Reduced max page size value to 20

* #186 Fix for max page size value

* #186 Addition for previous commit

* #186 Code clean up
  • Loading branch information
Andrew-Orlov authored and tatarincev committed Dec 29, 2018
1 parent d35da43 commit 5431ee9
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
11 changes: 6 additions & 5 deletions VirtoCommerce.Storefront/Domain/WorkContextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using VirtoCommerce.Storefront.Extensions;
using VirtoCommerce.Storefront.Infrastructure;
using VirtoCommerce.Storefront.Model;
using VirtoCommerce.Storefront.Model.Common;

namespace VirtoCommerce.Storefront.Domain
{
public partial class WorkContextBuilder : IWorkContextBuilder
{
public WorkContextBuilder(HttpContext httpContext)
public WorkContextBuilder(HttpContext httpContext, StorefrontOptions options)
{
HttpContext = httpContext;
WorkContext = new WorkContext();
Expand All @@ -19,12 +20,12 @@ public WorkContextBuilder(HttpContext httpContext)
var htmlEncoder = httpContext.RequestServices.GetRequiredService<HtmlEncoder>();
var qs = WorkContext.QueryString = HttpContext.Request.Query.ToNameValueCollection(htmlEncoder);
WorkContext.PageNumber = qs["page"].ToNullableInt();
WorkContext.PageSize = qs["count"].ToNullableInt();
if (WorkContext.PageSize == null)

var qsPageSize = qs["count"].ToNullableInt() ?? qs["page_size"].ToNullableInt();
if (qsPageSize.HasValue && qsPageSize.Value > options.PageSizeMaxValue)
{
WorkContext.PageSize = qs["page_size"].ToNullableInt();
WorkContext.PageSize = options.PageSizeMaxValue;
}

}

public HttpContext HttpContext { get; }
Expand Down
2 changes: 2 additions & 0 deletions VirtoCommerce.Storefront/Infrastructure/StorefrontOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ public class StorefrontOptions
public bool CacheEnabled { get; set; }

public TimeSpan CacheAbsoluteExpiration { get; set; }

public int PageSizeMaxValue { get; set; } = 100;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task Invoke(HttpContext context)
return;
}

var builder = new WorkContextBuilder(context);
var builder = new WorkContextBuilder(context, _options);
var workContext = builder.WorkContext;

workContext.ApplicationSettings = _applicationSettings;
Expand Down
1 change: 1 addition & 0 deletions VirtoCommerce.Storefront/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"DefaultStore": "Electronics",
"CacheEnabled": "true",
"CacheAbsoluteExpiration": "10:00:00",
"PageSizeMaxValue": 100,
"Endpoint": {
"Url": "http://localhost/admin",
"AppId": "27e0d789f12641049bd0e939185b4fd2",
Expand Down

0 comments on commit 5431ee9

Please sign in to comment.