From c415691d7207165ef168c914a7eab2d4701d7687 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sun, 7 Nov 2021 15:33:13 -0500 Subject: [PATCH] Implement pages for profile photos --- ProjectLighthouse/Controllers/PhotosController.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ProjectLighthouse/Controllers/PhotosController.cs b/ProjectLighthouse/Controllers/PhotosController.cs index 9ce5c655..0ea9d167 100644 --- a/ProjectLighthouse/Controllers/PhotosController.cs +++ b/ProjectLighthouse/Controllers/PhotosController.cs @@ -1,4 +1,5 @@ #nullable enable +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -71,13 +72,18 @@ namespace LBPUnion.ProjectLighthouse.Controllers } [HttpGet("photos/by")] - public async Task UserPhotos([FromQuery] string user) + public async Task UserPhotos([FromQuery] string user, [FromQuery] int pageStart, [FromQuery] int pageSize) { User? userFromQuery = await this.database.Users.FirstOrDefaultAsync(u => u.Username == user); // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (user == null) return this.NotFound(); - List photos = await this.database.Photos.Where(p => p.CreatorId == userFromQuery.UserId).Take(10).ToListAsync(); + List photos = await this.database.Photos.Where + (p => p.CreatorId == userFromQuery.UserId) + .OrderByDescending(s => s.Timestamp) + .Skip(pageStart - 1) + .Take(Math.Min(pageSize, 30)) + .ToListAsync(); string response = photos.Aggregate(string.Empty, (s, photo) => s + photo.Serialize(0)); return this.Ok(LbpSerializer.StringElement("photos", response)); }