Show proper author for photos

This commit is contained in:
jvyden 2021-11-13 06:53:00 -05:00
commit 084dcf1f75
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
2 changed files with 6 additions and 4 deletions

View file

@ -71,7 +71,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
[HttpGet("photos/user/{id:int}")]
public async Task<IActionResult> SlotPhotos(int id)
{
List<Photo> photos = await this.database.Photos.Take(10).ToListAsync();
List<Photo> photos = await this.database.Photos.Include(p => p.Creator).Take(10).ToListAsync();
string response = photos.Aggregate(string.Empty, (s, photo) => s + photo.Serialize(id));
return this.Ok(LbpSerializer.StringElement("photos", response));
}
@ -83,7 +83,9 @@ namespace LBPUnion.ProjectLighthouse.Controllers
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (user == null) return this.NotFound();
List<Photo> photos = await this.database.Photos.Where(p => p.CreatorId == userFromQuery.UserId)
List<Photo> photos = await this.database.Photos.Include
(p => p.Creator)
.Where(p => p.CreatorId == userFromQuery.UserId)
.OrderByDescending(s => s.Timestamp)
.Skip(pageStart - 1)
.Take(Math.Min(pageSize, 30))
@ -100,7 +102,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
if (user == null) return this.NotFound();
List<Photo> photos = new();
foreach (Photo photo in this.database.Photos)
foreach (Photo photo in this.database.Photos.Include(p => p.Creator))
{
photos.AddRange(photo.Subjects.Where(subject => subject.User.UserId == userFromQuery.UserId).Select(_ => photo));
}

View file

@ -92,7 +92,7 @@ namespace LBPUnion.ProjectLighthouse.Types
LbpSerializer.StringElement("medium", this.MediumHash) +
LbpSerializer.StringElement("large", this.LargeHash) +
LbpSerializer.StringElement("plan", this.PlanHash) +
LbpSerializer.StringElement("author", this.CreatorId) +
LbpSerializer.StringElement("author", this.Creator.Username) +
LbpSerializer.StringElement("subjects", subjectsAggregate) +
slot;