Initial DeepDrft Models Project
- Track Entity & DTO - Paging models
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
namespace DeepDrftModels.DTOs;
|
||||
|
||||
public class TrackDto
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string MediaPath { get; set; }
|
||||
public string TrackName { get; set; }
|
||||
public string Artist { get; set; }
|
||||
public string? Album { get; set; }
|
||||
public string? Genre { get; set; }
|
||||
public DateOnly? ReleaseDate { get; set; }
|
||||
public string? ImagePath { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="C:\lib\NetBlocks\NetBlocks.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace DeepDrftModels.Entities;
|
||||
|
||||
public class TrackEntity
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string MediaPath { get; set; }
|
||||
public string TrackName { get; set; }
|
||||
public string Artist { get; set; }
|
||||
public string? Album { get; set; }
|
||||
public string? Genre { get; set; }
|
||||
public DateOnly? ReleaseDate { get; set; }
|
||||
public string? ImagePath { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
namespace DeepDrftModels.Models;
|
||||
|
||||
public class PagedResult<T>
|
||||
{
|
||||
public IEnumerable<T> Items { get; set; } = new List<T>();
|
||||
public int TotalCount { get; set; }
|
||||
public int Page { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
public int TotalPages => (int)Math.Ceiling((double)TotalCount / PageSize);
|
||||
public bool HasNextPage => Page < TotalPages;
|
||||
public bool HasPreviousPage => Page > 1;
|
||||
|
||||
public PagedResult()
|
||||
{
|
||||
}
|
||||
|
||||
public static PagedResult<T> From<TOther>(PagedResult<TOther> other, IEnumerable<T> items)
|
||||
{
|
||||
return new PagedResult<T>()
|
||||
{
|
||||
Items = items.ToList(),
|
||||
Page = other.Page,
|
||||
PageSize = other.PageSize,
|
||||
TotalCount = other.TotalCount,
|
||||
};
|
||||
}
|
||||
|
||||
public PagedResult(IEnumerable<T> items, int totalCount, int page, int pageSize)
|
||||
{
|
||||
Items = items.ToList() ?? new List<T>();
|
||||
TotalCount = totalCount;
|
||||
Page = page;
|
||||
PageSize = pageSize;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace DeepDrftModels.Models;
|
||||
|
||||
public class PagingParameters
|
||||
{
|
||||
private const int _maxPageSize = 100;
|
||||
private int _pageSize = 20;
|
||||
|
||||
public int Page { get; set; } = 1;
|
||||
|
||||
public int PageSize
|
||||
{
|
||||
get => _pageSize;
|
||||
set => _pageSize = value > _maxPageSize ? _maxPageSize : value;
|
||||
}
|
||||
}
|
||||
|
||||
public class PagingParameters<T> : PagingParameters
|
||||
{
|
||||
public Expression<Func<T, object>>? OrderBy { get; set; }
|
||||
public bool IsDescending { get; set; } = false;
|
||||
|
||||
public int Skip => (Page - 1) * PageSize;
|
||||
}
|
||||
Reference in New Issue
Block a user