re-add the missing ordering in the query

This commit is contained in:
Dominic Villemure
2024-08-25 10:05:34 -04:00
parent 588be7941c
commit 79c87f2091

View File

@@ -46,7 +46,6 @@ public class GetContentsByCreatorHandler(
// INNER JOIN "Content"."Creators" AS creator ON content."CreatedBy" = creator."Id" // 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"."Images" AS i ON creator."Id" = i."CreatorId"
// LEFT JOIN "Content"."Colors" AS c ON creator."Id" = c."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}' // WHERE content."CreatedBy" = '{req.CreatorId}'
// AND content."DeletedBy" IS NULL // AND content."DeletedBy" IS NULL
// """); // """);
@@ -66,12 +65,20 @@ public class GetContentsByCreatorHandler(
// var results = await context // var results = await context
// .Database // .Database
// .SqlQueryRaw<ContentModel>(query) // .SqlQueryRaw<ContentModel>(query)
// .Include(c => c.Reactions)
// .ToListAsync(cancellationToken: ct); // .ToListAsync(cancellationToken: ct);
var content = await context var query = context.Contents
.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 .Select(c => new ContentModel
{ {
Id = c.Id, Id = c.Id,
@@ -88,10 +95,12 @@ public class GetContentsByCreatorHandler(
Urls = c.Urls, Urls = c.Urls,
Reactions = c.Reactions.Select(x => new ReactionModel 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() }).ToList()
}) })
.Where(x => x.CreatedBy == req.CreatorId && x.DeletedAt == null) .Take(req.PageSize)
.ToListAsync(ct); .ToListAsync(ct);
await SendAsync(content, cancellation: ct); await SendAsync(content, cancellation: ct);