✨ Site mode
This commit is contained in:
@@ -4,7 +4,6 @@ using DysonNetwork.Shared.Registry;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Models = DysonNetwork.Shared.Models;
|
||||
using PublicationPagePresets = DysonNetwork.Shared.Models.PublicationPagePresets;
|
||||
|
||||
namespace DysonNetwork.Zone.Publication;
|
||||
|
||||
@@ -15,10 +14,10 @@ public class PublicationSiteController(
|
||||
RemotePublisherService publisherService
|
||||
) : ControllerBase
|
||||
{
|
||||
[HttpGet("site/{slug}")]
|
||||
public async Task<ActionResult<SnPublicationSite>> GetSite(string slug)
|
||||
[HttpGet("{pubName}/{slug}")]
|
||||
public async Task<ActionResult<SnPublicationSite>> GetSite(string pubName, string slug)
|
||||
{
|
||||
var site = await publicationService.GetSiteBySlug(slug);
|
||||
var site = await publicationService.GetSiteBySlug(slug, pubName);
|
||||
if (site == null)
|
||||
return NotFound();
|
||||
return Ok(site);
|
||||
@@ -71,6 +70,7 @@ public class PublicationSiteController(
|
||||
|
||||
var site = new SnPublicationSite
|
||||
{
|
||||
Mode = request.Mode,
|
||||
Slug = request.Slug,
|
||||
Name = request.Name,
|
||||
Description = request.Description,
|
||||
@@ -106,12 +106,10 @@ public class PublicationSiteController(
|
||||
if (publisher == null) return NotFound();
|
||||
|
||||
var site = await publicationService.GetSiteById(id);
|
||||
if (site == null)
|
||||
return NotFound();
|
||||
|
||||
if (site.PublisherId != publisher.Id)
|
||||
if (site == null || site.PublisherId != publisher.Id)
|
||||
return NotFound();
|
||||
|
||||
site.Mode = request.Mode;
|
||||
site.Slug = request.Slug;
|
||||
site.Name = request.Name;
|
||||
site.Description = request.Description ?? site.Description;
|
||||
@@ -204,7 +202,7 @@ public class PublicationSiteController(
|
||||
|
||||
var page = new SnPublicationPage
|
||||
{
|
||||
Preset = request.Preset ?? PublicationPagePresets.Landing,
|
||||
Type = request.Type,
|
||||
Path = request.Path ?? "/",
|
||||
Config = request.Config ?? new Dictionary<string, object?>(),
|
||||
SiteId = site.Id
|
||||
@@ -239,7 +237,7 @@ public class PublicationSiteController(
|
||||
|
||||
var accountId = Guid.Parse(currentUser.Id);
|
||||
|
||||
if (request.Preset != null) page.Preset = request.Preset;
|
||||
page.Type = request.Type;
|
||||
if (request.Path != null) page.Path = request.Path;
|
||||
if (request.Config != null) page.Config = request.Config;
|
||||
|
||||
@@ -278,6 +276,7 @@ public class PublicationSiteController(
|
||||
|
||||
public class PublicationSiteRequest
|
||||
{
|
||||
public PublicationSiteMode Mode { get; set; }
|
||||
[MaxLength(4096)] public string Slug { get; set; } = null!;
|
||||
[MaxLength(4096)] public string Name { get; set; } = null!;
|
||||
[MaxLength(8192)] public string? Description { get; set; }
|
||||
@@ -285,7 +284,7 @@ public class PublicationSiteController(
|
||||
|
||||
public class PublicationPageRequest
|
||||
{
|
||||
[MaxLength(8192)] public string? Preset { get; set; }
|
||||
public PublicationPageType Type { get; set; }
|
||||
[MaxLength(8192)] public string? Path { get; set; }
|
||||
public Dictionary<string, object?>? Config { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using DysonNetwork.Shared.Auth;
|
||||
using DysonNetwork.Shared.Data;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Registry;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -9,7 +10,8 @@ namespace DysonNetwork.Zone.Publication;
|
||||
public class PublicationSiteService(
|
||||
AppDatabase db,
|
||||
RemotePublisherService publisherService,
|
||||
RemoteAccountService remoteAccounts
|
||||
RemoteAccountService remoteAccounts,
|
||||
RemotePublisherService remotePublishers
|
||||
)
|
||||
{
|
||||
public async Task<SnPublicationSite?> GetSiteById(Guid id)
|
||||
@@ -19,9 +21,18 @@ public class PublicationSiteService(
|
||||
.FirstOrDefaultAsync(s => s.Id == id);
|
||||
}
|
||||
|
||||
public async Task<SnPublicationSite?> GetSiteBySlug(string slug)
|
||||
public async Task<SnPublicationSite?> GetSiteBySlug(string slug, string? pubName = null)
|
||||
{
|
||||
Guid? pubId = null;
|
||||
if (pubName != null)
|
||||
{
|
||||
var pub = await remotePublishers.GetPublisherByName(pubName);
|
||||
if (pub == null) throw new InvalidOperationException("Publisher not found.");
|
||||
pubId = pub.Id;
|
||||
}
|
||||
|
||||
return await db.PublicationSites
|
||||
.If(pubId.HasValue, q => q.Where(s => s.PublisherId == pubId.Value))
|
||||
.Include(s => s.Pages)
|
||||
.FirstOrDefaultAsync(s => s.Slug == slug);
|
||||
}
|
||||
@@ -39,7 +50,7 @@ public class PublicationSiteService(
|
||||
var perk = (await remoteAccounts.GetAccount(accountId)).PerkSubscription;
|
||||
var perkLevel = perk is not null ? PerkSubscriptionPrivilege.GetPrivilegeFromIdentifier(perk.Identifier) : 0;
|
||||
|
||||
var maxSite = (perkLevel) switch
|
||||
var maxSite = perkLevel switch
|
||||
{
|
||||
1 => 2,
|
||||
2 => 3,
|
||||
|
||||
Reference in New Issue
Block a user