mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-11 14:28:40 +00:00
Implement pages for profile photos
This commit is contained in:
parent
67aa11b1a6
commit
c415691d72
1 changed files with 8 additions and 2 deletions
|
@ -1,4 +1,5 @@
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -71,13 +72,18 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("photos/by")]
|
[HttpGet("photos/by")]
|
||||||
public async Task<IActionResult> UserPhotos([FromQuery] string user)
|
public async Task<IActionResult> UserPhotos([FromQuery] string user, [FromQuery] int pageStart, [FromQuery] int pageSize)
|
||||||
{
|
{
|
||||||
User? userFromQuery = await this.database.Users.FirstOrDefaultAsync(u => u.Username == user);
|
User? userFromQuery = await this.database.Users.FirstOrDefaultAsync(u => u.Username == user);
|
||||||
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
|
||||||
if (user == null) return this.NotFound();
|
if (user == null) return this.NotFound();
|
||||||
|
|
||||||
List<Photo> photos = await this.database.Photos.Where(p => p.CreatorId == userFromQuery.UserId).Take(10).ToListAsync();
|
List<Photo> 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));
|
string response = photos.Aggregate(string.Empty, (s, photo) => s + photo.Serialize(0));
|
||||||
return this.Ok(LbpSerializer.StringElement("photos", response));
|
return this.Ok(LbpSerializer.StringElement("photos", response));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue