Compare commits
2 Commits
e477429a35
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
a071bd2738
|
|||
|
43945fc524
|
@@ -20,6 +20,19 @@ public enum PublicationSiteMode
|
|||||||
SelfManaged
|
SelfManaged
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class PublicationSiteConfig
|
||||||
|
{
|
||||||
|
public string? StyleOverride { get; set; }
|
||||||
|
public List<PublicationSiteNavItem>? NavItems { get; set; } = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PublicationSiteNavItem
|
||||||
|
{
|
||||||
|
[MaxLength(1024)] public string Label { get; set; } = null!;
|
||||||
|
[MaxLength(8192)] public string Href { get; set; } = null!;
|
||||||
|
Dictionary<string, object> Attributes { get; set; } = new();
|
||||||
|
}
|
||||||
|
|
||||||
public class SnPublicationSite : ModelBase
|
public class SnPublicationSite : ModelBase
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; } = Guid.NewGuid();
|
public Guid Id { get; set; } = Guid.NewGuid();
|
||||||
@@ -29,6 +42,7 @@ public class SnPublicationSite : ModelBase
|
|||||||
|
|
||||||
public PublicationSiteMode Mode { get; set; } = PublicationSiteMode.FullyManaged;
|
public PublicationSiteMode Mode { get; set; } = PublicationSiteMode.FullyManaged;
|
||||||
public List<SnPublicationPage> Pages { get; set; } = [];
|
public List<SnPublicationPage> Pages { get; set; } = [];
|
||||||
|
[Column(TypeName = "jsonb")] public PublicationSiteConfig Config { get; set; } = new();
|
||||||
|
|
||||||
public Guid PublisherId { get; set; }
|
public Guid PublisherId { get; set; }
|
||||||
[NotMapped] public SnPublisher Publisher { get; set; } = null!;
|
[NotMapped] public SnPublisher Publisher { get; set; } = null!;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class DiscoveryService(RemoteRealmService remoteRealmService)
|
|||||||
// Since we don't have CreatedAt in the proto model, we'll just apply randomizer if requested
|
// Since we don't have CreatedAt in the proto model, we'll just apply randomizer if requested
|
||||||
var orderedRealms = randomizer
|
var orderedRealms = randomizer
|
||||||
? communityRealms.OrderBy(_ => Random.Shared.Next())
|
? communityRealms.OrderBy(_ => Random.Shared.Next())
|
||||||
: communityRealms.OrderByDescending(q => q.Members.Count);
|
: communityRealms.OrderByDescending(q => q.Members.Count());
|
||||||
|
|
||||||
return orderedRealms.Skip(offset).Take(take).ToList();
|
return orderedRealms.Skip(offset).Take(take).ToList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,26 +40,6 @@ public class PostController(
|
|||||||
return Ok(posts);
|
return Ok(posts);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Retrieves a paginated list of posts with optional filtering and sorting.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="includeReplies">Whether to include reply posts in the results. If false, only root posts are returned.</param>
|
|
||||||
/// <param name="offset">The number of posts to skip for pagination.</param>
|
|
||||||
/// <param name="take">The maximum number of posts to return (default: 20).</param>
|
|
||||||
/// <param name="pubName">Filter posts by publisher name.</param>
|
|
||||||
/// <param name="realmName">Filter posts by realm slug.</param>
|
|
||||||
/// <param name="type">Filter posts by post type (as integer).</param>
|
|
||||||
/// <param name="categories">Filter posts by category slugs.</param>
|
|
||||||
/// <param name="tags">Filter posts by tag slugs.</param>
|
|
||||||
/// <param name="queryTerm">Search term to filter posts by title, description, or content.</param>
|
|
||||||
/// <param name="onlyMedia">If true, only returns posts that have attachments.</param>
|
|
||||||
/// <param name="shuffle">If true, returns posts in random order. If false, orders by published/created date (newest first).</param>
|
|
||||||
/// <param name="pinned">If true, returns posts that pinned. If false, returns posts that are not pinned. If null, returns all posts.</param>
|
|
||||||
/// <returns>
|
|
||||||
/// Returns an ActionResult containing a list of Post objects that match the specified criteria.
|
|
||||||
/// Includes an X-Total header with the total count of matching posts before pagination.
|
|
||||||
/// </returns>
|
|
||||||
/// <response code="200">Returns the list of posts matching the criteria.</response>
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<SnPost>))]
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(List<SnPost>))]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
|
|||||||
156
DysonNetwork.Zone/Migrations/20251210104942_AddSiteGlobalConfig.Designer.cs
generated
Normal file
156
DysonNetwork.Zone/Migrations/20251210104942_AddSiteGlobalConfig.Designer.cs
generated
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using DysonNetwork.Shared.Models;
|
||||||
|
using DysonNetwork.Zone;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using NodaTime;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DysonNetwork.Zone.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(AppDatabase))]
|
||||||
|
[Migration("20251210104942_AddSiteGlobalConfig")]
|
||||||
|
partial class AddSiteGlobalConfig
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.11")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublicationPage", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid")
|
||||||
|
.HasColumnName("id");
|
||||||
|
|
||||||
|
b.Property<Dictionary<string, object>>("Config")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("jsonb")
|
||||||
|
.HasColumnName("config");
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone")
|
||||||
|
.HasColumnName("created_at");
|
||||||
|
|
||||||
|
b.Property<Instant?>("DeletedAt")
|
||||||
|
.HasColumnType("timestamp with time zone")
|
||||||
|
.HasColumnName("deleted_at");
|
||||||
|
|
||||||
|
b.Property<string>("Path")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(8192)
|
||||||
|
.HasColumnType("character varying(8192)")
|
||||||
|
.HasColumnName("path");
|
||||||
|
|
||||||
|
b.Property<Guid>("SiteId")
|
||||||
|
.HasColumnType("uuid")
|
||||||
|
.HasColumnName("site_id");
|
||||||
|
|
||||||
|
b.Property<int>("Type")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("type");
|
||||||
|
|
||||||
|
b.Property<Instant>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone")
|
||||||
|
.HasColumnName("updated_at");
|
||||||
|
|
||||||
|
b.HasKey("Id")
|
||||||
|
.HasName("pk_publication_pages");
|
||||||
|
|
||||||
|
b.HasIndex("SiteId")
|
||||||
|
.HasDatabaseName("ix_publication_pages_site_id");
|
||||||
|
|
||||||
|
b.ToTable("publication_pages", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublicationSite", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid")
|
||||||
|
.HasColumnName("id");
|
||||||
|
|
||||||
|
b.Property<Guid>("AccountId")
|
||||||
|
.HasColumnType("uuid")
|
||||||
|
.HasColumnName("account_id");
|
||||||
|
|
||||||
|
b.Property<PublicationSiteConfig>("Config")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("jsonb")
|
||||||
|
.HasColumnName("config");
|
||||||
|
|
||||||
|
b.Property<Instant>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone")
|
||||||
|
.HasColumnName("created_at");
|
||||||
|
|
||||||
|
b.Property<Instant?>("DeletedAt")
|
||||||
|
.HasColumnType("timestamp with time zone")
|
||||||
|
.HasColumnName("deleted_at");
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasMaxLength(8192)
|
||||||
|
.HasColumnType("character varying(8192)")
|
||||||
|
.HasColumnName("description");
|
||||||
|
|
||||||
|
b.Property<int>("Mode")
|
||||||
|
.HasColumnType("integer")
|
||||||
|
.HasColumnName("mode");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(4096)
|
||||||
|
.HasColumnType("character varying(4096)")
|
||||||
|
.HasColumnName("name");
|
||||||
|
|
||||||
|
b.Property<Guid>("PublisherId")
|
||||||
|
.HasColumnType("uuid")
|
||||||
|
.HasColumnName("publisher_id");
|
||||||
|
|
||||||
|
b.Property<string>("Slug")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(4096)
|
||||||
|
.HasColumnType("character varying(4096)")
|
||||||
|
.HasColumnName("slug");
|
||||||
|
|
||||||
|
b.Property<Instant>("UpdatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone")
|
||||||
|
.HasColumnName("updated_at");
|
||||||
|
|
||||||
|
b.HasKey("Id")
|
||||||
|
.HasName("pk_publication_sites");
|
||||||
|
|
||||||
|
b.ToTable("publication_sites", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublicationPage", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("DysonNetwork.Shared.Models.SnPublicationSite", "Site")
|
||||||
|
.WithMany("Pages")
|
||||||
|
.HasForeignKey("SiteId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired()
|
||||||
|
.HasConstraintName("fk_publication_pages_publication_sites_site_id");
|
||||||
|
|
||||||
|
b.Navigation("Site");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublicationSite", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Pages");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using DysonNetwork.Shared.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace DysonNetwork.Zone.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddSiteGlobalConfig : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<PublicationSiteConfig>(
|
||||||
|
name: "config",
|
||||||
|
table: "publication_sites",
|
||||||
|
type: "jsonb",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: new PublicationSiteConfig());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "config",
|
||||||
|
table: "publication_sites");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
// <auto-generated />
|
// <auto-generated />
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using DysonNetwork.Shared.Models;
|
||||||
using DysonNetwork.Zone;
|
using DysonNetwork.Zone;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
@@ -82,6 +83,11 @@ namespace DysonNetwork.Zone.Migrations
|
|||||||
.HasColumnType("uuid")
|
.HasColumnType("uuid")
|
||||||
.HasColumnName("account_id");
|
.HasColumnName("account_id");
|
||||||
|
|
||||||
|
b.Property<PublicationSiteConfig>("Config")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("jsonb")
|
||||||
|
.HasColumnName("config");
|
||||||
|
|
||||||
b.Property<Instant>("CreatedAt")
|
b.Property<Instant>("CreatedAt")
|
||||||
.HasColumnType("timestamp with time zone")
|
.HasColumnType("timestamp with time zone")
|
||||||
.HasColumnName("created_at");
|
.HasColumnName("created_at");
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ public class PublicationSiteController(
|
|||||||
|
|
||||||
[HttpPost("{pubName}")]
|
[HttpPost("{pubName}")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task<ActionResult<SnPublicationSite>> CreateSite([FromRoute] string pubName, [FromBody] PublicationSiteRequest request)
|
public async Task<ActionResult<SnPublicationSite>> CreateSite([FromRoute] string pubName,
|
||||||
|
[FromBody] PublicationSiteRequest request)
|
||||||
{
|
{
|
||||||
if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
@@ -75,6 +76,7 @@ public class PublicationSiteController(
|
|||||||
Name = request.Name,
|
Name = request.Name,
|
||||||
Description = request.Description,
|
Description = request.Description,
|
||||||
PublisherId = publisher.Id,
|
PublisherId = publisher.Id,
|
||||||
|
Config = request.Config ?? new PublicationSiteConfig(),
|
||||||
AccountId = accountId
|
AccountId = accountId
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -96,7 +98,8 @@ public class PublicationSiteController(
|
|||||||
|
|
||||||
[HttpPatch("{pubName}/{slug}")]
|
[HttpPatch("{pubName}/{slug}")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task<ActionResult<SnPublicationSite>> UpdateSite([FromRoute] string pubName, string slug, [FromBody] PublicationSiteRequest request)
|
public async Task<ActionResult<SnPublicationSite>> UpdateSite([FromRoute] string pubName, string slug,
|
||||||
|
[FromBody] PublicationSiteRequest request)
|
||||||
{
|
{
|
||||||
if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
@@ -113,6 +116,7 @@ public class PublicationSiteController(
|
|||||||
site.Slug = request.Slug;
|
site.Slug = request.Slug;
|
||||||
site.Name = request.Name;
|
site.Name = request.Name;
|
||||||
site.Description = request.Description ?? site.Description;
|
site.Description = request.Description ?? site.Description;
|
||||||
|
site.Config = request.Config ?? site.Config;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -153,18 +157,10 @@ public class PublicationSiteController(
|
|||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("site/{slug}/page")]
|
|
||||||
public async Task<ActionResult<SnPublicationPage>> RenderPage(string slug, [FromQuery] string path = "/")
|
|
||||||
{
|
|
||||||
var page = await publicationService.RenderPage(slug, path);
|
|
||||||
if (page == null)
|
|
||||||
return NotFound();
|
|
||||||
return Ok(page);
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet("{pubName}/{siteSlug}/pages")]
|
[HttpGet("{pubName}/{siteSlug}/pages")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task<ActionResult<List<SnPublicationPage>>> ListPagesForSite([FromRoute] string pubName, [FromRoute] string siteSlug)
|
public async Task<ActionResult<List<SnPublicationPage>>> ListPagesForSite([FromRoute] string pubName,
|
||||||
|
[FromRoute] string siteSlug)
|
||||||
{
|
{
|
||||||
var site = await publicationService.GetSiteBySlug(siteSlug);
|
var site = await publicationService.GetSiteBySlug(siteSlug);
|
||||||
if (site == null) return NotFound();
|
if (site == null) return NotFound();
|
||||||
@@ -187,7 +183,8 @@ public class PublicationSiteController(
|
|||||||
|
|
||||||
[HttpPost("{pubName}/{siteSlug}/pages")]
|
[HttpPost("{pubName}/{siteSlug}/pages")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public async Task<ActionResult<SnPublicationPage>> CreatePage([FromRoute] string pubName, [FromRoute] string siteSlug, [FromBody] PublicationPageRequest request)
|
public async Task<ActionResult<SnPublicationPage>> CreatePage([FromRoute] string pubName,
|
||||||
|
[FromRoute] string siteSlug, [FromBody] PublicationPageRequest request)
|
||||||
{
|
{
|
||||||
if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser)
|
if (HttpContext.Items["CurrentUser"] is not Shared.Proto.Account currentUser)
|
||||||
return Unauthorized();
|
return Unauthorized();
|
||||||
@@ -280,6 +277,7 @@ public class PublicationSiteController(
|
|||||||
[MaxLength(4096)] public string Slug { get; set; } = null!;
|
[MaxLength(4096)] public string Slug { get; set; } = null!;
|
||||||
[MaxLength(4096)] public string Name { get; set; } = null!;
|
[MaxLength(4096)] public string Name { get; set; } = null!;
|
||||||
[MaxLength(8192)] public string? Description { get; set; }
|
[MaxLength(8192)] public string? Description { get; set; }
|
||||||
|
public PublicationSiteConfig? Config { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PublicationPageRequest
|
public class PublicationPageRequest
|
||||||
@@ -288,4 +286,4 @@ public class PublicationSiteController(
|
|||||||
[MaxLength(8192)] public string? Path { get; set; }
|
[MaxLength(8192)] public string? Path { get; set; }
|
||||||
public Dictionary<string, object?>? Config { get; set; }
|
public Dictionary<string, object?>? Config { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user