API mostly working, starting to work on webapp
This commit is contained in:
17
Entities/Author.cs
Normal file
17
Entities/Author.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
//using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComiServ.Entities
|
||||
{
|
||||
[Index(nameof(Name), IsUnique = true)]
|
||||
public class Author
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = null!;
|
||||
public ICollection<ComicAuthor> ComicAuthors = null!;
|
||||
}
|
||||
}
|
||||
32
Entities/Comic.cs
Normal file
32
Entities/Comic.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using ComiServ.Controllers;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComiServ.Entities
|
||||
{
|
||||
[Index(nameof(Handle), IsUnique = true)]
|
||||
[Index(nameof(Filepath), IsUnique = true)]
|
||||
public class Comic
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public bool Exists { get; set; }
|
||||
//id exposed through the API
|
||||
[Required]
|
||||
[StringLength(ComicsContext.HANDLE_LENGTH)]
|
||||
public string Handle { get; set; } = null!;
|
||||
[Required]
|
||||
public string Filepath { get; set; } = null!;
|
||||
[Required]
|
||||
public string Title { get; set; } = null!;
|
||||
[Required]
|
||||
public string Description { get; set; } = null!;
|
||||
public int PageCount { get; set; }
|
||||
public long SizeBytes { get; set; }
|
||||
public long FileXxhash64 { get; set; }
|
||||
[InverseProperty("Comic")]
|
||||
public ICollection<ComicTag> ComicTags { get; set; } = [];
|
||||
[InverseProperty("Comic")]
|
||||
public ICollection<ComicAuthor> ComicAuthors { get; set; } = [];
|
||||
}
|
||||
}
|
||||
21
Entities/ComicAuthor.cs
Normal file
21
Entities/ComicAuthor.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComiServ.Entities
|
||||
{
|
||||
[PrimaryKey("ComicId", "AuthorId")]
|
||||
[Index("ComicId")]
|
||||
[Index("AuthorId")]
|
||||
public class ComicAuthor
|
||||
{
|
||||
[ForeignKey(nameof(Comic))]
|
||||
public int ComicId { get; set; }
|
||||
[Required]
|
||||
public Comic Comic { get; set; } = null!;
|
||||
[ForeignKey(nameof(Author))]
|
||||
public int AuthorId { get; set; }
|
||||
[Required]
|
||||
public Author Author { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
15
Entities/ComicTag.cs
Normal file
15
Entities/ComicTag.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComiServ.Entities
|
||||
{
|
||||
[PrimaryKey("ComicId", "TagId")]
|
||||
[Index("ComicId")]
|
||||
[Index("TagId")]
|
||||
public class ComicTag
|
||||
{
|
||||
public int ComicId { get; set; }
|
||||
public Comic Comic { get; set; } = null!;
|
||||
public int TagId { get; set; }
|
||||
public Tag Tag { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
12
Entities/Cover.cs
Normal file
12
Entities/Cover.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ComiServ.Entities
|
||||
{
|
||||
[PrimaryKey("FileXxhash64")]
|
||||
public class Cover
|
||||
{
|
||||
public long FileXxhash64 { get; set; }
|
||||
public string Filename { get; set; } = null!;
|
||||
public byte[] CoverFile { get; set; } = null!;
|
||||
}
|
||||
}
|
||||
35
Entities/EntitySwaggerFilter.cs
Normal file
35
Entities/EntitySwaggerFilter.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace ComiServ.Entities
|
||||
{
|
||||
/// <summary>
|
||||
/// This was originally made to remove Entity types that were being added to the Swagger schema.
|
||||
/// I found that there was a bug a `ProducesResponseTypeAttribute` that caused it, and this is
|
||||
/// no longer necessary. I changed Apply to a nop but am keeping this around as an example and
|
||||
/// in case I actually need something like this in the future.
|
||||
/// </summary>
|
||||
public class EntitySwaggerFilter : ISchemaFilter
|
||||
{
|
||||
public readonly static string[] FILTER = [
|
||||
nameof(Author),
|
||||
nameof(Comic),
|
||||
nameof(ComicAuthor),
|
||||
nameof(ComicTag),
|
||||
nameof(Cover),
|
||||
nameof(Tag)
|
||||
];
|
||||
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
|
||||
{
|
||||
return;
|
||||
foreach (var item in context.SchemaRepository.Schemas.Keys)
|
||||
{
|
||||
if (FILTER.Contains(item))
|
||||
{
|
||||
context.SchemaRepository.Schemas.Remove(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Entities/Tag.cs
Normal file
16
Entities/Tag.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace ComiServ.Entities
|
||||
{
|
||||
[Index(nameof(Name), IsUnique = true)]
|
||||
public class Tag
|
||||
{
|
||||
//[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; } = null!;
|
||||
public ICollection<ComicTag> ComicTags = null!;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user