pages implemented

This commit is contained in:
turecross321 2021-11-16 21:54:32 +01:00 committed by GitHub
commit c2f7030e5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System;
using LBPUnion.ProjectLighthouse.Serialization; using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types.Levels; using LBPUnion.ProjectLighthouse.Types.Levels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -20,7 +21,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
} }
[HttpGet("slots/search")] [HttpGet("slots/search")]
public async Task<IActionResult> SearchSlots([FromQuery] string query) public async Task<IActionResult> SearchSlots([FromQuery] string query, [FromQuery] int pageSize, [FromQuery] int pageStart)
{ {
if (query == null) return this.BadRequest(); if (query == null) return this.BadRequest();
@ -43,10 +44,14 @@ namespace LBPUnion.ProjectLighthouse.Controllers
s.SlotId.ToString().Equals(keyword) s.SlotId.ToString().Equals(keyword)
); );
List<Slot> slots = await dbQuery.ToListAsync(); List<Slot> slots = await dbQuery
.Skip(pageStart - 1)
.Take(Math.Min(pageSize, 30))
.ToListAsync();
string response = slots.Aggregate("", (current, slot) => current + slot.Serialize()); string response = slots.Aggregate("", (current, slot) => current + slot.Serialize());
return this.Ok(LbpSerializer.StringElement("slots", response)); return this.Ok(LbpSerializer.TaggedStringElement("slots", response, "total", dbQuery.Count()));
} }
} }
} }