Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1012 from bacongobbler/non-nullable-page-size
Browse files Browse the repository at this point in the history
page fields must be required
  • Loading branch information
bacongobbler authored Jul 8, 2022
2 parents 06ff476 + 07c3b48 commit fc9855c
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 37 deletions.
18 changes: 11 additions & 7 deletions src/Core/Models/Page.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Hippo.Core.Models;
using System.ComponentModel.DataAnnotations;

namespace Hippo.Core.Models;

public class Page<TModel>
{
Expand All @@ -15,30 +17,32 @@ public Page(IReadOnlyCollection<TModel> items, int totalItems)
/// <summary>
/// the fetched items
/// </summary>
[Required]
public IReadOnlyCollection<TModel> Items { get; set; } = new List<TModel>();

/// <summary>
/// the total number of items for the requested query
/// </summary>
[Required]
public int TotalItems { get; set; }

/// <summary>
/// The zero based page index of the current data
/// </summary>
public int? PageIndex { get; set; }
[Required]
public int PageIndex { get; set; }

/// <summary>
/// The requested page size, not to be confused with the number of quered records
/// </summary>
public int? PageSize { get; set; }
[Required]
public int PageSize { get; set; }

public bool? IsLastPage
[Required]
public bool IsLastPage
{
get
{
if (!PageIndex.HasValue || !PageSize.HasValue)
return null;

return TotalItems == PageIndex * PageSize + Items.Count;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/Web/ClientApp/src/app/core/api/v1/model/appItemPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { AppItem } from './appItem';


export interface AppItemPage {
items?: Array<AppItem> | null;
totalItems?: number;
pageIndex?: number | null;
pageSize?: number | null;
readonly isLastPage?: boolean | null;
items: Array<AppItem>;
totalItems: number;
pageIndex: number;
pageSize: number;
readonly isLastPage: boolean;
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { CertificateItem } from './certificateItem';


export interface CertificateItemPage {
items?: Array<CertificateItem> | null;
totalItems?: number;
pageIndex?: number | null;
pageSize?: number | null;
readonly isLastPage?: boolean | null;
items: Array<CertificateItem>;
totalItems: number;
pageIndex: number;
pageSize: number;
readonly isLastPage: boolean;
}

10 changes: 5 additions & 5 deletions src/Web/ClientApp/src/app/core/api/v1/model/channelItemPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { ChannelItem } from './channelItem';


export interface ChannelItemPage {
items?: Array<ChannelItem> | null;
totalItems?: number;
pageIndex?: number | null;
pageSize?: number | null;
readonly isLastPage?: boolean | null;
items: Array<ChannelItem>;
totalItems: number;
pageIndex: number;
pageSize: number;
readonly isLastPage: boolean;
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { ChannelJobStatusItem } from './channelJobStatusItem';


export interface ChannelJobStatusItemPage {
items?: Array<ChannelJobStatusItem> | null;
totalItems?: number;
pageIndex?: number | null;
pageSize?: number | null;
readonly isLastPage?: boolean | null;
items: Array<ChannelJobStatusItem>;
totalItems: number;
pageIndex: number;
pageSize: number;
readonly isLastPage: boolean;
}

10 changes: 5 additions & 5 deletions src/Web/ClientApp/src/app/core/api/v1/model/revisionItemPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import { RevisionItem } from './revisionItem';


export interface RevisionItemPage {
items?: Array<RevisionItem> | null;
totalItems?: number;
pageIndex?: number | null;
pageSize?: number | null;
readonly isLastPage?: boolean | null;
items: Array<RevisionItem>;
totalItems: number;
pageIndex: number;
pageSize: number;
readonly isLastPage: boolean;
}

10 changes: 5 additions & 5 deletions src/Web/ClientApp/src/app/core/api/v1/model/stringPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@


export interface StringPage {
items?: Array<string> | null;
totalItems?: number;
pageIndex?: number | null;
pageSize?: number | null;
readonly isLastPage?: boolean | null;
items: Array<string>;
totalItems: number;
pageIndex: number;
pageSize: number;
readonly isLastPage: boolean;
}

0 comments on commit fc9855c

Please sign in to comment.