Refactoring, database structure changed
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using WatchIt.Database.Model.Accounts;
|
||||
|
||||
namespace WatchIt.Database.Configuration.Accounts;
|
||||
|
||||
public class AccountBackgroundPictureConfiguration : IEntityTypeConfiguration<AccountBackgroundPicture>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public void Configure(EntityTypeBuilder<AccountBackgroundPicture> builder)
|
||||
{
|
||||
builder.ToTable("AccountBackgroundPictures", "accounts");
|
||||
|
||||
// Account
|
||||
builder.HasKey(x => x.AccountId);
|
||||
builder.HasIndex(x => x.AccountId)
|
||||
.IsUnique();
|
||||
builder.HasOne(x => x.Account)
|
||||
.WithOne(x => x.BackgroundPicture)
|
||||
.HasForeignKey<AccountBackgroundPicture>(x => x.AccountId)
|
||||
.IsRequired();
|
||||
builder.Property(x => x.AccountId)
|
||||
.IsRequired();
|
||||
|
||||
// Background
|
||||
builder.HasOne(x => x.Background)
|
||||
.WithMany(x => x.BackgroundUsages)
|
||||
.HasForeignKey(x => x.BackgroundId)
|
||||
.IsRequired();
|
||||
builder.Property(x => x.BackgroundId)
|
||||
.IsRequired();
|
||||
|
||||
// Version
|
||||
builder.Property(b => b.Version)
|
||||
.IsRowVersion();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using WatchIt.Database.Model.Accounts;
|
||||
|
||||
namespace WatchIt.Database.Configuration.Accounts;
|
||||
|
||||
public class AccountConfiguration : IEntityTypeConfiguration<Account>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public void Configure(EntityTypeBuilder<Account> builder)
|
||||
{
|
||||
builder.ToTable("Accounts", "accounts");
|
||||
|
||||
// Id
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.HasIndex(x => x.Id)
|
||||
.IsUnique();
|
||||
builder.Property(x => x.Id)
|
||||
.IsRequired()
|
||||
.UseIdentityAlwaysColumn();
|
||||
|
||||
// Username
|
||||
builder.Property(x => x.Username)
|
||||
.HasMaxLength(50)
|
||||
.IsRequired();
|
||||
|
||||
// Email
|
||||
builder.Property(x => x.Email)
|
||||
.HasMaxLength(320)
|
||||
.IsRequired();
|
||||
|
||||
// Password
|
||||
builder.Property(x => x.Password)
|
||||
.HasMaxLength(1000)
|
||||
.IsRequired();
|
||||
|
||||
// Left salt
|
||||
builder.Property(x => x.LeftSalt)
|
||||
.HasMaxLength(20)
|
||||
.IsRequired();
|
||||
|
||||
// Right salt
|
||||
builder.Property(x => x.RightSalt)
|
||||
.HasMaxLength(20)
|
||||
.IsRequired();
|
||||
|
||||
// Is admin
|
||||
builder.Property(x => x.IsAdmin)
|
||||
.IsRequired()
|
||||
.HasDefaultValue(false);
|
||||
|
||||
// Join date
|
||||
builder.Property(x => x.JoinDate)
|
||||
.IsRequired()
|
||||
.HasDefaultValueSql("now()");
|
||||
|
||||
// Active date
|
||||
builder.Property(x => x.ActiveDate)
|
||||
.IsRequired()
|
||||
.HasDefaultValueSql("now()");
|
||||
|
||||
// Description
|
||||
builder.Property(x => x.Description)
|
||||
.HasMaxLength(1000);
|
||||
|
||||
// Gender
|
||||
builder.HasOne(x => x.Gender)
|
||||
.WithMany(x => x.Accounts)
|
||||
.HasForeignKey(x => x.GenderId);
|
||||
builder.Property(x => x.GenderId);
|
||||
|
||||
// Version
|
||||
builder.Property(b => b.Version)
|
||||
.IsRowVersion();
|
||||
|
||||
|
||||
#region Navigation
|
||||
|
||||
// AccountFollow
|
||||
builder.HasMany(x => x.Follows)
|
||||
.WithMany(x => x.Followers)
|
||||
.UsingEntity<AccountFollow>(
|
||||
x => x.HasOne<Account>(y => y.Followed)
|
||||
.WithMany(y => y.FollowersRelationshipObjects)
|
||||
.HasForeignKey(y => y.FollowedId)
|
||||
.IsRequired(),
|
||||
x => x.HasOne<Account>(y => y.Follower)
|
||||
.WithMany(y => y.FollowsRelationshipObjects)
|
||||
.HasForeignKey(y => y.FollowerId)
|
||||
.IsRequired()
|
||||
);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using WatchIt.Database.Model.Accounts;
|
||||
|
||||
namespace WatchIt.Database.Configuration.Accounts;
|
||||
|
||||
public class AccountFollowConfiguration : IEntityTypeConfiguration<AccountFollow>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public void Configure(EntityTypeBuilder<AccountFollow> builder)
|
||||
{
|
||||
builder.ToTable("AccountFollows", "accounts");
|
||||
builder.HasKey(x => new { x.FollowerId, x.FollowedId });
|
||||
|
||||
// Follower
|
||||
// FK configured in AccountConfiguration
|
||||
builder.Property(x => x.FollowerId)
|
||||
.IsRequired();
|
||||
|
||||
// Followed
|
||||
// FK configured in AccountConfiguration
|
||||
builder.Property(x => x.FollowedId)
|
||||
.IsRequired();
|
||||
|
||||
// Version
|
||||
builder.Property(b => b.Version)
|
||||
.IsRowVersion();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using WatchIt.Database.Model.Accounts;
|
||||
|
||||
namespace WatchIt.Database.Configuration.Accounts;
|
||||
|
||||
public class AccountProfilePictureConfiguration : ImageEntityConfiguration<AccountProfilePicture>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public override void Configure(EntityTypeBuilder<AccountProfilePicture> builder)
|
||||
{
|
||||
builder.ToTable($"AccountProfilePictures", "accounts");
|
||||
|
||||
// Account
|
||||
builder.HasKey(x => x.AccountId);
|
||||
builder.HasIndex(x => x.AccountId)
|
||||
.IsUnique();
|
||||
builder.HasOne(x => x.Account)
|
||||
.WithOne(x => x.ProfilePicture)
|
||||
.HasForeignKey<AccountProfilePicture>(x => x.AccountId)
|
||||
.IsRequired();
|
||||
builder.Property(x => x.AccountId)
|
||||
.IsRequired();
|
||||
|
||||
// Generic properties
|
||||
base.Configure(builder);
|
||||
|
||||
// Version
|
||||
builder.Property(b => b.Version)
|
||||
.IsRowVersion();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using WatchIt.Database.Model.Accounts;
|
||||
|
||||
namespace WatchIt.Database.Configuration.Accounts;
|
||||
|
||||
public class AccountRefreshTokenConfiguration : IEntityTypeConfiguration<AccountRefreshToken>
|
||||
{
|
||||
#region PUBLIC METHODS
|
||||
|
||||
public void Configure(EntityTypeBuilder<AccountRefreshToken> builder)
|
||||
{
|
||||
builder.ToTable("AccountRefreshTokens", "accounts");
|
||||
|
||||
// Id
|
||||
builder.HasKey(x => x.Token);
|
||||
builder.HasIndex(x => x.Token)
|
||||
.IsUnique();
|
||||
builder.Property(x => x.Token)
|
||||
.IsRequired();
|
||||
|
||||
// Account
|
||||
builder.HasOne(x => x.Account)
|
||||
.WithMany(x => x.RefreshTokens)
|
||||
.HasForeignKey(x => x.AccountId)
|
||||
.IsRequired();
|
||||
builder.Property(x => x.AccountId)
|
||||
.IsRequired();
|
||||
|
||||
// Expiration date
|
||||
builder.Property(x => x.ExpirationDate)
|
||||
.IsRequired();
|
||||
|
||||
// Is extendable
|
||||
builder.Property(x => x.IsExtendable)
|
||||
.IsRequired();
|
||||
|
||||
// Version
|
||||
builder.Property(b => b.Version)
|
||||
.IsRowVersion();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user