main project split, authpassword endpoint created
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using TimetableDesigner.Backend.Services.Authentication.Database.Model;
|
||||
|
||||
namespace TimetableDesigner.Backend.Services.Authentication.Database.Configuration;
|
||||
|
||||
public class AccountConfiguration : IEntityTypeConfiguration<Account>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Account> builder)
|
||||
{
|
||||
builder.HasKey(x => x.Id);
|
||||
builder.HasIndex(x => x.Id)
|
||||
.IsUnique();
|
||||
builder.Property(x => x.Id)
|
||||
.IsRequired()
|
||||
.UseIdentityAlwaysColumn();
|
||||
|
||||
builder.Property(x => x.Email)
|
||||
.HasMaxLength(320)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.Password)
|
||||
.HasMaxLength(1000)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.PasswordSalt)
|
||||
.HasMaxLength(20)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(b => b.Version)
|
||||
.IsRowVersion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using TimetableDesigner.Backend.Services.Authentication.Database.Model;
|
||||
|
||||
namespace TimetableDesigner.Backend.Services.Authentication.Database.Configuration;
|
||||
|
||||
public class RefreshTokenConfiguration : IEntityTypeConfiguration<RefreshToken>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<RefreshToken> builder)
|
||||
{
|
||||
builder.HasKey(x => x.Token);
|
||||
builder.HasIndex(x => x.Token)
|
||||
.IsUnique();
|
||||
builder.Property(x => x.Token)
|
||||
.IsRequired();
|
||||
|
||||
builder.HasOne(x => x.Account)
|
||||
.WithMany(x => x.RefreshTokens)
|
||||
.HasForeignKey(x => x.AccountId)
|
||||
.IsRequired();
|
||||
builder.Property(x => x.AccountId)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.ExpirationDate)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(x => x.IsExtendable)
|
||||
.IsRequired();
|
||||
|
||||
builder.Property(b => b.Version)
|
||||
.IsRowVersion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TimetableDesigner.Backend.Services.Authentication.Database.Model;
|
||||
|
||||
namespace TimetableDesigner.Backend.Services.Authentication.Database;
|
||||
|
||||
public class DatabaseContext : DbContext
|
||||
{
|
||||
public virtual DbSet<Account> Accounts { get; set; }
|
||||
public virtual DbSet<RefreshToken> RefreshTokens { get; set; }
|
||||
|
||||
|
||||
public DatabaseContext() { }
|
||||
|
||||
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options) { }
|
||||
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) =>
|
||||
optionsBuilder.UseNpgsql("name=Database");
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder) =>
|
||||
modelBuilder.ApplyConfigurationsFromAssembly(Assembly.GetAssembly(typeof(DatabaseContext))!);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace TimetableDesigner.Backend.Services.Authentication.Database.Model;
|
||||
|
||||
public class Account
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Email { get; set; } = null!;
|
||||
public byte[] Password { get; set; } = null!;
|
||||
public string PasswordSalt { get; set; } = null!;
|
||||
public uint Version { get; set; }
|
||||
|
||||
public virtual IEnumerable<RefreshToken> RefreshTokens { get; set; } = new List<RefreshToken>();
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace TimetableDesigner.Backend.Services.Authentication.Database.Model;
|
||||
|
||||
public class RefreshToken
|
||||
{
|
||||
public Guid Token { get; set; }
|
||||
public long AccountId { get; set; }
|
||||
public DateTimeOffset ExpirationDate { get; set; }
|
||||
public bool IsExtendable { get; set; }
|
||||
public uint Version { get; set; }
|
||||
|
||||
public virtual Account Account { get; set; } = null!;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user