♻️ Moved the site to the Zone project

This commit is contained in:
2025-11-19 22:28:52 +08:00
parent 9b4cbade5c
commit 1b774c1de6
16 changed files with 2537 additions and 151 deletions

View File

@@ -14,7 +14,7 @@ public class SnPublicationSite : ModelBase
public List<SnPublicationPage> Pages { get; set; } = []; public List<SnPublicationPage> Pages { get; set; } = [];
public Guid PublisherId { get; set; } public Guid PublisherId { get; set; }
public SnPublisher Publisher { get; set; } = null!; [NotMapped] public SnPublisher Publisher { get; set; } = null!;
public Guid AccountId { get; set; } public Guid AccountId { get; set; }
// Preloaded via the remote services // Preloaded via the remote services
[NotMapped] public SnAccount? Account { get; set; } [NotMapped] public SnAccount? Account { get; set; }

View File

@@ -1,8 +1,10 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using DysonNetwork.Shared.Proto;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using NodaTime; using NodaTime;
using NodaTime.Extensions;
using NodaTime.Serialization.Protobuf; using NodaTime.Serialization.Protobuf;
namespace DysonNetwork.Shared.Models; namespace DysonNetwork.Shared.Models;
@@ -148,23 +150,42 @@ public class SnPublisherMember : ModelBase
public Instant? JoinedAt { get; set; } public Instant? JoinedAt { get; set; }
public Proto.PublisherMember ToProto() public PublisherMember ToProto()
{ {
return new Proto.PublisherMember() return new PublisherMember
{ {
PublisherId = PublisherId.ToString(), PublisherId = PublisherId.ToString(),
AccountId = AccountId.ToString(), AccountId = AccountId.ToString(),
Role = Role switch Role = Role switch
{ {
PublisherMemberRole.Owner => Shared.Proto.PublisherMemberRole.Owner, PublisherMemberRole.Owner => Proto.PublisherMemberRole.Owner,
PublisherMemberRole.Manager => Shared.Proto.PublisherMemberRole.Manager, PublisherMemberRole.Manager => Proto.PublisherMemberRole.Manager,
PublisherMemberRole.Editor => Shared.Proto.PublisherMemberRole.Editor, PublisherMemberRole.Editor => Proto.PublisherMemberRole.Editor,
PublisherMemberRole.Viewer => Shared.Proto.PublisherMemberRole.Viewer, PublisherMemberRole.Viewer => Proto.PublisherMemberRole.Viewer,
_ => throw new ArgumentOutOfRangeException(nameof(Role), Role, null) _ => throw new ArgumentOutOfRangeException(nameof(Role), Role, null)
}, },
JoinedAt = JoinedAt?.ToTimestamp() JoinedAt = JoinedAt?.ToTimestamp()
}; };
} }
public static SnPublisherMember FromProtoValue(PublisherMember proto)
{
return new SnPublisherMember
{
PublisherId = Guid.Parse(proto.PublisherId),
AccountId = Guid.Parse(proto.AccountId),
Role = proto.Role switch
{
Proto.PublisherMemberRole.Owner => PublisherMemberRole.Owner,
Proto.PublisherMemberRole.Manager => PublisherMemberRole.Manager,
Proto.PublisherMemberRole.Editor => PublisherMemberRole.Editor,
_ => PublisherMemberRole.Viewer
},
JoinedAt = proto.JoinedAt?.ToDateTimeOffset().ToInstant(),
CreatedAt = proto.CreatedAt.ToDateTimeOffset().ToInstant(),
UpdatedAt = proto.UpdatedAt.ToDateTimeOffset().ToInstant()
};
}
} }
public enum PublisherSubscriptionStatus public enum PublisherSubscriptionStatus
@@ -200,4 +221,4 @@ public abstract class PublisherFeatureFlag
{ {
public static List<string> AllFlags => [Develop]; public static List<string> AllFlags => [Develop];
public static string Develop = "develop"; public static string Develop = "develop";
} }

View File

