🐛 Dozens of bug fixes
This commit is contained in:
@@ -33,12 +33,12 @@ public class PostCategoryController(AppDatabase db) : ControllerBase
|
|||||||
|
|
||||||
var totalCount = await categoriesQuery.CountAsync();
|
var totalCount = await categoriesQuery.CountAsync();
|
||||||
Response.Headers.Append("X-Total", totalCount.ToString());
|
Response.Headers.Append("X-Total", totalCount.ToString());
|
||||||
|
|
||||||
// Get categories with their post counts in a single query
|
// Get categories with their post counts in a single query
|
||||||
var categories = await categoriesQuery
|
var categories = await categoriesQuery
|
||||||
.Skip(offset)
|
.Skip(offset)
|
||||||
.Take(take)
|
.Take(take)
|
||||||
.Select(c => new
|
.Select(c => new
|
||||||
{
|
{
|
||||||
Category = c,
|
Category = c,
|
||||||
PostCount = c.Posts.Count
|
PostCount = c.Posts.Count
|
||||||
@@ -46,15 +46,13 @@ public class PostCategoryController(AppDatabase db) : ControllerBase
|
|||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
// Project results back to the original type and set the Usage property
|
// Project results back to the original type and set the Usage property
|
||||||
var result = categories.Select(x =>
|
var result = categories.Select(x =>
|
||||||
{
|
{
|
||||||
x.Category.Usage = x.PostCount;
|
x.Category.Usage = x.PostCount;
|
||||||
return x.Category;
|
return x.Category;
|
||||||
}).ToList();
|
}).ToList();
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
|
|
||||||
return Ok(categories);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("tags")]
|
[HttpGet("tags")]
|
||||||
@@ -83,12 +81,12 @@ public class PostCategoryController(AppDatabase db) : ControllerBase
|
|||||||
|
|
||||||
var totalCount = await tagsQuery.CountAsync();
|
var totalCount = await tagsQuery.CountAsync();
|
||||||
Response.Headers.Append("X-Total", totalCount.ToString());
|
Response.Headers.Append("X-Total", totalCount.ToString());
|
||||||
|
|
||||||
// Get tags with their post counts in a single query
|
// Get tags with their post counts in a single query
|
||||||
var tags = await tagsQuery
|
var tags = await tagsQuery
|
||||||
.Skip(offset)
|
.Skip(offset)
|
||||||
.Take(take)
|
.Take(take)
|
||||||
.Select(t => new
|
.Select(t => new
|
||||||
{
|
{
|
||||||
Tag = t,
|
Tag = t,
|
||||||
PostCount = t.Posts.Count
|
PostCount = t.Posts.Count
|
||||||
@@ -96,7 +94,7 @@ public class PostCategoryController(AppDatabase db) : ControllerBase
|
|||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
// Project results back to the original type and set the Usage property
|
// Project results back to the original type and set the Usage property
|
||||||
var result = tags.Select(x =>
|
var result = tags.Select(x =>
|
||||||
{
|
{
|
||||||
x.Tag.Usage = x.PostCount;
|
x.Tag.Usage = x.PostCount;
|
||||||
return x.Tag;
|
return x.Tag;
|
||||||
@@ -122,4 +120,4 @@ public class PostCategoryController(AppDatabase db) : ControllerBase
|
|||||||
return NotFound();
|
return NotFound();
|
||||||
return Ok(tag);
|
return Ok(tag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -235,15 +235,9 @@ public class WebFeedPublicController(
|
|||||||
|
|
||||||
var accountId = Guid.Parse(currentUser.Id);
|
var accountId = Guid.Parse(currentUser.Id);
|
||||||
|
|
||||||
// Get IDs of already subscribed feeds
|
|
||||||
var subscribedFeedIds = await db.WebFeedSubscriptions
|
|
||||||
.Where(s => s.AccountId == accountId)
|
|
||||||
.Select(s => s.FeedId)
|
|
||||||
.ToListAsync();
|
|
||||||
|
|
||||||
var feedsQuery = db.WebFeeds
|
var feedsQuery = db.WebFeeds
|
||||||
.Include(f => f.Publisher)
|
.Include(f => f.Publisher)
|
||||||
.Where(f => !subscribedFeedIds.Contains(f.Id))
|
.OrderByDescending(f => f.CreatedAt)
|
||||||
.AsQueryable();
|
.AsQueryable();
|
||||||
|
|
||||||
// Apply search filter if query is provided
|
// Apply search filter if query is provided
|
||||||
@@ -256,9 +250,6 @@ public class WebFeedPublicController(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Order by most recently created first
|
|
||||||
feedsQuery = feedsQuery.OrderByDescending(f => f.CreatedAt);
|
|
||||||
|
|
||||||
var totalCount = await feedsQuery.CountAsync();
|
var totalCount = await feedsQuery.CountAsync();
|
||||||
var feeds = await feedsQuery
|
var feeds = await feedsQuery
|
||||||
.Skip(offset)
|
.Skip(offset)
|
||||||
|
Reference in New Issue
Block a user