diff --git a/Controller/PixivImagesController.cs b/Controller/PixivImagesController.cs new file mode 100644 index 0000000..da6aa9e --- /dev/null +++ b/Controller/PixivImagesController.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.OData.Query; +using Microsoft.AspNetCore.OData.Results; +using Microsoft.AspNetCore.OData.Routing.Controllers; + +public class PixivImagesController : ODataController +{ + private readonly AppDbContext _db; + public PixivImagesController(AppDbContext db) => _db = db; + + // GET /odata/PixivImages + [EnableQuery] + public IQueryable Get() + => _db.PixivImages; + + // GET /odata/PixivImages('{id}') + [EnableQuery] + public SingleResult Get([FromRoute] Guid key) + => SingleResult.Create(_db.PixivImages.Where(x => x.Id == key)); +} diff --git a/Data/DbContext.cs b/Data/DbContext.cs index e8944d8..8e0846d 100644 --- a/Data/DbContext.cs +++ b/Data/DbContext.cs @@ -6,4 +6,5 @@ : base(options) { } public DbSet HololiveSchedule => Set(); + public DbSet PixivImages => Set(); } diff --git a/Data/PixivImage.cs b/Data/PixivImage.cs new file mode 100644 index 0000000..1c35a99 --- /dev/null +++ b/Data/PixivImage.cs @@ -0,0 +1,14 @@ +public class PixivImage +{ + public Guid Id { get; set; } + public string RelativePath { get; set; } = null!; + public string FileName { get; set; } = null!; + public long? PixivId { get; set; } + public int? PageIndex { get; set; } + public string? Tags { get; set; } + public string? Title { get; set; } + public string? Description { get; set; } + public string? AuthorId { get; set; } + public string? AuthorName { get; set; } + public DateTimeOffset ImportedAtUtc { get; set; } +} diff --git a/Program.cs b/Program.cs index 6c88158..a0ad811 100644 --- a/Program.cs +++ b/Program.cs @@ -10,6 +10,7 @@ var odataBuilder = new ODataConventionModelBuilder(); odataBuilder.EntitySet("HololiveSchedule"); +odataBuilder.EntitySet("PixivImages"); builder.Services.AddControllers() .AddOData(opt =>