mirror of
https://github.com/Ikatono/ComiServ.git
synced 2026-01-14 05:47:48 -06:00
updated controllers and some services to use async/await
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
namespace ComiServ.Models
|
||||
{
|
||||
public record class AuthorResponse(string Name, int WorkCount)
|
||||
{
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public record class AuthorResponse(string Name, int WorkCount)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
namespace ComiServ.Models
|
||||
{
|
||||
//handle is taken from URL
|
||||
public record class ComicDeleteRequest
|
||||
(
|
||||
bool DeleteIfFileExists
|
||||
);
|
||||
}
|
||||
namespace ComiServ.Models;
|
||||
|
||||
//handle is taken from URL
|
||||
public record class ComicDeleteRequest
|
||||
(
|
||||
bool DeleteIfFileExists
|
||||
);
|
||||
|
||||
@@ -1,23 +1,22 @@
|
||||
using ComiServ.Entities;
|
||||
|
||||
namespace ComiServ.Models
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public class ComicDuplicateList
|
||||
{
|
||||
public class ComicDuplicateList
|
||||
public long Hash { get; set; }
|
||||
public int Count { get; set; }
|
||||
public List<ComicData> Comics { get; set; }
|
||||
public ComicDuplicateList(long hash, IEnumerable<Comic> comics)
|
||||
{
|
||||
public long Hash { get; set; }
|
||||
public int Count { get; set; }
|
||||
public List<ComicData> Comics { get; set; }
|
||||
public ComicDuplicateList(long hash, IEnumerable<Comic> comics)
|
||||
{
|
||||
Hash = hash;
|
||||
Comics = comics.Select(c => new ComicData(c)).ToList();
|
||||
Count = Comics.Count;
|
||||
}
|
||||
public ComicDuplicateList(long hash, IEnumerable<ComicData> comics)
|
||||
{
|
||||
Hash = hash;
|
||||
Comics = comics.ToList();
|
||||
Count = Comics.Count;
|
||||
}
|
||||
Hash = hash;
|
||||
Comics = comics.Select(c => new ComicData(c)).ToList();
|
||||
Count = Comics.Count;
|
||||
}
|
||||
public ComicDuplicateList(long hash, IEnumerable<ComicData> comics)
|
||||
{
|
||||
Hash = hash;
|
||||
Comics = comics.ToList();
|
||||
Count = Comics.Count;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
namespace ComiServ.Models
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public class ComicMetadataUpdateRequest
|
||||
{
|
||||
public class ComicMetadataUpdateRequest
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public List<string>? Tags { get; set; }
|
||||
public List<string>? Authors { get; set; }
|
||||
}
|
||||
public string? Title { get; set; }
|
||||
public string? Description { get; set; }
|
||||
public List<string>? Tags { get; set; }
|
||||
public List<string>? Authors { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
namespace ComiServ.Models
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public record class LibraryResponse(int ComicCount, int UniqueFiles)
|
||||
{
|
||||
public record class LibraryResponse(int ComicCount, int UniqueFiles)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,95 @@
|
||||
namespace ComiServ.Models
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComiServ.Models;
|
||||
public class Paginated<T>
|
||||
{
|
||||
public class Paginated<T>
|
||||
public int Max { get; }
|
||||
public int Page { get; }
|
||||
public bool Last { get; }
|
||||
public int Count { get; }
|
||||
public List<T> Items { get; }
|
||||
public Paginated(int max, int page, IEnumerable<T> iter)
|
||||
{
|
||||
public int Max { get; }
|
||||
public int Page { get;}
|
||||
public bool Last { get; }
|
||||
public int Count { get; }
|
||||
public List<T> Items { get; }
|
||||
public Paginated(int max, int page, IEnumerable<T> iter)
|
||||
if (max <= 0)
|
||||
{
|
||||
Max = max;
|
||||
Page = page;
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
if (page < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(page), page, "must be greater than or equal to 0");
|
||||
}
|
||||
Items = iter.Skip(max * page).Take(max + 1).ToList();
|
||||
if (Items.Count > max)
|
||||
{
|
||||
Last = false;
|
||||
Items.RemoveAt(max);
|
||||
}
|
||||
else
|
||||
{
|
||||
Last = true;
|
||||
}
|
||||
Count = Items.Count;
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
if (page < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(page), page, "must be greater than or equal to 0");
|
||||
}
|
||||
Max = max;
|
||||
Page = page;
|
||||
Items = iter.Skip(max * page).Take(max + 1).ToList();
|
||||
if (Items.Count > max)
|
||||
{
|
||||
Last = false;
|
||||
Items.RemoveAt(max);
|
||||
}
|
||||
else
|
||||
{
|
||||
Last = true;
|
||||
}
|
||||
Count = Items.Count;
|
||||
}
|
||||
private Paginated(int max, int page, bool last, List<T> items)
|
||||
{
|
||||
Max = max;
|
||||
Page = page;
|
||||
Last = last;
|
||||
Items = items;
|
||||
Count = Items.Count;
|
||||
}
|
||||
public static async Task<Paginated<T>> CreateAsync(int max, int page, IQueryable<T> iter)
|
||||
{
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
if (page < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(page), page, "must be greater than or equal to 0");
|
||||
}
|
||||
var items = await iter.Skip(max * page).Take(max + 1).ToListAsync();
|
||||
bool last = true;
|
||||
if (items.Count > max)
|
||||
{
|
||||
last = false;
|
||||
items.RemoveAt(max);
|
||||
}
|
||||
return new(max, page, last, items);
|
||||
}
|
||||
public static async Task<Paginated<T>> CreateAsync(int max, int page, IAsyncEnumerable<T> iter)
|
||||
{
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
if (page < 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(page), page, "must be greater than or equal to 0");
|
||||
}
|
||||
List<T> items = [];
|
||||
var skip = max * page;
|
||||
await foreach (T item in iter)
|
||||
{
|
||||
if (skip > 0)
|
||||
{
|
||||
skip--;
|
||||
continue;
|
||||
}
|
||||
items.Add(item);
|
||||
if (items.Count >= max + 1)
|
||||
break;
|
||||
}
|
||||
var last = true;
|
||||
if (items.Count > max)
|
||||
{
|
||||
last = false;
|
||||
items.RemoveAt(max);
|
||||
}
|
||||
return new(max, page, last, items);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +1,51 @@
|
||||
using System.Collections;
|
||||
|
||||
namespace ComiServ.Models
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public class RequestError : IEnumerable<string>
|
||||
{
|
||||
public class RequestError : IEnumerable<string>
|
||||
public static RequestError InvalidHandle => new("Invalid handle");
|
||||
public static RequestError ComicNotFound => new("Comic not found");
|
||||
public static RequestError CoverNotFound => new("Cover not found");
|
||||
public static RequestError PageNotFound => new("Page not found");
|
||||
public static RequestError FileNotFound => new("File not found");
|
||||
public static RequestError ThumbnailNotFound => new("Thumbnail not found");
|
||||
public static RequestError NotAuthenticated => new("Not authenticated");
|
||||
public static RequestError NoAccess => new("User does not have access to this resource");
|
||||
public static RequestError UserNotFound => new("User not found");
|
||||
public static RequestError ComicFileExists => new("Comic file exists so comic not deleted");
|
||||
public static RequestError UserSpecificEndpoint => new("Endpoint is user-specific, requires login");
|
||||
public string[] Errors { get; }
|
||||
public RequestError(string ErrorMessage)
|
||||
{
|
||||
public static RequestError InvalidHandle => new("Invalid handle");
|
||||
public static RequestError ComicNotFound => new("Comic not found");
|
||||
public static RequestError CoverNotFound => new("Cover not found");
|
||||
public static RequestError PageNotFound => new("Page not found");
|
||||
public static RequestError FileNotFound => new("File not found");
|
||||
public static RequestError ThumbnailNotFound => new("Thumbnail not found");
|
||||
public static RequestError NotAuthenticated => new("Not authenticated");
|
||||
public static RequestError NoAccess => new("User does not have access to this resource");
|
||||
public static RequestError UserNotFound => new("User not found");
|
||||
public static RequestError ComicFileExists => new("Comic file exists so comic not deleted");
|
||||
public static RequestError UserSpecificEndpoint => new("Endpoint is user-specific, requires login");
|
||||
public string[] Errors { get; }
|
||||
public RequestError(string ErrorMessage)
|
||||
{
|
||||
Errors = [ErrorMessage];
|
||||
}
|
||||
public RequestError()
|
||||
{
|
||||
Errors = [];
|
||||
}
|
||||
public RequestError(IEnumerable<string> ErrorMessages)
|
||||
{
|
||||
Errors = ErrorMessages.ToArray();
|
||||
}
|
||||
public RequestError And(RequestError other)
|
||||
{
|
||||
return new RequestError(Errors.Concat(other.Errors));
|
||||
}
|
||||
public RequestError And(string other)
|
||||
{
|
||||
return new RequestError(Errors.Append(other));
|
||||
}
|
||||
public RequestError And(IEnumerable<string> other)
|
||||
{
|
||||
return new RequestError(Errors.Concat(other));
|
||||
}
|
||||
public IEnumerator<string> GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<string>)Errors).GetEnumerator();
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
Errors = [ErrorMessage];
|
||||
}
|
||||
public RequestError()
|
||||
{
|
||||
Errors = [];
|
||||
}
|
||||
public RequestError(IEnumerable<string> ErrorMessages)
|
||||
{
|
||||
Errors = ErrorMessages.ToArray();
|
||||
}
|
||||
public RequestError And(RequestError other)
|
||||
{
|
||||
return new RequestError(Errors.Concat(other.Errors));
|
||||
}
|
||||
public RequestError And(string other)
|
||||
{
|
||||
return new RequestError(Errors.Append(other));
|
||||
}
|
||||
public RequestError And(IEnumerable<string> other)
|
||||
{
|
||||
return new RequestError(Errors.Concat(other));
|
||||
}
|
||||
public IEnumerator<string> GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<string>)Errors).GetEnumerator();
|
||||
}
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
namespace ComiServ.Models
|
||||
{
|
||||
public record class TagResponse(string Name, int WorkCount)
|
||||
{
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public record class TagResponse(string Name, int WorkCount)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,75 @@
|
||||
using System.Reflection.PortableExecutable;
|
||||
using Microsoft.CodeAnalysis.CSharp;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Reflection.PortableExecutable;
|
||||
|
||||
namespace ComiServ.Models
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public class Truncated<T>
|
||||
{
|
||||
public class Truncated<T>
|
||||
public int Max { get; }
|
||||
public int Count { get; }
|
||||
public bool Complete { get; }
|
||||
public List<T> Items { get; }
|
||||
public Truncated(int max, IEnumerable<T> iter)
|
||||
{
|
||||
public int Max { get; }
|
||||
public int Count { get; }
|
||||
public bool Complete { get; }
|
||||
public List<T> Items { get; }
|
||||
public Truncated(int max, IEnumerable<T> items)
|
||||
if (max <= 0)
|
||||
{
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
Max = max;
|
||||
Items = items.Take(max+1).ToList();
|
||||
if (Items.Count <= max)
|
||||
{
|
||||
Complete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Items.RemoveAt(max);
|
||||
Complete = false;
|
||||
}
|
||||
Count = Items.Count;
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
Max = max;
|
||||
Items = iter.Take(max+1).ToList();
|
||||
if (Items.Count <= max)
|
||||
{
|
||||
Complete = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Items.RemoveAt(max);
|
||||
Complete = false;
|
||||
}
|
||||
Count = Items.Count;
|
||||
}
|
||||
private Truncated(int max, bool complete, List<T> items)
|
||||
{
|
||||
Max = max;
|
||||
Complete = complete;
|
||||
Count = items.Count;
|
||||
Items = items;
|
||||
}
|
||||
public static async Task<Truncated<T>> CreateAsync(int max, IQueryable<T> iter)
|
||||
{
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
var items = await iter.Take(max+1).ToListAsync();
|
||||
var complete = true;
|
||||
if (items.Count < max)
|
||||
{
|
||||
items.RemoveAt(max);
|
||||
complete = false;
|
||||
}
|
||||
return new(max, complete, items);
|
||||
}
|
||||
public static async Task<Truncated<T>> CreateAsync(int max, IAsyncEnumerable<T> iter)
|
||||
{
|
||||
if (max <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(max), max, "must be greater than 0");
|
||||
}
|
||||
List<T> items = [];
|
||||
await foreach (T item in iter)
|
||||
{
|
||||
items.Add(item);
|
||||
if (items.Count > max)
|
||||
break;
|
||||
}
|
||||
var complete = true;
|
||||
if (items.Count <= max)
|
||||
{
|
||||
items.RemoveAt(max);
|
||||
complete = false;
|
||||
}
|
||||
return new Truncated<T>(max, complete, items);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using ComiServ.Entities;
|
||||
|
||||
namespace ComiServ.Models
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public class UserCreateRequest
|
||||
{
|
||||
public class UserCreateRequest
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public UserTypeEnum UserType { get; set; }
|
||||
//NOT HASHED do not persist this object
|
||||
public string Password { get; set; }
|
||||
}
|
||||
public string Username { get; set; }
|
||||
public UserTypeEnum UserType { get; set; }
|
||||
//NOT HASHED do not persist this object
|
||||
public string Password { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
namespace ComiServ.Models
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public record class UserDescription(string Username, string Usertype)
|
||||
{
|
||||
public record class UserDescription(string Username, string Usertype);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using ComiServ.Entities;
|
||||
|
||||
namespace ComiServ.Models
|
||||
namespace ComiServ.Models;
|
||||
|
||||
public class UserModifyRequest
|
||||
{
|
||||
public class UserModifyRequest
|
||||
{
|
||||
public string Username { get; set; }
|
||||
public string? NewUsername { get; set; }
|
||||
public UserTypeEnum? NewUserType { get; set; }
|
||||
}
|
||||
public string Username { get; set; }
|
||||
public string? NewUsername { get; set; }
|
||||
public UserTypeEnum? NewUserType { get; set; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user