From 79c87f2091b9283c349470c281775147bb8c9180 Mon Sep 17 00:00:00 2001 From: Dominic Villemure Date: Sun, 25 Aug 2024 10:05:34 -0400 Subject: [PATCH] re-add the missing ordering in the query --- .../Contents/Handlers/GetContentsByCreator.cs | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Web/Features/Contents/Handlers/GetContentsByCreator.cs b/src/Web/Features/Contents/Handlers/GetContentsByCreator.cs index 52247c9..571815d 100644 --- a/src/Web/Features/Contents/Handlers/GetContentsByCreator.cs +++ b/src/Web/Features/Contents/Handlers/GetContentsByCreator.cs @@ -46,7 +46,6 @@ public class GetContentsByCreatorHandler( // INNER JOIN "Content"."Creators" AS creator ON content."CreatedBy" = creator."Id" // LEFT JOIN "Content"."Images" AS i ON creator."Id" = i."CreatorId" // LEFT JOIN "Content"."Colors" AS c ON creator."Id" = c."CreatorId" -// LEFT JOIN "Content"."ContentReactions" AS cr ON content."Id" = cr."ContentId" // WHERE content."CreatedBy" = '{req.CreatorId}' // AND content."DeletedBy" IS NULL // """); @@ -66,12 +65,20 @@ public class GetContentsByCreatorHandler( // var results = await context // .Database // .SqlQueryRaw(query) -// .Include(c => c.Reactions) // .ToListAsync(cancellationToken: ct); - var content = await context - .Contents + var query = context.Contents + .Where(c => c.CreatedBy == req.CreatorId && c.DeletedAt == null) + .OrderByDescending(c => c.CreatedAt); + + if (req.LastId.HasValue) + { + query = query.Where(c => c.Id > req.LastId.Value) + .OrderByDescending(c => c.CreatedAt); + } + + var content = await query .Select(c => new ContentModel { Id = c.Id, @@ -88,10 +95,12 @@ public class GetContentsByCreatorHandler( Urls = c.Urls, Reactions = c.Reactions.Select(x => new ReactionModel { - Reaction = x.Reaction.FromEnum(), UserId = x.UserId, UserName = x.UserName + Reaction = x.Reaction.FromEnum(), + UserId = x.UserId, + UserName = x.UserName }).ToList() }) - .Where(x => x.CreatedBy == req.CreatorId && x.DeletedAt == null) + .Take(req.PageSize) .ToListAsync(ct); await SendAsync(content, cancellation: ct);