From 08941a282b17f835b345f7e1f1948ce2512952ba Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 24 Dec 2025 00:10:07 +0800 Subject: [PATCH] :truck: Move the categories subscription listing API path --- .../Post/AccountHelperClient.cs | 0 .../Post/PostCategorySubController.cs | 44 +++++++++++++++++++ .../PublisherSubscriptionController.cs | 32 -------------- 3 files changed, 44 insertions(+), 32 deletions(-) delete mode 100644 DysonNetwork.Sphere/Post/AccountHelperClient.cs create mode 100644 DysonNetwork.Sphere/Post/PostCategorySubController.cs diff --git a/DysonNetwork.Sphere/Post/AccountHelperClient.cs b/DysonNetwork.Sphere/Post/AccountHelperClient.cs deleted file mode 100644 index e69de29..0000000 diff --git a/DysonNetwork.Sphere/Post/PostCategorySubController.cs b/DysonNetwork.Sphere/Post/PostCategorySubController.cs new file mode 100644 index 0000000..2084370 --- /dev/null +++ b/DysonNetwork.Sphere/Post/PostCategorySubController.cs @@ -0,0 +1,44 @@ +using DysonNetwork.Shared.Models; +using DysonNetwork.Shared.Proto; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace DysonNetwork.Sphere.Post; + +[Route(("/api/categories"))] +[ApiController] +public class PostCategorySubController(AppDatabase db) : ControllerBase +{ + /// + /// Get all subscriptions of categories and tags for the current user + /// + /// List of active subscription + [HttpGet("subscriptions")] + [Authorize] + public async Task>> ListCategoriesSubscription( + [FromQuery] int offset = 0, + [FromQuery] int take = 20 + ) + { + if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); + var accountId = Guid.Parse(currentUser.Id); + + var pubQuery = db.PostCategorySubscriptions + .Include(ps => ps.Tag) + .Include(ps => ps.Category) + .Where(ps => ps.AccountId == accountId) + .OrderByDescending(ps => ps.CreatedAt) + .AsQueryable(); + + var totalCount = await pubQuery.CountAsync(); + var subscriptions = await pubQuery + .Take(take) + .Skip(offset) + .ToListAsync(); + + Response.Headers["X-Total"] = totalCount.ToString(); + + return Ok(subscriptions); + } +} \ No newline at end of file diff --git a/DysonNetwork.Sphere/Publisher/PublisherSubscriptionController.cs b/DysonNetwork.Sphere/Publisher/PublisherSubscriptionController.cs index b656fc3..b1a4c19 100644 --- a/DysonNetwork.Sphere/Publisher/PublisherSubscriptionController.cs +++ b/DysonNetwork.Sphere/Publisher/PublisherSubscriptionController.cs @@ -115,36 +115,4 @@ public class PublisherSubscriptionController( return Ok(subscriptions); } - - /// - /// Get all subscriptions of categories and tags for the current user - /// - /// List of active subscription - [HttpGet("subscriptions/categories")] - [Authorize] - public async Task>> ListCategoriesSubscription( - [FromQuery] int offset = 0, - [FromQuery] int take = 20 - ) - { - if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized(); - var accountId = Guid.Parse(currentUser.Id); - - var pubQuery = db.PostCategorySubscriptions - .Include(ps => ps.Tag) - .Include(ps => ps.Category) - .Where(ps => ps.AccountId == accountId) - .OrderByDescending(ps => ps.CreatedAt) - .AsQueryable(); - - var totalCount = await pubQuery.CountAsync(); - var subscriptions = await pubQuery - .Take(take) - .Skip(offset) - .ToListAsync(); - - Response.Headers["X-Total"] = totalCount.ToString(); - - return Ok(subscriptions); - } } \ No newline at end of file