first commit
This commit is contained in:
37
MyNewProjectName.Contracts/Common/PagedList.cs
Normal file
37
MyNewProjectName.Contracts/Common/PagedList.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
namespace MyNewProjectName.Contracts.Common
|
||||
{
|
||||
// PagedList model to support pagination in API responses
|
||||
public class PagedList<T>
|
||||
{
|
||||
// Items in the current page
|
||||
public List<T> Items { get; set; } = new List<T>();
|
||||
|
||||
// Total count of items across all pages
|
||||
public int TotalCount { get; set; }
|
||||
|
||||
// Current page number
|
||||
public int PageNumber { get; set; }
|
||||
|
||||
// Page size (items per page)
|
||||
public int PageSize { get; set; }
|
||||
|
||||
// Total number of pages
|
||||
public int TotalPages => (int)Math.Ceiling(TotalCount / (double)PageSize);
|
||||
|
||||
// Flag indicating if there is a previous page
|
||||
public bool HasPreviousPage => PageNumber > 1;
|
||||
|
||||
// Flag indicating if there is a next page
|
||||
public bool HasNextPage => PageNumber < TotalPages;
|
||||
public PagedList(List<T> items, int totalCount, int pageNumber, int pageSize)
|
||||
{
|
||||
Items = items;
|
||||
TotalCount = totalCount;
|
||||
PageNumber = pageNumber;
|
||||
PageSize = pageSize;
|
||||
}
|
||||
|
||||
// Default constructor
|
||||
public PagedList() { }
|
||||
}
|
||||
}
|
||||
19
MyNewProjectName.Contracts/Common/PaginationParams.cs
Normal file
19
MyNewProjectName.Contracts/Common/PaginationParams.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace MyNewProjectName.Contracts.Common
|
||||
{
|
||||
// Parameters for handling pagination in requests
|
||||
public class PaginationParams
|
||||
{
|
||||
private const int MaxPageSize = 1000;
|
||||
private int _pageSize = 50;
|
||||
|
||||
// Page number (default is 1)
|
||||
public int PageNumber { get; set; } = 1;
|
||||
|
||||
// Page size with validation to ensure it doesn't exceed MaxPageSize
|
||||
public int PageSize
|
||||
{
|
||||
get => _pageSize;
|
||||
set => _pageSize = (value > MaxPageSize) ? MaxPageSize : value;
|
||||
}
|
||||
}
|
||||
}
|
||||
21
MyNewProjectName.Contracts/Common/ServiceResponse.cs
Normal file
21
MyNewProjectName.Contracts/Common/ServiceResponse.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace MyNewProjectName.Contracts.Common
|
||||
{
|
||||
// Generic response model for all API endpoints
|
||||
public class ServiceResponse<T>
|
||||
{
|
||||
// Success status of the request
|
||||
public bool Success { get; set; } = true;
|
||||
|
||||
// Response message
|
||||
public string Message { get; set; } = string.Empty;
|
||||
|
||||
// Response data
|
||||
public T? Data { get; set; }
|
||||
|
||||
// Error details if any
|
||||
public List<string>? Errors { get; set; }
|
||||
|
||||
// Field-specific validation errors for frontend form validation
|
||||
public Dictionary<string, List<string>>? FieldErrors { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user