Relationships controllers

This commit is contained in:
2025-04-17 23:54:35 +08:00
parent cec8c3af81
commit f9701764f3
8 changed files with 282 additions and 61 deletions

View File

@ -14,7 +14,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace DysonNetwork.Sphere.Migrations
{
[DbContext(typeof(AppDatabase))]
[Migration("20250415171044_AddRelationship")]
[Migration("20250417145426_AddRelationship")]
partial class AddRelationship
{
/// <inheritdoc />
@ -226,13 +226,13 @@ namespace DysonNetwork.Sphere.Migrations
modelBuilder.Entity("DysonNetwork.Sphere.Account.Relationship", b =>
{
b.Property<long>("FromAccountId")
b.Property<long>("AccountId")
.HasColumnType("bigint")
.HasColumnName("from_account_id");
.HasColumnName("account_id");
b.Property<long>("ToAccountId")
b.Property<long>("RelatedId")
.HasColumnType("bigint")
.HasColumnName("to_account_id");
.HasColumnName("related_id");
b.Property<Instant>("CreatedAt")
.HasColumnType("timestamp with time zone")
@ -242,19 +242,23 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("timestamp with time zone")
.HasColumnName("deleted_at");
b.Property<int>("Type")
b.Property<Instant?>("ExpiredAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("expired_at");
b.Property<int>("Status")
.HasColumnType("integer")
.HasColumnName("type");
.HasColumnName("status");
b.Property<Instant>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("updated_at");
b.HasKey("FromAccountId", "ToAccountId")
b.HasKey("AccountId", "RelatedId")
.HasName("pk_account_relationships");
b.HasIndex("ToAccountId")
.HasDatabaseName("ix_account_relationships_to_account_id");
b.HasIndex("RelatedId")
.HasDatabaseName("ix_account_relationships_related_id");
b.ToTable("account_relationships", (string)null);
});
@ -514,23 +518,23 @@ namespace DysonNetwork.Sphere.Migrations
modelBuilder.Entity("DysonNetwork.Sphere.Account.Relationship", b =>
{
b.HasOne("DysonNetwork.Sphere.Account.Account", "FromAccount")
b.HasOne("DysonNetwork.Sphere.Account.Account", "Account")
.WithMany("OutgoingRelationships")
.HasForeignKey("FromAccountId")
.HasForeignKey("AccountId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_account_relationships_accounts_from_account_id");
.HasConstraintName("fk_account_relationships_accounts_account_id");
b.HasOne("DysonNetwork.Sphere.Account.Account", "ToAccount")
b.HasOne("DysonNetwork.Sphere.Account.Account", "Related")
.WithMany("IncomingRelationships")
.HasForeignKey("ToAccountId")
.HasForeignKey("RelatedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_account_relationships_accounts_to_account_id");
.HasConstraintName("fk_account_relationships_accounts_related_id");
b.Navigation("FromAccount");
b.Navigation("Account");
b.Navigation("ToAccount");
b.Navigation("Related");
});
modelBuilder.Entity("DysonNetwork.Sphere.Auth.Challenge", b =>

View File

@ -15,34 +15,35 @@ namespace DysonNetwork.Sphere.Migrations
name: "account_relationships",
columns: table => new
{
from_account_id = table.Column<long>(type: "bigint", nullable: false),
to_account_id = table.Column<long>(type: "bigint", nullable: false),
type = table.Column<int>(type: "integer", nullable: false),
account_id = table.Column<long>(type: "bigint", nullable: false),
related_id = table.Column<long>(type: "bigint", nullable: false),
expired_at = table.Column<Instant>(type: "timestamp with time zone", nullable: true),
status = table.Column<int>(type: "integer", 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_account_relationships", x => new { x.from_account_id, x.to_account_id });
table.PrimaryKey("pk_account_relationships", x => new { x.account_id, x.related_id });
table.ForeignKey(
name: "fk_account_relationships_accounts_from_account_id",
column: x => x.from_account_id,
name: "fk_account_relationships_accounts_account_id",
column: x => x.account_id,
principalTable: "accounts",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "fk_account_relationships_accounts_to_account_id",
column: x => x.to_account_id,
name: "fk_account_relationships_accounts_related_id",
column: x => x.related_id,
principalTable: "accounts",
principalColumn: "id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "ix_account_relationships_to_account_id",
name: "ix_account_relationships_related_id",
table: "account_relationships",
column: "to_account_id");
column: "related_id");
}
/// <inheritdoc />

View File

@ -223,13 +223,13 @@ namespace DysonNetwork.Sphere.Migrations
modelBuilder.Entity("DysonNetwork.Sphere.Account.Relationship", b =>
{
b.Property<long>("FromAccountId")
b.Property<long>("AccountId")
.HasColumnType("bigint")
.HasColumnName("from_account_id");
.HasColumnName("account_id");
b.Property<long>("ToAccountId")
b.Property<long>("RelatedId")
.HasColumnType("bigint")
.HasColumnName("to_account_id");
.HasColumnName("related_id");
b.Property<Instant>("CreatedAt")
.HasColumnType("timestamp with time zone")
@ -239,19 +239,23 @@ namespace DysonNetwork.Sphere.Migrations
.HasColumnType("timestamp with time zone")
.HasColumnName("deleted_at");
b.Property<int>("Type")
b.Property<Instant?>("ExpiredAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("expired_at");
b.Property<int>("Status")
.HasColumnType("integer")
.HasColumnName("type");
.HasColumnName("status");
b.Property<Instant>("UpdatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("updated_at");
b.HasKey("FromAccountId", "ToAccountId")
b.HasKey("AccountId", "RelatedId")
.HasName("pk_account_relationships");
b.HasIndex("ToAccountId")
.HasDatabaseName("ix_account_relationships_to_account_id");
b.HasIndex("RelatedId")
.HasDatabaseName("ix_account_relationships_related_id");
b.ToTable("account_relationships", (string)null);
});
@ -511,23 +515,23 @@ namespace DysonNetwork.Sphere.Migrations
modelBuilder.Entity("DysonNetwork.Sphere.Account.Relationship", b =>
{
b.HasOne("DysonNetwork.Sphere.Account.Account", "FromAccount")
b.HasOne("DysonNetwork.Sphere.Account.Account", "Account")
.WithMany("OutgoingRelationships")
.HasForeignKey("FromAccountId")
.HasForeignKey("AccountId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_account_relationships_accounts_from_account_id");
.HasConstraintName("fk_account_relationships_accounts_account_id");
b.HasOne("DysonNetwork.Sphere.Account.Account", "ToAccount")
b.HasOne("DysonNetwork.Sphere.Account.Account", "Related")
.WithMany("IncomingRelationships")
.HasForeignKey("ToAccountId")
.HasForeignKey("RelatedId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired()
.HasConstraintName("fk_account_relationships_accounts_to_account_id");
.HasConstraintName("fk_account_relationships_accounts_related_id");
b.Navigation("FromAccount");
b.Navigation("Account");
b.Navigation("ToAccount");
b.Navigation("Related");
});
modelBuilder.Entity("DysonNetwork.Sphere.Auth.Challenge", b =>