feat: много запланированного

- клонирование коллекции
- добавление паблик-коллекций
- регенерация паблик-ссылок
This commit is contained in:
2026-10-07 02:45:37 +04:00
parent c1b052e2c7
commit 274e60a433
30 changed files with 719 additions and 112 deletions
@@ -0,0 +1,316 @@
// <auto-generated />
using System;
using MemeVault.Infrastructure.Persistence;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace MemeVault.Infrastructure.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20261006223631_DropCollectionIsInbox")]
partial class DropCollectionIsInbox
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "10.0.12")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("MemeVault.Domain.Aggregates.BotUser.BotUser", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<string>("FirstName")
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasColumnName("first_name");
b.Property<Guid?>("InboxCollectionId")
.HasColumnType("uuid")
.HasColumnName("inbox_collection_id");
b.Property<DateTimeOffset>("LastSeenAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("last_seen_at");
b.Property<long>("TelegramId")
.HasColumnType("bigint")
.HasColumnName("telegram_id");
b.Property<string>("Username")
.IsRequired()
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasColumnName("username");
b.HasKey("Id");
b.HasIndex("InboxCollectionId");
b.HasIndex("TelegramId")
.IsUnique()
.HasDatabaseName("ix_bot_users_telegram_id");
b.ToTable("bot_users", (string)null);
});
modelBuilder.Entity("MemeVault.Domain.Aggregates.Collection.Collection", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<string>("Description")
.HasMaxLength(500)
.HasColumnType("character varying(500)")
.HasColumnName("description");
b.Property<bool>("IsNsfw")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
.HasDefaultValue(false)
.HasColumnName("is_nsfw");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("character varying(100)")
.HasColumnName("name");
b.Property<string>("ShareToken")
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasColumnName("share_token");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("updated_at");
b.Property<string>("Visibility")
.IsRequired()
.HasColumnType("text")
.HasColumnName("visibility");
b.HasKey("Id");
b.HasIndex("ShareToken")
.IsUnique()
.HasDatabaseName("ix_collections_share_token")
.HasFilter("share_token IS NOT NULL");
b.ToTable("collections", (string)null);
});
modelBuilder.Entity("MemeVault.Domain.Aggregates.CollectionInvite.CollectionInvite", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id");
b.Property<Guid>("CollectionId")
.HasColumnType("uuid")
.HasColumnName("collection_id");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<long>("CreatedByTelegramId")
.HasColumnType("bigint")
.HasColumnName("created_by_telegram_id");
b.Property<DateTimeOffset?>("ExpiresAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("expires_at");
b.Property<bool>("IsRevoked")
.HasColumnType("boolean")
.HasColumnName("is_revoked");
b.Property<DateTimeOffset?>("RevokedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("revoked_at");
b.Property<string>("Role")
.IsRequired()
.HasColumnType("text")
.HasColumnName("role");
b.Property<string>("Token")
.IsRequired()
.HasMaxLength(32)
.HasColumnType("character varying(32)")
.HasColumnName("token");
b.HasKey("Id");
b.HasIndex("CollectionId")
.HasDatabaseName("ix_collection_invites_collection_id");
b.HasIndex("Token")
.IsUnique()
.HasDatabaseName("ix_collection_invites_token");
b.ToTable("collection_invites", (string)null);
});
modelBuilder.Entity("MemeVault.Domain.Aggregates.MediaItem.MediaItem", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id");
b.Property<string>("Caption")
.HasMaxLength(4096)
.HasColumnType("character varying(4096)")
.HasColumnName("caption");
b.Property<Guid>("CollectionId")
.HasColumnType("uuid")
.HasColumnName("collection_id");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<string>("MediaGroupId")
.HasMaxLength(64)
.HasColumnType("character varying(64)")
.HasColumnName("media_group_id");
b.Property<long>("OwnerTelegramId")
.HasColumnType("bigint")
.HasColumnName("owner_telegram_id");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("text")
.HasColumnName("type");
b.Property<DateTimeOffset?>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("updated_at");
b.Property<string[]>("_tags")
.IsRequired()
.HasColumnType("text[]")
.HasColumnName("tags");
b.HasKey("Id");
b.HasIndex("CollectionId")
.HasDatabaseName("ix_media_items_collection");
b.HasIndex("OwnerTelegramId")
.HasDatabaseName("ix_media_items_owner");
b.HasIndex("_tags")
.HasDatabaseName("ix_media_items_tags");
NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("_tags"), "gin");
b.ToTable("media_items", (string)null);
});
modelBuilder.Entity("MemeVault.Domain.Aggregates.BotUser.BotUser", b =>
{
b.HasOne("MemeVault.Domain.Aggregates.Collection.Collection", null)
.WithMany()
.HasForeignKey("InboxCollectionId")
.OnDelete(DeleteBehavior.SetNull);
});
modelBuilder.Entity("MemeVault.Domain.Aggregates.Collection.Collection", b =>
{
b.OwnsMany("MemeVault.Domain.Aggregates.Collection.CollectionMember", "Members", b1 =>
{
b1.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uuid")
.HasColumnName("id");
b1.Property<DateTimeOffset>("AddedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("added_at");
b1.Property<Guid>("CollectionId")
.HasColumnType("uuid")
.HasColumnName("collection_id");
b1.Property<string>("Role")
.IsRequired()
.HasColumnType("text")
.HasColumnName("role");
b1.Property<long>("TelegramId")
.HasColumnType("bigint")
.HasColumnName("telegram_id");
b1.HasKey("Id");
b1.HasIndex("CollectionId", "TelegramId")
.IsUnique()
.HasDatabaseName("ix_collection_members_unique");
b1.ToTable("collection_members", (string)null);
b1.WithOwner()
.HasForeignKey("CollectionId");
});
b.Navigation("Members");
});
modelBuilder.Entity("MemeVault.Domain.Aggregates.MediaItem.MediaItem", b =>
{
b.OwnsOne("MemeVault.Domain.ValueObjects.MediaSource", "Source", b1 =>
{
b1.Property<Guid>("MediaItemId")
.HasColumnType("uuid");
b1.Property<string>("Origin")
.HasColumnType("text")
.HasColumnName("source_origin");
b1.Property<string>("Reference")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasColumnName("source_reference");
b1.HasKey("MediaItemId");
b1.ToTable("media_items");
b1.WithOwner()
.HasForeignKey("MediaItemId");
});
b.Navigation("Source");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,61 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace MemeVault.Infrastructure.Migrations
{
/// <inheritdoc />
public partial class DropCollectionIsInbox : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "is_inbox",
table: "collections");
migrationBuilder.AddColumn<Guid>(
name: "inbox_collection_id",
table: "bot_users",
type: "uuid",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_bot_users_inbox_collection_id",
table: "bot_users",
column: "inbox_collection_id");
migrationBuilder.AddForeignKey(
name: "FK_bot_users_collections_inbox_collection_id",
table: "bot_users",
column: "inbox_collection_id",
principalTable: "collections",
principalColumn: "id",
onDelete: ReferentialAction.SetNull);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_bot_users_collections_inbox_collection_id",
table: "bot_users");
migrationBuilder.DropIndex(
name: "IX_bot_users_inbox_collection_id",
table: "bot_users");
migrationBuilder.DropColumn(
name: "inbox_collection_id",
table: "bot_users");
migrationBuilder.AddColumn<bool>(
name: "is_inbox",
table: "collections",
type: "boolean",
nullable: false,
defaultValue: false);
}
}
}
@@ -38,6 +38,10 @@ namespace MemeVault.Infrastructure.Migrations
.HasColumnType("character varying(64)")
.HasColumnName("first_name");
b.Property<Guid?>("InboxCollectionId")
.HasColumnType("uuid")
.HasColumnName("inbox_collection_id");
b.Property<DateTimeOffset>("LastSeenAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("last_seen_at");
@@ -54,6 +58,8 @@ namespace MemeVault.Infrastructure.Migrations
b.HasKey("Id");
b.HasIndex("InboxCollectionId");
b.HasIndex("TelegramId")
.IsUnique()
.HasDatabaseName("ix_bot_users_telegram_id");
@@ -77,10 +83,6 @@ namespace MemeVault.Infrastructure.Migrations
.HasColumnType("character varying(500)")
.HasColumnName("description");
b.Property<bool>("IsInbox")
.HasColumnType("boolean")
.HasColumnName("is_inbox");
b.Property<bool>("IsNsfw")
.ValueGeneratedOnAdd()
.HasColumnType("boolean")
@@ -230,6 +232,14 @@ namespace MemeVault.Infrastructure.Migrations
b.ToTable("media_items", (string)null);
});
modelBuilder.Entity("MemeVault.Domain.Aggregates.BotUser.BotUser", b =>
{
b.HasOne("MemeVault.Domain.Aggregates.Collection.Collection", null)
.WithMany()
.HasForeignKey("InboxCollectionId")
.OnDelete(DeleteBehavior.SetNull);
});
modelBuilder.Entity("MemeVault.Domain.Aggregates.Collection.Collection", b =>
{
b.OwnsMany("MemeVault.Domain.Aggregates.Collection.CollectionMember", "Members", b1 =>
@@ -32,5 +32,15 @@ public sealed class BotUserConfiguration : IEntityTypeConfiguration<BotUser>
builder.Property(x => x.CreatedAt).HasColumnName("created_at");
builder.Property(x => x.LastSeenAt).HasColumnName("last_seen_at");
builder.Property(x => x.InboxCollectionId)
.HasColumnName("inbox_collection_id");
// FK → collections.id; без навигационного свойства на агрегате
builder.HasOne<Domain.Aggregates.Collection.Collection>()
.WithMany()
.HasForeignKey(u => u.InboxCollectionId)
.IsRequired(false)
.OnDelete(DeleteBehavior.SetNull);
}
}
@@ -25,10 +25,6 @@ public sealed class CollectionConfiguration : IEntityTypeConfiguration<Collectio
.HasColumnName("description")
.HasMaxLength(500);
builder.Property(x => x.IsInbox)
.HasColumnName("is_inbox")
.IsRequired();
builder.Property(x => x.IsNsfw)
.HasColumnName("is_nsfw")
.IsRequired()
@@ -27,8 +27,7 @@ public sealed class CollectionRepository : ICollectionRepository
.Include(c => c.Members)
.Where(c => c.Members.Any(m =>
m.TelegramId == ownerTelegramId && m.Role == CollectionRole.Owner))
.OrderBy(x => x.IsInbox ? 0 : 1) // Inbox всегда первым
.ThenBy(x => x.Name)
.OrderBy(x => x.Name)
.ToListAsync(ct);
}
@@ -37,19 +36,10 @@ public sealed class CollectionRepository : ICollectionRepository
return await _db.Collections
.Include(c => c.Members)
.Where(c => c.Members.Any(m => m.TelegramId == telegramId))
.OrderBy(x => x.IsInbox ? 0 : 1) // Inbox всегда первым
.ThenBy(x => x.Name)
.OrderBy(x => x.Name)
.ToListAsync(ct);
}
public Task<Collection?> GetInboxAsync(long ownerTelegramId, CancellationToken ct) =>
_db.Collections
.Include(c => c.Members)
.FirstOrDefaultAsync(c =>
c.IsInbox &&
c.Members.Any(m => m.TelegramId == ownerTelegramId && m.Role == CollectionRole.Owner),
ct);
public async Task AddAsync(Collection collection, CancellationToken ct) =>
await _db.Collections.AddAsync(collection, ct);