feat: add Data Transfer Objects for user & scoreboard record

This commit is contained in:
cuqmbr 2022-07-17 14:31:40 +03:00
parent 4adf64d129
commit c8bc5f2989
9 changed files with 160 additions and 16 deletions

View 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!;
}

View File

@ -0,0 +1,8 @@
namespace DatabaseModels.DataTransferObjets;
public class UserDto
{
public int Id { get; set; }
public string Username { get; set; } = null!;
}

View File

@ -6,8 +6,4 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="DTO" />
</ItemGroup>
</Project>

View 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() };
}

View File

@ -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 };
}

View File

@ -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; }
}

View 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
}
}
}

View 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");
}
}
}

View File

@ -53,6 +53,10 @@ namespace Server.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Role")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasColumnType("TEXT");