This commit is contained in:
22
server/AyaNova/ControllerHelpers/ApiDataListResponse.cs
Normal file
22
server/AyaNova/ControllerHelpers/ApiDataListResponse.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AyaNova.Api.ControllerHelpers
|
||||
{
|
||||
|
||||
public class ApiDataListResponse
|
||||
{
|
||||
|
||||
public object Data { get; }
|
||||
public long TotalRecordCount { get; }
|
||||
public object Columns {get;}
|
||||
|
||||
public ApiDataListResponse(object returnItems, long totalRecordCount, Newtonsoft.Json.Linq.JArray columns)
|
||||
{
|
||||
Data = returnItems;
|
||||
TotalRecordCount = totalRecordCount;
|
||||
Columns = columns;
|
||||
|
||||
}
|
||||
}//eoc
|
||||
|
||||
}//eons
|
||||
@@ -1,38 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AyaNova.Api.ControllerHelpers
|
||||
{
|
||||
|
||||
|
||||
|
||||
public class ApiOkWithPagingResponse<T>
|
||||
{
|
||||
|
||||
public object Data { get; }
|
||||
public object Paging { get; }
|
||||
|
||||
public ApiOkWithPagingResponse(ApiPagedResponse<T> pr)
|
||||
{
|
||||
Data = pr.items;
|
||||
Paging = pr.PageLinks;
|
||||
|
||||
}
|
||||
}//eoc
|
||||
|
||||
public class ApiOkWithPagingResponse
|
||||
{
|
||||
|
||||
public object Data { get; }
|
||||
public object Paging { get; }
|
||||
public object Columns {get;}
|
||||
|
||||
public ApiOkWithPagingResponse(ApiPagedResponse pr)
|
||||
{
|
||||
Data = pr.items;
|
||||
Paging = pr.PageLinks;
|
||||
Columns = pr.Columns;
|
||||
|
||||
}
|
||||
}//eoc
|
||||
|
||||
}//eons
|
||||
@@ -1,42 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using AyaNova.Models;
|
||||
// using System.Collections.Generic;
|
||||
// using AyaNova.Models;
|
||||
|
||||
namespace AyaNova.Api.ControllerHelpers
|
||||
{
|
||||
// namespace AyaNova.Api.ControllerHelpers
|
||||
// {
|
||||
|
||||
|
||||
|
||||
public class ApiPagedResponse<T>
|
||||
{
|
||||
// // public class ApiPagedResponse<T>
|
||||
// // {
|
||||
|
||||
public T[] items { get; }
|
||||
public object PageLinks { get; }
|
||||
public object Columns { get; }
|
||||
// // public T[] items { get; }
|
||||
// // public object PageLinks { get; }
|
||||
// // public object Columns { get; }
|
||||
|
||||
public ApiPagedResponse(T[] returnItems, object pageLinks, object columns = null)
|
||||
{
|
||||
items = returnItems;
|
||||
PageLinks = pageLinks;
|
||||
Columns = Columns;
|
||||
// // public ApiPagedResponse(T[] returnItems, object pageLinks, object columns = null)
|
||||
// // {
|
||||
// // items = returnItems;
|
||||
// // PageLinks = pageLinks;
|
||||
// // Columns = Columns;
|
||||
|
||||
}
|
||||
}//eoc
|
||||
// // }
|
||||
// // }//eoc
|
||||
|
||||
public class ApiPagedResponse
|
||||
{
|
||||
// public class ApiPagedResponse
|
||||
// {
|
||||
|
||||
public object items { get; }
|
||||
public object PageLinks { get; }
|
||||
public Newtonsoft.Json.Linq.JArray Columns { get; }
|
||||
// public object items { get; }
|
||||
// public object PageLinks { get; }
|
||||
// public Newtonsoft.Json.Linq.JArray Columns { get; }
|
||||
|
||||
public ApiPagedResponse(object returnItems, object pageLinks, Newtonsoft.Json.Linq.JArray columns)
|
||||
{
|
||||
items = returnItems;
|
||||
PageLinks = pageLinks;
|
||||
Columns = columns;
|
||||
// public ApiPagedResponse(object returnItems, object pageLinks, Newtonsoft.Json.Linq.JArray columns)
|
||||
// {
|
||||
// items = returnItems;
|
||||
// PageLinks = pageLinks;
|
||||
// Columns = columns;
|
||||
|
||||
}
|
||||
}//eoc
|
||||
// }
|
||||
// }//eoc
|
||||
|
||||
|
||||
}//eons
|
||||
// }//eons
|
||||
@@ -10,25 +10,31 @@ namespace AyaNova.Api.ControllerHelpers
|
||||
public const int DefaultOffset = 0;
|
||||
public const int DefaultLimit = 25;
|
||||
|
||||
[FromQuery]
|
||||
[FromBody]
|
||||
[Range(0, int.MaxValue)]
|
||||
public int? Offset { get; set; }
|
||||
|
||||
[FromQuery]
|
||||
[FromBody]
|
||||
[Range(1, MaxPageSize, ErrorMessage = "Limit must be greater than 0 and less than 1000.")]
|
||||
public int? Limit { get; set; }
|
||||
|
||||
//Data filter id to use with this list query
|
||||
//0 or less means no filter
|
||||
[FromQuery]
|
||||
public long DataFilterId { get; set; }
|
||||
// //Data filter id to use with this list query
|
||||
// //0 or less means no filter
|
||||
// [FromBody]
|
||||
// public long DataFilterId { get; set; }
|
||||
|
||||
[FromQuery]
|
||||
[FromBody]
|
||||
public bool Mini { get; set; }
|
||||
|
||||
[FromQuery, Required]
|
||||
[FromBody, Required]
|
||||
public string DataListKey { get; set; }
|
||||
|
||||
[FromBody]
|
||||
public string FilterJson { get; set; }
|
||||
|
||||
[FromBody]
|
||||
public string SortJson { get; set; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,89 +1,89 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
// using System;
|
||||
// using Microsoft.AspNetCore.Routing;
|
||||
// using Microsoft.AspNetCore.Mvc;
|
||||
// using Newtonsoft.Json;
|
||||
|
||||
namespace AyaNova.Api.ControllerHelpers
|
||||
{
|
||||
// namespace AyaNova.Api.ControllerHelpers
|
||||
// {
|
||||
|
||||
public class PaginationLinkBuilder
|
||||
{ //adapted from //https://www.jerriepelser.com/blog/paging-in-aspnet-webapi-pagination-links/
|
||||
public Uri FirstPage { get; private set; }
|
||||
public Uri LastPage { get; private set; }
|
||||
public Uri NextPage { get; private set; }
|
||||
public Uri PreviousPage { get; private set; }
|
||||
public ListOptions PagingOptions { get; }
|
||||
public long TotalRecordCount { get; }
|
||||
// public class PaginationLinkBuilder
|
||||
// { //adapted from //https://www.jerriepelser.com/blog/paging-in-aspnet-webapi-pagination-links/
|
||||
// public Uri FirstPage { get; private set; }
|
||||
// public Uri LastPage { get; private set; }
|
||||
// public Uri NextPage { get; private set; }
|
||||
// public Uri PreviousPage { get; private set; }
|
||||
// public ListOptions PagingOptions { get; }
|
||||
// public long TotalRecordCount { get; }
|
||||
|
||||
public PaginationLinkBuilder(IUrlHelper urlHelper, string routeName, object routeValues, ListOptions pagingOptions, long totalRecordCount)
|
||||
{
|
||||
PagingOptions = pagingOptions;
|
||||
TotalRecordCount = totalRecordCount;
|
||||
// public PaginationLinkBuilder(IUrlHelper urlHelper, string routeName, object routeValues, ListOptions pagingOptions, long totalRecordCount)
|
||||
// {
|
||||
// PagingOptions = pagingOptions;
|
||||
// TotalRecordCount = totalRecordCount;
|
||||
|
||||
// Determine total number of pages
|
||||
var pageCount = totalRecordCount > 0
|
||||
? (int)Math.Ceiling(totalRecordCount / (double)pagingOptions.Limit)
|
||||
: 0;
|
||||
// // Determine total number of pages
|
||||
// var pageCount = totalRecordCount > 0
|
||||
// ? (int)Math.Ceiling(totalRecordCount / (double)pagingOptions.Limit)
|
||||
// : 0;
|
||||
|
||||
// Create page links
|
||||
// // Create page links
|
||||
|
||||
FirstPage = new Uri(urlHelper.Link(routeName, new RouteValueDictionary(routeValues)
|
||||
{
|
||||
{"pageNo", 1},
|
||||
{"pageSize", pagingOptions.Limit}
|
||||
}));
|
||||
// FirstPage = new Uri(urlHelper.Link(routeName, new RouteValueDictionary(routeValues)
|
||||
// {
|
||||
// {"pageNo", 1},
|
||||
// {"pageSize", pagingOptions.Limit}
|
||||
// }));
|
||||
|
||||
|
||||
LastPage = new Uri(urlHelper.Link(routeName, new RouteValueDictionary(routeValues)
|
||||
{
|
||||
{"pageNo", pageCount},
|
||||
{"pageSize", pagingOptions.Limit}
|
||||
}));
|
||||
// LastPage = new Uri(urlHelper.Link(routeName, new RouteValueDictionary(routeValues)
|
||||
// {
|
||||
// {"pageNo", pageCount},
|
||||
// {"pageSize", pagingOptions.Limit}
|
||||
// }));
|
||||
|
||||
if (pagingOptions.Offset > 1)
|
||||
{
|
||||
PreviousPage = new Uri(urlHelper.Link(routeName, new RouteValueDictionary(routeValues)
|
||||
{
|
||||
{"pageNo", pagingOptions.Offset - 1},
|
||||
{"pageSize", pagingOptions.Limit}
|
||||
}));
|
||||
}
|
||||
// if (pagingOptions.Offset > 1)
|
||||
// {
|
||||
// PreviousPage = new Uri(urlHelper.Link(routeName, new RouteValueDictionary(routeValues)
|
||||
// {
|
||||
// {"pageNo", pagingOptions.Offset - 1},
|
||||
// {"pageSize", pagingOptions.Limit}
|
||||
// }));
|
||||
// }
|
||||
|
||||
|
||||
|
||||
if (pagingOptions.Offset < pageCount)
|
||||
{
|
||||
NextPage = new Uri(urlHelper.Link(routeName, new RouteValueDictionary(routeValues)
|
||||
{
|
||||
{"pageNo", pagingOptions.Offset + 1},
|
||||
{"pageSize", pagingOptions.Limit}
|
||||
}));
|
||||
}
|
||||
// if (pagingOptions.Offset < pageCount)
|
||||
// {
|
||||
// NextPage = new Uri(urlHelper.Link(routeName, new RouteValueDictionary(routeValues)
|
||||
// {
|
||||
// {"pageNo", pagingOptions.Offset + 1},
|
||||
// {"pageSize", pagingOptions.Limit}
|
||||
// }));
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Return paging data suitable for API return
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Object PagingLinksObject()
|
||||
{
|
||||
return new
|
||||
{
|
||||
Count = TotalRecordCount,
|
||||
Offset = PagingOptions.Offset,
|
||||
Limit = PagingOptions.Limit,
|
||||
First = FirstPage,
|
||||
Previous = PreviousPage,
|
||||
Next = NextPage,
|
||||
Last = LastPage
|
||||
};
|
||||
}
|
||||
// /// <summary>
|
||||
// /// Return paging data suitable for API return
|
||||
// /// </summary>
|
||||
// /// <returns></returns>
|
||||
// public Object PagingLinksObject()
|
||||
// {
|
||||
// return new
|
||||
// {
|
||||
// Count = TotalRecordCount,
|
||||
// Offset = PagingOptions.Offset,
|
||||
// Limit = PagingOptions.Limit,
|
||||
// First = FirstPage,
|
||||
// Previous = PreviousPage,
|
||||
// Next = NextPage,
|
||||
// Last = LastPage
|
||||
// };
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
Reference in New Issue
Block a user