API mostly working, starting to work on webapp

This commit is contained in:
Cameron
2024-08-23 23:52:36 -05:00
commit a4403ce17b
26 changed files with 1725 additions and 0 deletions

40
Models/ComicData.cs Normal file
View File

@@ -0,0 +1,40 @@
using ComiServ.Entities;
namespace ComiServ.Models
{
public class ComicData
{
public string Handle { get; set; }
public bool Exists { get; set; }
public string Filepath { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int PageCount { get; set; }
public long SizeBytes { get; set; }
public string FileXxhash64 { get; set; }
public List<string> Authors { get; set; }
public List<string> Tags { get; set; }
public ComicData(Comic comic)
{
Handle = comic.Handle;
Exists = comic.Exists;
Filepath = comic.Filepath;
Title = comic.Title;
PageCount = comic.PageCount;
SizeBytes = comic.SizeBytes;
FileXxhash64 = "";
var unsigned = (UInt64)comic.FileXxhash64;
for (int i = 0; i < 8; i++)
{
var c = unsigned % 16;
if (c < 10)
FileXxhash64 += ((char)('0' + c)).ToString();
else
FileXxhash64 += ((char)('A' + c - 10)).ToString();
unsigned /= 16;
}
Authors = comic.ComicAuthors.Select(a => a.Author.Name).ToList();
Tags = comic.ComicTags.Select(a => a.Tag.Name).ToList();
}
}
}

View File

@@ -0,0 +1,10 @@
namespace ComiServ.Models
{
public class ComicMetadataUpdate
{
public string? Title { get; set; }
public string? Description { get; set; }
public List<string>? Tags { get; set; }
public List<string>? Authors { get; set; }
}
}

35
Models/Paginated.cs Normal file
View File

@@ -0,0 +1,35 @@
namespace ComiServ.Models
{
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)
{
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.Take(max + 1).ToList();
if (Items.Count > max)
{
Last = false;
Items.RemoveAt(max);
}
else
{
Last = true;
}
Count = Items.Count;
}
}
}

34
Models/RequestError.cs Normal file
View File

@@ -0,0 +1,34 @@
namespace ComiServ.Models
{
public class RequestError
{
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 string[] Errors { get; }
public RequestError(string ErrorMessage)
{
Errors = [ErrorMessage];
}
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))
;
}
}
}

32
Models/Truncated.cs Normal file
View File

@@ -0,0 +1,32 @@
using System.Reflection.PortableExecutable;
namespace ComiServ.Models
{
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> items)
{
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;
if (Items.Count > 0)
Items.RemoveAt(max);
}
else
{
Complete = false;
}
Count = Items.Count;
}
}
}