@@ -0,0 +1,111 @@
using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Proto;
namespace DysonNetwork.Shared.Registry;
public class RemotePublisherService(PublisherService.PublisherServiceClient publishers)
{
public async Task<SnPublisher> GetPublisher(string? name = null, string? id = null,
CancellationToken cancellationToken = default)
{
if (string.IsNullOrEmpty(name) && string.IsNullOrEmpty(id))
throw new ArgumentException("Either name or id must be provided.");
if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(id))
throw new ArgumentException("Only one of name or id can be provided.");
var request = new GetPublisherRequest();
if (!string.IsNullOrEmpty(name))
request.Name = name;
else
request.Id = id;
var response = await publishers.GetPublisherAsync(request, cancellationToken: cancellationToken);
return SnPublisher.FromProtoValue(response.Publisher);
}
public async Task<List<SnPublisher>> GetPublishersBatch(List<string> ids,
CancellationToken cancellationToken = default)
{
var request = new GetPublisherBatchRequest();
request.Ids.AddRange(ids);
var response = await publishers.GetPublisherBatchAsync(request, cancellationToken: cancellationToken);
return response.Publishers.Select(SnPublisher.FromProtoValue).ToList();
}
public async Task<List<SnPublisher>> ListPublishers(string? accountId = null, string? realmId = null,
CancellationToken cancellationToken = default)
{
var request = new ListPublishersRequest
{
AccountId = accountId ?? "",
RealmId = realmId ?? ""
};
var response = await publishers.ListPublishersAsync(request, cancellationToken: cancellationToken);
return response.Publishers.Select(SnPublisher.FromProtoValue).ToList();
}
public async Task<List<SnPublisherMember>> ListPublisherMembers(string publisherId,
CancellationToken cancellationToken = default)
{
var request = new ListPublisherMembersRequest { PublisherId = publisherId };
var response = await publishers.ListPublisherMembersAsync(request, cancellationToken: cancellationToken);
return response.Members.Select(SnPublisherMember.FromProtoValue).ToList();
}
public async Task<string?> SetPublisherFeatureFlag(string publisherId, string flag,
CancellationToken cancellationToken = default)
{
var request = new SetPublisherFeatureFlagRequest
{
PublisherId = publisherId,
Flag = flag
};
var response = await publishers.SetPublisherFeatureFlagAsync(request, cancellationToken: cancellationToken);
return response.Value;
}
public async Task<bool> HasPublisherFeature(string publisherId, string flag,
CancellationToken cancellationToken = default)
{
var request = new HasPublisherFeatureRequest
{
PublisherId = publisherId,
Flag = flag
};
var response = await publishers.HasPublisherFeatureAsync(request, cancellationToken: cancellationToken);
return response.Enabled;
}
public async Task<bool> IsPublisherMember(string publisherId, string accountId,
Proto.PublisherMemberRole? role = null, CancellationToken cancellationToken = default)
{
var request = new IsPublisherMemberRequest
{
PublisherId = publisherId,
AccountId = accountId,
};
if (role.HasValue) request.Role = role.Value;
var response = await publishers.IsPublisherMemberAsync(request, cancellationToken: cancellationToken);
return response.Valid;
}
public async Task<List<SnPublisher>> GetUserPublishers(Guid accountId,
CancellationToken cancellationToken = default)
{
return await ListPublishers(accountId: accountId.ToString(), realmId: null, cancellationToken);
}
public async Task<bool> IsMemberWithRole(Guid publisherId, Guid accountId, Models.PublisherMemberRole role,
CancellationToken cancellationToken = default)
{
var protoRole = role switch
{
Models.PublisherMemberRole.Owner => Proto.PublisherMemberRole.Owner,
Models.PublisherMemberRole.Manager => Proto.PublisherMemberRole.Manager,
Models.PublisherMemberRole.Editor => Proto.PublisherMemberRole.Editor,
Models.PublisherMemberRole.Viewer => Proto.PublisherMemberRole.Viewer,
_ => Proto.PublisherMemberRole.Unspecified
};
return await IsPublisherMember(publisherId.ToString(), accountId.ToString(), protoRole, cancellationToken);
}
}

View File

