💥 Add /api prefix for json endpoints with redirect

This commit is contained in:
2025-07-10 14:18:02 +08:00
parent 1f2cdb146d
commit fc6edd7378
43 changed files with 217 additions and 41 deletions

View File

@@ -0,0 +1,22 @@
@page "/posts/{PostId:guid}"
@model DysonNetwork.Sphere.Pages.Posts.PostDetailModel
@{
ViewData["Title"] = Model.Post?.Title + " | Solar Network";
}
<div class="container mx-auto p-4">
@if (Model.Post != null)
{
<h1 class="text-3xl font-bold mb-4">@Model.Post.Title</h1>
<p class="text-gray-600 mb-2">Created at: @Model.Post.CreatedAt</p>
<div class="prose lg:prose-xl">
<p>@Model.Post.Content</p>
</div>
}
else
{
<div class="alert alert-error">
<span>Post not found.</span>
</div>
}
</div>

View File

@@ -0,0 +1,44 @@
using DysonNetwork.Sphere.Account;
using DysonNetwork.Sphere.Post;
using DysonNetwork.Sphere.Publisher;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
namespace DysonNetwork.Sphere.Pages.Posts;
public class PostDetailModel(
AppDatabase db,
PublisherService pub,
RelationshipService rels
) : PageModel
{
[BindProperty(SupportsGet = true)]
public Guid PostId { get; set; }
public Post.Post? Post { get; set; }
public async Task<IActionResult> OnGetAsync()
{
if (PostId == Guid.Empty)
return NotFound();
HttpContext.Items.TryGetValue("CurrentUser", out var currentUserValue);
var currentUser = currentUserValue as Sphere.Account.Account;
var userFriends = currentUser is null ? [] : await rels.ListAccountFriends(currentUser);
var userPublishers = currentUser is null ? [] : await pub.GetUserPublishers(currentUser.Id);
Post = await db.Posts
.Where(e => e.Id == PostId)
.Include(e => e.Publisher)
.Include(e => e.Tags)
.Include(e => e.Categories)
.FilterWithVisibility(currentUser, userFriends, userPublishers)
.FirstOrDefaultAsync();
if (Post == null)
return NotFound();
return Page();
}
}