feat: invites
This commit is contained in:
@@ -2,6 +2,7 @@ using MemeVault.Application.Common;
|
||||
using MemeVault.Domain.Repositories;
|
||||
using MemeVault.Infrastructure.Persistence;
|
||||
using MemeVault.Infrastructure.Persistence.Repositories;
|
||||
using MemeVault.Infrastructure.Persistence.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -21,6 +22,7 @@ public static class InfrastructureServiceExtensions
|
||||
services.AddScoped<IMediaItemRepository, MediaItemRepository>();
|
||||
services.AddScoped<IBotUserRepository, BotUserRepository>();
|
||||
services.AddScoped<ICollectionRepository, CollectionRepository>();
|
||||
services.AddScoped<ICollectionInviteRepository, CollectionInviteRepository>();
|
||||
|
||||
var redisConn = config.GetConnectionString("Redis") ?? "localhost:6379";
|
||||
services.AddStackExchangeRedisCache(opts => opts.Configuration = redisConn);
|
||||
|
||||
+296
@@ -0,0 +1,296 @@
|
||||
// <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("20260928051822_AddCollectionInvites")]
|
||||
partial class AddCollectionInvites
|
||||
{
|
||||
/// <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<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("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>("IsInbox")
|
||||
.HasColumnType("boolean")
|
||||
.HasColumnName("is_inbox");
|
||||
|
||||
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<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.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,82 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MemeVault.Infrastructure.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddCollectionInvites : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropIndex(
|
||||
name: "ix_collections_inbox_unique",
|
||||
table: "collections");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "ix_collections_owner",
|
||||
table: "collections");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "owner_telegram_id",
|
||||
table: "collections");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "collection_invites",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
collection_id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||
created_by_telegram_id = table.Column<long>(type: "bigint", nullable: false),
|
||||
role = table.Column<string>(type: "text", nullable: false),
|
||||
token = table.Column<string>(type: "character varying(32)", maxLength: 32, nullable: false),
|
||||
created_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
|
||||
is_revoked = table.Column<bool>(type: "boolean", nullable: false),
|
||||
revoked_at = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_collection_invites", x => x.id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_collection_invites_collection_id",
|
||||
table: "collection_invites",
|
||||
column: "collection_id");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_collection_invites_token",
|
||||
table: "collection_invites",
|
||||
column: "token",
|
||||
unique: true);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "collection_invites");
|
||||
|
||||
migrationBuilder.AddColumn<long>(
|
||||
name: "owner_telegram_id",
|
||||
table: "collections",
|
||||
type: "bigint",
|
||||
nullable: false,
|
||||
defaultValue: 0L);
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_collections_inbox_unique",
|
||||
table: "collections",
|
||||
columns: new[] { "owner_telegram_id", "is_inbox" },
|
||||
unique: true,
|
||||
filter: "is_inbox = true");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "ix_collections_owner",
|
||||
table: "collections",
|
||||
column: "owner_telegram_id");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,10 +87,6 @@ namespace MemeVault.Infrastructure.Migrations
|
||||
.HasColumnType("character varying(100)")
|
||||
.HasColumnName("name");
|
||||
|
||||
b.Property<long>("OwnerTelegramId")
|
||||
.HasColumnType("bigint")
|
||||
.HasColumnName("owner_telegram_id");
|
||||
|
||||
b.Property<string>("ShareToken")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("character varying(64)")
|
||||
@@ -107,22 +103,64 @@ namespace MemeVault.Infrastructure.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("OwnerTelegramId")
|
||||
.HasDatabaseName("ix_collections_owner");
|
||||
|
||||
b.HasIndex("ShareToken")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_collections_share_token")
|
||||
.HasFilter("share_token IS NOT NULL");
|
||||
|
||||
b.HasIndex("OwnerTelegramId", "IsInbox")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_collections_inbox_unique")
|
||||
.HasFilter("is_inbox = true");
|
||||
|
||||
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<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")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using MemeVault.Application.Common;
|
||||
using MemeVault.Domain.Aggregates.BotUser;
|
||||
using MemeVault.Domain.Aggregates.Collection;
|
||||
using MemeVault.Domain.Aggregates.CollectionInvite;
|
||||
using MemeVault.Domain.Aggregates.MediaItem;
|
||||
using MemeVault.Infrastructure.Persistence.Configurations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -14,11 +15,13 @@ public sealed class AppDbContext : DbContext, IUnitOfWork
|
||||
public DbSet<MediaItem> MediaItems => Set<MediaItem>();
|
||||
public DbSet<BotUser> BotUsers => Set<BotUser>();
|
||||
public DbSet<Collection> Collections => Set<Collection>();
|
||||
public DbSet<CollectionInvite> CollectionInvites => Set<CollectionInvite>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.ApplyConfiguration(new MediaItemConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new BotUserConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new CollectionConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new CollectionInviteConfiguration());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,8 @@ public sealed class CollectionConfiguration : IEntityTypeConfiguration<Collectio
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.Property(x => x.Id).HasColumnName("id");
|
||||
|
||||
builder.Property(x => x.OwnerTelegramId)
|
||||
.HasColumnName("owner_telegram_id")
|
||||
.IsRequired();
|
||||
// OwnerTelegramId вычисляется из Members, не хранится как отдельная колонка
|
||||
builder.Ignore(x => x.OwnerTelegramId);
|
||||
|
||||
builder.Property(x => x.Name)
|
||||
.HasColumnName("name")
|
||||
@@ -44,15 +43,6 @@ public sealed class CollectionConfiguration : IEntityTypeConfiguration<Collectio
|
||||
.HasFilter("share_token IS NOT NULL")
|
||||
.HasDatabaseName("ix_collections_share_token");
|
||||
|
||||
builder.HasIndex(x => x.OwnerTelegramId)
|
||||
.HasDatabaseName("ix_collections_owner");
|
||||
|
||||
// Уникальность Inbox на пользователя
|
||||
builder.HasIndex(x => new { x.OwnerTelegramId, x.IsInbox })
|
||||
.HasFilter("is_inbox = true")
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_collections_inbox_unique");
|
||||
|
||||
// Участники — owned entity
|
||||
builder.OwnsMany(x => x.Members, m =>
|
||||
{
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
using MemeVault.Domain.Aggregates.CollectionInvite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace MemeVault.Infrastructure.Persistence.Configurations;
|
||||
|
||||
public sealed class CollectionInviteConfiguration : IEntityTypeConfiguration<CollectionInvite>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<CollectionInvite> builder)
|
||||
{
|
||||
builder.ToTable("collection_invites");
|
||||
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.Property(x => x.Id).HasColumnName("id");
|
||||
|
||||
builder.Property(x => x.CollectionId)
|
||||
.HasColumnName("collection_id")
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.CreatedByTelegramId)
|
||||
.HasColumnName("created_by_telegram_id")
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.Role)
|
||||
.HasColumnName("role")
|
||||
.HasConversion<string>()
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.Token)
|
||||
.HasColumnName("token")
|
||||
.HasMaxLength(32)
|
||||
.IsRequired();
|
||||
|
||||
builder.HasIndex(x => x.Token)
|
||||
.IsUnique()
|
||||
.HasDatabaseName("ix_collection_invites_token");
|
||||
|
||||
builder.HasIndex(x => x.CollectionId)
|
||||
.HasDatabaseName("ix_collection_invites_collection_id");
|
||||
|
||||
builder.Property(x => x.CreatedAt).HasColumnName("created_at");
|
||||
builder.Property(x => x.IsRevoked).HasColumnName("is_revoked");
|
||||
builder.Property(x => x.RevokedAt).HasColumnName("revoked_at");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using MemeVault.Domain.Aggregates.CollectionInvite;
|
||||
using MemeVault.Domain.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace MemeVault.Infrastructure.Persistence.Repositories;
|
||||
|
||||
public sealed class CollectionInviteRepository : ICollectionInviteRepository
|
||||
{
|
||||
private readonly AppDbContext _db;
|
||||
|
||||
public CollectionInviteRepository(AppDbContext db) => _db = db;
|
||||
|
||||
public Task<CollectionInvite?> GetByIdAsync(Guid id, CancellationToken ct) =>
|
||||
_db.CollectionInvites.FirstOrDefaultAsync(x => x.Id == id, ct);
|
||||
|
||||
public Task<CollectionInvite?> GetByTokenAsync(string token, CancellationToken ct) =>
|
||||
_db.CollectionInvites.FirstOrDefaultAsync(x => x.Token == token, ct);
|
||||
|
||||
public async Task<IReadOnlyList<CollectionInvite>> GetByCollectionAsync(Guid collectionId, CancellationToken ct) =>
|
||||
await _db.CollectionInvites
|
||||
.Where(x => x.CollectionId == collectionId)
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.ToListAsync(ct);
|
||||
|
||||
public async Task AddAsync(CollectionInvite invite, CancellationToken ct) =>
|
||||
await _db.CollectionInvites.AddAsync(invite, ct);
|
||||
|
||||
public Task UpdateAsync(CollectionInvite invite, CancellationToken ct)
|
||||
{
|
||||
_db.CollectionInvites.Update(invite);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using MemeVault.Domain.Aggregates.Collection;
|
||||
using MemeVault.Domain.Enums;
|
||||
using MemeVault.Domain.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
@@ -24,7 +25,8 @@ public sealed class CollectionRepository : ICollectionRepository
|
||||
{
|
||||
return await _db.Collections
|
||||
.Include(c => c.Members)
|
||||
.Where(x => x.OwnerTelegramId == ownerTelegramId)
|
||||
.Where(c => c.Members.Any(m =>
|
||||
m.TelegramId == ownerTelegramId && m.Role == CollectionRole.Owner))
|
||||
.OrderBy(x => x.IsInbox ? 0 : 1) // Inbox всегда первым
|
||||
.ThenBy(x => x.Name)
|
||||
.ToListAsync(ct);
|
||||
@@ -32,7 +34,11 @@ public sealed class CollectionRepository : ICollectionRepository
|
||||
|
||||
public Task<Collection?> GetInboxAsync(long ownerTelegramId, CancellationToken ct) =>
|
||||
_db.Collections
|
||||
.FirstOrDefaultAsync(x => x.OwnerTelegramId == ownerTelegramId && x.IsInbox, ct);
|
||||
.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);
|
||||
|
||||
Reference in New Issue
Block a user