@@ -116,6 +116,7 @@ public static class ServiceInjectionHelper
.ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler() .ConfigurePrimaryHttpMessageHandler(_ => new HttpClientHandler()
{ ServerCertificateCustomValidationCallback = (_, _, _, _) => true } { ServerCertificateCustomValidationCallback = (_, _, _, _) => true }
); );
services.AddSingleton<RemotePublisherService>();
return services; return services;
} }

View File

@@ -52,9 +52,6 @@ public class AppDatabase(
public DbSet<WebFeed> WebFeeds { get; set; } = null!; public DbSet<WebFeed> WebFeeds { get; set; } = null!;
public DbSet<WebFeedSubscription> WebFeedSubscriptions { get; set; } = null!; public DbSet<WebFeedSubscription> WebFeedSubscriptions { get; set; } = null!;
public DbSet<SnPublicationSite> PublicationSites { get; set; } = null!;
public DbSet<SnPublicationPage> PublicationPages { get; set; } = null!;
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
optionsBuilder.UseNpgsql( optionsBuilder.UseNpgsql(

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
using NodaTime;
#nullable disable
namespace DysonNetwork.Sphere.Migrations
{
/// <inheritdoc />
public partial class RemovePublicationSites : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "publication_pages");
migrationBuilder.DropTable(
name: "publication_sites");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "publication_sites",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false),
publisher_id = table.Column<Guid>(type: "uuid", nullable: false),
account_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
description = table.Column<string>(type: "character varying(8192)", maxLength: 8192, nullable: true),
name = table.Column<string>(type: "character varying(4096)", maxLength: 4096, nullable: false),
slug = table.Column<string>(type: "character varying(4096)", maxLength: 4096, nullable: false),
updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_publication_sites", x => x.id);
table.ForeignKey(
name: "fk_publication_sites_publishers_publisher_id",
column: x => x.publisher_id,
principalTable: "publishers",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "publication_pages",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false),
site_id = table.Column<Guid>(type: "uuid", nullable: false),
config = table.Column<Dictionary<string, object>>(type: "jsonb", nullable: false),
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
path = table.Column<string>(type: "character varying(8192)", maxLength: 8192, nullable: false),
preset = table.Column<string>(type: "character varying(8192)", maxLength: 8192, nullable: false),
updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_publication_pages", x => x.id);
table.ForeignKey(
name: "fk_publication_pages_publication_sites_site_id",
column: x => x.site_id,
principalTable: "publication_sites",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "ix_publication_pages_site_id",
table: "publication_pages",
column: "site_id");
migrationBuilder.CreateIndex(
name: "ix_publication_sites_publisher_id",
table: "publication_sites",
column: "publisher_id");
}
}
}

View File

