💄 Updated the hosted site post page
This commit is contained in:
37
DysonNetwork.Zone/Pages/Posts/Details.cshtml.cs
Normal file
37
DysonNetwork.Zone/Pages/Posts/Details.cshtml.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using DysonNetwork.Zone.Publication;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace DysonNetwork.Zone.Pages.Posts;
|
||||
|
||||
public class DetailsModel(PostService.PostServiceClient postClient) : PageModel
|
||||
{
|
||||
[FromRoute] public string Slug { get; set; } = null!;
|
||||
|
||||
public SnPublicationSite? Site { get; set; }
|
||||
public SnPost? Post { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
Site = HttpContext.Items[PublicationSiteMiddleware.SiteContextKey] as SnPublicationSite;
|
||||
|
||||
if (string.IsNullOrEmpty(Slug))
|
||||
return NotFound();
|
||||
|
||||
var request = new GetPostRequest { PublisherId = Site!.PublisherId.ToString() };
|
||||
if (Guid.TryParse(Slug, out var guid)) request.Id = guid.ToString();
|
||||
else request.Slug = Slug;
|
||||
var response = await postClient.GetPostAsync(request);
|
||||
|
||||
if (response == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
Post = SnPost.FromProtoValue(response);
|
||||
|
||||
return Page();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user