Compare commits
2 Commits
c86d7275ec
...
6211f546b1
Author | SHA1 | Date | |
---|---|---|---|
|
6211f546b1 | ||
|
9070fe7fa3 |
@@ -45,7 +45,9 @@ public class PostController(
|
|||||||
[FromQuery(Name = "tags")] List<string>? tags = null,
|
[FromQuery(Name = "tags")] List<string>? tags = null,
|
||||||
[FromQuery(Name = "query")] string? queryTerm = null,
|
[FromQuery(Name = "query")] string? queryTerm = null,
|
||||||
[FromQuery(Name = "vector")] bool queryVector = false,
|
[FromQuery(Name = "vector")] bool queryVector = false,
|
||||||
[FromQuery(Name = "replies")] bool includeReplies = false
|
[FromQuery(Name = "replies")] bool includeReplies = false,
|
||||||
|
[FromQuery(Name = "media")] bool onlyMedia = false,
|
||||||
|
[FromQuery(Name = "shuffle")] bool shuffle = false
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
|
||||||
@@ -77,6 +79,8 @@ public class PostController(
|
|||||||
query = query.Where(p => p.Tags.Any(c => tags.Contains(c.Slug)));
|
query = query.Where(p => p.Tags.Any(c => tags.Contains(c.Slug)));
|
||||||
if (!includeReplies)
|
if (!includeReplies)
|
||||||
query = query.Where(e => e.RepliedPostId == null);
|
query = query.Where(e => e.RepliedPostId == null);
|
||||||
|
if (onlyMedia)
|
||||||
|
query = query.Where(e => e.Attachments.Count > 0);
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(queryTerm))
|
if (!string.IsNullOrWhiteSpace(queryTerm))
|
||||||
{
|
{
|
||||||
@@ -95,10 +99,15 @@ public class PostController(
|
|||||||
|
|
||||||
var totalCount = await query
|
var totalCount = await query
|
||||||
.CountAsync();
|
.CountAsync();
|
||||||
|
|
||||||
|
if (shuffle)
|
||||||
|
query = query.OrderBy(e => EF.Functions.Random());
|
||||||
|
else
|
||||||
|
query = query.OrderByDescending(e => e.PublishedAt ?? e.CreatedAt);
|
||||||
|
|
||||||
var posts = await query
|
var posts = await query
|
||||||
.Include(e => e.RepliedPost)
|
.Include(e => e.RepliedPost)
|
||||||
.Include(e => e.ForwardedPost)
|
.Include(e => e.ForwardedPost)
|
||||||
.OrderByDescending(e => e.PublishedAt ?? e.CreatedAt)
|
|
||||||
.Skip(offset)
|
.Skip(offset)
|
||||||
.Take(take)
|
.Take(take)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
Reference in New Issue
Block a user