@@ -881,108 +881,6 @@ namespace DysonNetwork.Sphere.Migrations
b.ToTable("post_tags", (string)null); b.ToTable("post_tags", (string)null);
}); });
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<string>("Preset")
.IsRequired()
.HasMaxLength(8192)
.HasColumnType("character varying(8192)")
.HasColumnName("preset");
b.Property<Guid>("SiteId")
.HasColumnType("uuid")
.HasColumnName("site_id");
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<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<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.HasIndex("PublisherId")
.HasDatabaseName("ix_publication_sites_publisher_id");
b.ToTable("publication_sites", (string)null);
});
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublisher", b => modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublisher", b =>
{ {
b.Property<Guid>("Id") b.Property<Guid>("Id")
@@ -1793,30 +1691,6 @@ namespace DysonNetwork.Sphere.Migrations
b.Navigation("Post"); b.Navigation("Post");
}); });
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.HasOne("DysonNetwork.Shared.Models.SnPublisher", "Publisher")
.WithMany()
.HasForeignKey("PublisherId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_publication_sites_publishers_publisher_id");
b.Navigation("Publisher");
});
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublisherFeature", b => modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublisherFeature", b =>
{ {
b.HasOne("DysonNetwork.Shared.Models.SnPublisher", "Publisher") b.HasOne("DysonNetwork.Shared.Models.SnPublisher", "Publisher")
@@ -2021,11 +1895,6 @@ namespace DysonNetwork.Sphere.Migrations
b.Navigation("Reactions"); b.Navigation("Reactions");
}); });
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublicationSite", b =>
{
b.Navigation("Pages");
});
modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublisher", b => modelBuilder.Entity("DysonNetwork.Shared.Models.SnPublisher", b =>
{ {
b.Navigation("Collections"); b.Navigation("Collections");

View File

@@ -3,7 +3,6 @@ using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using DysonNetwork.Shared.Cache; using DysonNetwork.Shared.Cache;
using DysonNetwork.Shared.GeoIp; using DysonNetwork.Shared.GeoIp;
using DysonNetwork.Shared.Registry;
using DysonNetwork.Sphere.Autocompletion; using DysonNetwork.Sphere.Autocompletion;
using DysonNetwork.Sphere.Chat; using DysonNetwork.Sphere.Chat;
using DysonNetwork.Sphere.Chat.Realtime; using DysonNetwork.Sphere.Chat.Realtime;
@@ -11,7 +10,6 @@ using DysonNetwork.Sphere.Discovery;
using DysonNetwork.Sphere.Localization; using DysonNetwork.Sphere.Localization;
using DysonNetwork.Sphere.Poll; using DysonNetwork.Sphere.Poll;
using DysonNetwork.Sphere.Post; using DysonNetwork.Sphere.Post;
using DysonNetwork.Sphere.Publication;
using DysonNetwork.Sphere.Publisher; using DysonNetwork.Sphere.Publisher;
using DysonNetwork.Sphere.Sticker; using DysonNetwork.Sphere.Sticker;
using DysonNetwork.Sphere.Timeline; using DysonNetwork.Sphere.Timeline;
@@ -106,7 +104,6 @@ public static class ServiceCollectionExtensions
services.AddScoped<DiscoveryService>(); services.AddScoped<DiscoveryService>();
services.AddScoped<PollService>(); services.AddScoped<PollService>();
services.AddScoped<AutocompletionService>(); services.AddScoped<AutocompletionService>();
services.AddScoped<PublicationSiteService>();
var translationProvider = configuration["Translation:Provider"]?.ToLower(); var translationProvider = configuration["Translation:Provider"]?.ToLower();
switch (translationProvider) switch (translationProvider)

View File

@@ -1,4 +1,5 @@
using DysonNetwork.Shared.Data; using DysonNetwork.Shared.Data;
using DysonNetwork.Shared.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design; using Microsoft.EntityFrameworkCore.Design;
@@ -6,6 +7,9 @@ namespace DysonNetwork.Zone;
public class AppDatabase(DbContextOptions<AppDatabase> options, IConfiguration configuration) : DbContext(options) public class AppDatabase(DbContextOptions<AppDatabase> options, IConfiguration configuration) : DbContext(options)
{ {
public DbSet<SnPublicationSite> PublicationSites { get; set; } = null!;
public DbSet<SnPublicationPage> PublicationPages { get; set; } = null!;
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
optionsBuilder.UseNpgsql( optionsBuilder.UseNpgsql(

View File

@@ -0,0 +1,148 @@
// <auto-generated />
using System;
using System.Collections.Generic;
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("20251119140708_AddPublicationSites")]
partial class AddPublicationSites
{
/// <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<string>("Preset")
.IsRequired()
.HasMaxLength(8192)
.HasColumnType("character varying(8192)")
.HasColumnName("preset");
b.Property<Guid>("SiteId")
.HasColumnType("uuid")
.HasColumnName("site_id");
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<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<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
}
}
}

View File

@@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
using NodaTime;
#nullable disable
namespace DysonNetwork.Zone.Migrations
{
/// <inheritdoc />
public partial class AddPublicationSites : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "publication_sites",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false),
slug = table.Column<string>(type: "character varying(4096)", maxLength: 4096, nullable: false),
name = table.Column<string>(type: "character varying(4096)", maxLength: 4096, nullable: false),
description = table.Column<string>(type: "character varying(8192)", maxLength: 8192, nullable: true),
publisher_id = table.Column<Guid>(type: "uuid", nullable: false),
account_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_publication_sites", x => x.id);
});
migrationBuilder.CreateTable(
name: "publication_pages",
columns: table => new
{
id = table.Column<Guid>(type: "uuid", nullable: false),
preset = table.Column<string>(type: "character varying(8192)", maxLength: 8192, nullable: false),
path = table.Column<string>(type: "character varying(8192)", maxLength: 8192, nullable: false),
config = table.Column<Dictionary<string, object>>(type: "jsonb", nullable: false),
site_id = table.Column<Guid>(type: "uuid", nullable: false),
created_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
updated_at = table.Column<Instant>(type: "timestamp with time zone", nullable: false),
deleted_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("pk_publication_pages", x => x.id);
table.ForeignKey(
name: "fk_publication_pages_publication_sites_site_id",
column: x => x.site_id,
principalTable: "publication_sites",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "ix_publication_pages_site_id",
table: "publication_pages",
column: "site_id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "publication_pages");
migrationBuilder.DropTable(
name: "publication_sites");
}
}
}

View File

@@ -0,0 +1,145 @@
// <auto-generated />
using System;
using System.Collections.Generic;
using DysonNetwork.Zone;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using NodaTime;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace DysonNetwork.Zone.Migrations
{
[DbContext(typeof(AppDatabase))]
partial class AppDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(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<string>("Preset")
.IsRequired()
.HasMaxLength(8192)
.HasColumnType("character varying(8192)")
.HasColumnName("preset");
b.Property<Guid>("SiteId")
.HasColumnType("uuid")
.HasColumnName("site_id");
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<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<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
}
}
}

