feat: add Data Transfer Objects for user & scoreboard record
This commit is contained in:
parent
4adf64d129
commit
c8bc5f2989
11
DatabaseModels/DataTransferObjets/ScoreboardRecordDto.cs
Normal file
11
DatabaseModels/DataTransferObjets/ScoreboardRecordDto.cs
Normal file
@ -0,0 +1,11 @@
|
||||
namespace DatabaseModels.DataTransferObjets;
|
||||
|
||||
public class ScoreboardRecordDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int Score { get; set; }
|
||||
public DateTime PostTime { get; set; }
|
||||
|
||||
public UserDto User { get; set; } = null!;
|
||||
}
|
8
DatabaseModels/DataTransferObjets/UserDto.cs
Normal file
8
DatabaseModels/DataTransferObjets/UserDto.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace DatabaseModels.DataTransferObjets;
|
||||
|
||||
public class UserDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Username { get; set; } = null!;
|
||||
}
|
@ -6,8 +6,4 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="DTO" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
15
DatabaseModels/InitialObjects/ScoreboardRecord.cs
Normal file
15
DatabaseModels/InitialObjects/ScoreboardRecord.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using DatabaseModels.DataTransferObjets;
|
||||
|
||||
namespace DatabaseModels.InitialObjects;
|
||||
|
||||
public class ScoreboardRecord
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int Score { get; set; }
|
||||
public DateTime PostTime { get; set; }
|
||||
|
||||
public User User { get; set; } = null!;
|
||||
|
||||
public ScoreboardRecordDto ToDto() => new() { Id = Id, Score = Score, PostTime = PostTime, User = User.ToDto() };
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
namespace DatabaseModels.Plain;
|
||||
using DatabaseModels.DataTransferObjets;
|
||||
|
||||
namespace DatabaseModels.InitialObjects;
|
||||
|
||||
public class User
|
||||
{
|
||||
@ -7,6 +9,10 @@ public class User
|
||||
public string Username { get; set; } = null!;
|
||||
public string PasswordHash { get; set; } = null!;
|
||||
public string PasswordSalt { get; set; } = null!;
|
||||
|
||||
public string Role { get; set; } = null!;
|
||||
|
||||
public ICollection<ScoreboardRecord> ScoreboardRecords { get; set; } = null!;
|
||||
|
||||
public UserDto ToDto() => new() { Id = Id, Username = Username };
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
namespace DatabaseModels.Plain;
|
||||
|
||||
public class ScoreboardRecord
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public int Score { get; set; }
|
||||
public DateTime PostTime { get; set; }
|
||||
|
||||
public User User { get; set; }
|
||||
}
|
89
Server/Migrations/20220717101814_AddUserRole.Designer.cs
generated
Normal file
89
Server/Migrations/20220717101814_AddUserRole.Designer.cs
generated
Normal file
@ -0,0 +1,89 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Server.Data;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Server.Migrations
|
||||
{
|
||||
[DbContext(typeof(ServerDbContext))]
|
||||
[Migration("20220717101814_AddUserRole")]
|
||||
partial class AddUserRole
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "6.0.6");
|
||||
|
||||
modelBuilder.Entity("DatabaseModels.Plain.ScoreboardRecord", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<DateTime>("PostTime")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<int>("Score")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("Scoreboard");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DatabaseModels.Plain.User", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b.Property<string>("PasswordHash")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("PasswordSalt")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Role")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DatabaseModels.Plain.ScoreboardRecord", b =>
|
||||
{
|
||||
b.HasOne("DatabaseModels.Plain.User", "User")
|
||||
.WithMany("ScoreboardRecords")
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("DatabaseModels.Plain.User", b =>
|
||||
{
|
||||
b.Navigation("ScoreboardRecords");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
26
Server/Migrations/20220717101814_AddUserRole.cs
Normal file
26
Server/Migrations/20220717101814_AddUserRole.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Server.Migrations
|
||||
{
|
||||
public partial class AddUserRole : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Role",
|
||||
table: "Users",
|
||||
type: "TEXT",
|
||||
nullable: false,
|
||||
defaultValue: "");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Role",
|
||||
table: "Users");
|
||||
}
|
||||
}
|
||||
}
|
@ -53,6 +53,10 @@ namespace Server.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Role")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("Username")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT");
|
||||
|
Loading…
Reference in New Issue
Block a user