summaryrefslogtreecommitdiff
path: root/Controllers/ApiFeedController.cs
blob: 068cc1715127b74e59a34d5f8acd7df7dc07024c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using HyperBooru.ApiModels;
using HyperBooru.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace HyperBooru.Controllers;

[ApiController]
[Authorize]
[Route("/api/feed")]
public class ApiFeedController : Controller {
    private IFeedService                 feedService;

    public ApiFeedController(IDbContextFactory<HBContext> dbFactory, IFeedService feedService) =>
        this.feedService = feedService;

    [HttpPost]
    public IActionResult FetchChunkAsync([FromBody] FeedRequest feedRequest) {
        if(feedRequest.Count > 1000)
            throw new ApiModels.ArgumentException("Total number of requested items exceeds maximum");

        return Ok(feedService.LoadChunk(feedRequest).Select(m => m.Guid).ToArray());
    }
}