View File

@@ -1,17 +1,17 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using DysonNetwork.Shared.Models; using DysonNetwork.Shared.Models;
using DysonNetwork.Sphere.Publisher; using DysonNetwork.Shared.Registry;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using PublicationPagePresets = DysonNetwork.Shared.Models.PublicationPagePresets; using PublicationPagePresets = DysonNetwork.Shared.Models.PublicationPagePresets;
namespace DysonNetwork.Sphere.Publication; namespace DysonNetwork.Zone.Publication;
[ApiController] [ApiController]
[Route("/api/sites")] [Route("/api/sites")]
public class PublicationSiteController( public class PublicationSiteController(
PublicationSiteService publicationService, PublicationSiteService publicationService,
PublisherService publisherService RemotePublisherService publisherService
) : ControllerBase ) : ControllerBase
{ {
[HttpGet("{slug}")] [HttpGet("{slug}")]

View File

@@ -2,14 +2,13 @@ using System.Text.RegularExpressions;
using DysonNetwork.Shared.Auth; using DysonNetwork.Shared.Auth;
using DysonNetwork.Shared.Models; using DysonNetwork.Shared.Models;
using DysonNetwork.Shared.Registry; using DysonNetwork.Shared.Registry;
using DysonNetwork.Sphere.Publisher;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace DysonNetwork.Sphere.Publication; namespace DysonNetwork.Zone.Publication;
public class PublicationSiteService( public class PublicationSiteService(
AppDatabase db, AppDatabase db,
PublisherService publisherService, RemotePublisherService publisherService,
RemoteAccountService remoteAccounts RemoteAccountService remoteAccounts
) )
{ {

View File

@@ -3,6 +3,7 @@ using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using DysonNetwork.Shared.Cache; using DysonNetwork.Shared.Cache;
using DysonNetwork.Shared.GeoIp; using DysonNetwork.Shared.GeoIp;
using DysonNetwork.Zone.Publication;
using NodaTime; using NodaTime;
using NodaTime.Serialization.SystemTextJson; using NodaTime.Serialization.SystemTextJson;
@@ -74,6 +75,8 @@ public static class ServiceCollectionExtensions
services.Configure<GeoIpOptions>(configuration.GetSection("GeoIP")); services.Configure<GeoIpOptions>(configuration.GetSection("GeoIP"));
services.AddScoped<GeoIpService>(); services.AddScoped<GeoIpService>();
services.AddScoped<PublicationSiteService>();
return services; return services;
} }
} }