🐛 Dozens of bug fixes

This commit is contained in:
2025-08-25 13:43:40 +08:00
parent 915054fce0
commit 75c92c51db
2 changed files with 8 additions and 19 deletions

View File

@@ -33,12 +33,12 @@ public class PostCategoryController(AppDatabase db) : ControllerBase
var totalCount = await categoriesQuery.CountAsync();
Response.Headers.Append("X-Total", totalCount.ToString());
// Get categories with their post counts in a single query
var categories = await categoriesQuery
.Skip(offset)
.Take(take)
.Select(c => new
.Select(c => new
{
Category = c,
PostCount = c.Posts.Count
@@ -46,15 +46,13 @@ public class PostCategoryController(AppDatabase db) : ControllerBase
.ToListAsync();
// 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;
return x.Category;
}).ToList();
return Ok(result);
return Ok(categories);
}
[HttpGet("tags")]
@@ -83,12 +81,12 @@ public class PostCategoryController(AppDatabase db) : ControllerBase
var totalCount = await tagsQuery.CountAsync();
Response.Headers.Append("X-Total", totalCount.ToString());
// Get tags with their post counts in a single query
var tags = await tagsQuery
.Skip(offset)
.Take(take)
.Select(t => new
.Select(t => new
{
Tag = t,
PostCount = t.Posts.Count
@@ -96,7 +94,7 @@ public class PostCategoryController(AppDatabase db) : ControllerBase
.ToListAsync();
// 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;
return x.Tag;
@@ -122,4 +120,4 @@ public class PostCategoryController(AppDatabase db) : ControllerBase
return NotFound();
return Ok(tag);
}
}
}