From c674703428dde23d8d0387ae8b1a385887331319 Mon Sep 17 00:00:00 2001 From: maxime Date: Sat, 17 Feb 2024 17:41:03 +0100 Subject: [PATCH] fix users administration panel --- API/Controllers/AccountsController.cs | 80 ++++-- DbServices/DbUserService.cs | 12 + Services/UserService.cs | 3 + .../Migrations/20240221223713_m3.Designer.cs | 268 ++++++++++++++++++ StubContext/Migrations/20240221223713_m3.cs | 176 ++++++++++++ .../Migrations/20240306225043_m8.Designer.cs | 265 +++++++++++++++++ StubContext/Migrations/20240306225043_m8.cs | 99 +++++++ 7 files changed, 880 insertions(+), 23 deletions(-) create mode 100644 StubContext/Migrations/20240221223713_m3.Designer.cs create mode 100644 StubContext/Migrations/20240221223713_m3.cs create mode 100644 StubContext/Migrations/20240306225043_m8.Designer.cs create mode 100644 StubContext/Migrations/20240306225043_m8.cs diff --git a/API/Controllers/AccountsController.cs b/API/Controllers/AccountsController.cs index e8f30af..60db85c 100644 --- a/API/Controllers/AccountsController.cs +++ b/API/Controllers/AccountsController.cs @@ -10,8 +10,32 @@ public class AccountsController(IUserService service) : ControllerBase { private const string DefaultProfilePicture = "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png"; + + public record CountUsersResponse(int Value); + + + [HttpGet("/admin/users/count&search={search}")] + public async Task CountUsers( + [MaxLength(256, ErrorMessage = "Search string is too wide")] + string search + ) + { + return new CountUsersResponse(await service.UsersCount(search)); + } - [HttpGet("/admin/list-users")] + [HttpGet("/admin/users/count")] + public async Task CountUsers() + { + return new CountUsersResponse(await service.UsersCount()); + } + + // [HttpGet("/admin/users/count")] + // public async Task CountUsers() + // { + // return new CountUsersResponse(await service.UsersCount()); + // } + + [HttpGet("/admin/users")] public async Task> ListUsers( [Range(0, int.MaxValue, ErrorMessage = "Only positive number allowed")] int start, @@ -21,14 +45,14 @@ public class AccountsController(IUserService service) : ControllerBase string? search ) { - var result = search == null - ? await service.ListUsers(search!) + var result = search != null + ? await service.ListUsers(search) : await service.ListUsers(); return result.Skip(start).Take(n); } - [HttpGet("/admin/user/{id:int}")] + [HttpGet("/admin/users/{id:int}")] public async Task GetUser( [Range(0, int.MaxValue, ErrorMessage = "Only positive number allowed")] int id @@ -41,39 +65,49 @@ public class AccountsController(IUserService service) : ControllerBase return Ok(result); } - [HttpPost("/admin/user")] - public Task AddUser( + public record AddUserRequest( [MaxLength(256, ErrorMessage = "Username is too wide")] - string username, + string Username, [Range(4, 256, ErrorMessage = "Password must length be between 4 and 256")] - string password, - [MaxLength(256, ErrorMessage = "Email is too wide")] [EmailAddress] - string email, - bool isAdmin = false - ) + string Password, + [MaxLength(256, ErrorMessage = "Email is too wide")] + [EmailAddress] + string Email, + bool IsAdmin = false + ); + + [HttpPost("/admin/users")] + public Task AddUser([FromBody] AddUserRequest req) { - return service.CreateUser(username, email, password, DefaultProfilePicture, isAdmin); + return service.CreateUser(req.Username, req.Email, req.Password, DefaultProfilePicture, req.IsAdmin); } - [HttpDelete("/admin/user")] - public async void RemoveUsers(int[] identifiers) + public record RemoveUsersRequest(int[] Identifiers); + + [HttpPost("/admin/users/remove-all")] + public async void RemoveUsers([FromBody] RemoveUsersRequest req) { - await service.RemoveUsers(identifiers); + await service.RemoveUsers(req.Identifiers); } - [HttpPut("/admin/user/{id:int}")] + public record UpdateUserRequest( + [MaxLength(256, ErrorMessage = "Username is too wide")] + string Username, + [MaxLength(256, ErrorMessage = "Email is too wide")] + [EmailAddress] + string Email, + bool IsAdmin + ); + + [HttpPut("/admin/users/{id:int}")] public async Task UpdateUser( int id, - [MaxLength(256, ErrorMessage = "Username is too wide")] - string username, - [MaxLength(256, ErrorMessage = "Email is too wide")] [EmailAddress] - string email, - bool isAdmin + [FromBody] UpdateUserRequest req ) { try { - await service.UpdateUser(new User(id, username, email, DefaultProfilePicture, isAdmin)); + await service.UpdateUser(new User(id, req.Username, req.Email, DefaultProfilePicture, req.IsAdmin)); return Ok(); } catch (ServiceException e) diff --git a/DbServices/DbUserService.cs b/DbServices/DbUserService.cs index 1471391..83aa821 100644 --- a/DbServices/DbUserService.cs +++ b/DbServices/DbUserService.cs @@ -10,6 +10,16 @@ namespace DbServices; public class DbUserService(AppContext.AppContext context) : IUserService { + public Task UsersCount(string nameNeedle) + { + return context.Users.CountAsync(u => u.Name.ToLower().Contains(nameNeedle.ToLower())); + } + + public Task UsersCount() + { + return context.Users.CountAsync(); + } + public Task> ListUsers(string nameNeedle) { return Task.FromResult( @@ -72,6 +82,8 @@ public class DbUserService(AppContext.AppContext context) : IUserService entity.Name = user.Name; entity.Email = user.Email; entity.Id = user.Id; + entity.IsAdmin = user.IsAdmin; + await context.SaveChangesAsync(); } diff --git a/Services/UserService.cs b/Services/UserService.cs index 836d6a8..4e67597 100644 --- a/Services/UserService.cs +++ b/Services/UserService.cs @@ -5,6 +5,9 @@ namespace Services; public interface IUserService { + Task UsersCount(string nameNeedle); + Task UsersCount(); + Task> ListUsers(string nameNeedle); Task> ListUsers(); diff --git a/StubContext/Migrations/20240221223713_m3.Designer.cs b/StubContext/Migrations/20240221223713_m3.Designer.cs new file mode 100644 index 0000000..fbb81e9 --- /dev/null +++ b/StubContext/Migrations/20240221223713_m3.Designer.cs @@ -0,0 +1,268 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubContext; + +#nullable disable + +namespace StubContext.Migrations +{ + [DbContext(typeof(StubAppContext))] + [Migration("20240221223713_m3")] + partial class m3 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.0"); + + modelBuilder.Entity("AppContext.Entities.MemberEntity", b => + { + b.Property("TeamId") + .HasColumnType("INTEGER"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("Role") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("TeamId", "UserId"); + + b.HasIndex("UserId"); + + b.ToTable("Members"); + }); + + modelBuilder.Entity("AppContext.Entities.TacticEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationDate") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("OwnerId") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("Tactics"); + }); + + modelBuilder.Entity("AppContext.Entities.TacticStepEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("JsonContent") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ParentId") + .HasColumnType("INTEGER"); + + b.Property("StepId") + .HasColumnType("INTEGER"); + + b.Property("TacticId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.HasIndex("TacticId"); + + b.ToTable("TacticSteps"); + }); + + modelBuilder.Entity("AppContext.Entities.TeamEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MainColor") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Picture") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SecondColor") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Teams"); + }); + + modelBuilder.Entity("AppContext.Entities.UserEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Email") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IsAdmin") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ProfilePicture") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Salt") + .IsRequired() + .HasColumnType("BLOB"); + + b.HasKey("Id"); + + b.ToTable("Users"); + + b.HasData( + new + { + Id = 1, + Email = "maxime@mail.com", + IsAdmin = true, + Name = "maxime", + Password = "MA/xRuayPtWrv8x3Cgz5OzmlHs/d2kdqpsejjELTgVo=", + ProfilePicture = "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", + Salt = new byte[] { 150, 122, 99, 167, 226, 248, 165, 213, 13, 3, 4, 9, 173, 71, 224, 221, 124, 172, 97, 145, 188, 142, 224, 77, 247, 77, 124, 37, 24, 107, 43, 189 } + }, + new + { + Id = 2, + Email = "mael@mail.com", + IsAdmin = true, + Name = "mael", + Password = "d4SIGx08pW4fFOFycWyscF9MwGhN5/1b0NC1Qk23YCw=", + ProfilePicture = "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", + Salt = new byte[] { 139, 244, 180, 246, 0, 73, 0, 219, 14, 221, 232, 49, 46, 122, 94, 50, 119, 154, 154, 53, 224, 187, 86, 230, 63, 73, 65, 232, 218, 136, 75, 142 } + }, + new + { + Id = 3, + Email = "yanis@mail.com", + IsAdmin = true, + Name = "yanis", + Password = "rtqwioPIa+g4C7hlsJMynrxVjUYw1V09z21bA6nBORM=", + ProfilePicture = "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", + Salt = new byte[] { 154, 78, 98, 162, 75, 166, 161, 47, 28, 160, 107, 245, 28, 33, 244, 213, 64, 247, 249, 28, 216, 58, 63, 44, 71, 179, 227, 67, 81, 146, 81, 87 } + }, + new + { + Id = 4, + Email = "simon@mail.com", + IsAdmin = true, + Name = "simon", + Password = "RWebQFKoA5GHSVibfFwKJ+YrgliWiCjzHmDCQYA6h9Y=", + ProfilePicture = "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", + Salt = new byte[] { 151, 193, 143, 48, 112, 90, 1, 91, 205, 85, 248, 129, 36, 50, 255, 5, 247, 95, 2, 156, 141, 189, 98, 4, 223, 179, 132, 19, 109, 43, 75, 43 } + }, + new + { + Id = 5, + Email = "vivien@mail.com", + IsAdmin = true, + Name = "vivien", + Password = "aduT6b63cL7GYh6qX1VdL0YvQIDz7uXxwnqrM9SSzzU=", + ProfilePicture = "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", + Salt = new byte[] { 163, 203, 253, 50, 184, 48, 93, 231, 249, 199, 182, 214, 40, 190, 70, 79, 53, 18, 26, 151, 57, 183, 166, 150, 179, 165, 48, 68, 12, 31, 129, 242 } + }); + }); + + modelBuilder.Entity("AppContext.Entities.MemberEntity", b => + { + b.HasOne("AppContext.Entities.TeamEntity", "Team") + .WithMany("Members") + .HasForeignKey("TeamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AppContext.Entities.UserEntity", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Team"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("AppContext.Entities.TacticEntity", b => + { + b.HasOne("AppContext.Entities.UserEntity", "Owner") + .WithMany("Tactics") + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("AppContext.Entities.TacticStepEntity", b => + { + b.HasOne("AppContext.Entities.TacticStepEntity", "Parent") + .WithMany() + .HasForeignKey("ParentId"); + + b.HasOne("AppContext.Entities.TacticEntity", "Tactic") + .WithMany() + .HasForeignKey("TacticId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Parent"); + + b.Navigation("Tactic"); + }); + + modelBuilder.Entity("AppContext.Entities.TeamEntity", b => + { + b.Navigation("Members"); + }); + + modelBuilder.Entity("AppContext.Entities.UserEntity", b => + { + b.Navigation("Tactics"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/StubContext/Migrations/20240221223713_m3.cs b/StubContext/Migrations/20240221223713_m3.cs new file mode 100644 index 0000000..09e1933 --- /dev/null +++ b/StubContext/Migrations/20240221223713_m3.cs @@ -0,0 +1,176 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace StubContext.Migrations +{ + /// + public partial class m3 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Teams", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + Picture = table.Column(type: "TEXT", nullable: false), + MainColor = table.Column(type: "TEXT", nullable: false), + SecondColor = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Teams", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Password = table.Column(type: "TEXT", nullable: false), + Salt = table.Column(type: "BLOB", nullable: false), + Name = table.Column(type: "TEXT", nullable: false), + Email = table.Column(type: "TEXT", nullable: false), + ProfilePicture = table.Column(type: "TEXT", nullable: false), + IsAdmin = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Members", + columns: table => new + { + TeamId = table.Column(type: "INTEGER", nullable: false), + UserId = table.Column(type: "INTEGER", nullable: false), + Role = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Members", x => new { x.TeamId, x.UserId }); + table.ForeignKey( + name: "FK_Members_Teams_TeamId", + column: x => x.TeamId, + principalTable: "Teams", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Members_Users_UserId", + column: x => x.UserId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Tactics", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: false), + CreationDate = table.Column(type: "TEXT", nullable: false), + OwnerId = table.Column(type: "INTEGER", nullable: false), + Type = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Tactics", x => x.Id); + table.ForeignKey( + name: "FK_Tactics_Users_OwnerId", + column: x => x.OwnerId, + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "TacticSteps", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + TacticId = table.Column(type: "INTEGER", nullable: false), + ParentId = table.Column(type: "INTEGER", nullable: true), + StepId = table.Column(type: "INTEGER", nullable: false), + JsonContent = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TacticSteps", x => x.Id); + table.ForeignKey( + name: "FK_TacticSteps_TacticSteps_ParentId", + column: x => x.ParentId, + principalTable: "TacticSteps", + principalColumn: "Id"); + table.ForeignKey( + name: "FK_TacticSteps_Tactics_TacticId", + column: x => x.TacticId, + principalTable: "Tactics", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.InsertData( + table: "Users", + columns: new[] { "Id", "Email", "IsAdmin", "Name", "Password", "ProfilePicture", "Salt" }, + values: new object[,] + { + { 1, "maxime@mail.com", true, "maxime", "MA/xRuayPtWrv8x3Cgz5OzmlHs/d2kdqpsejjELTgVo=", "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", new byte[] { 150, 122, 99, 167, 226, 248, 165, 213, 13, 3, 4, 9, 173, 71, 224, 221, 124, 172, 97, 145, 188, 142, 224, 77, 247, 77, 124, 37, 24, 107, 43, 189 } }, + { 2, "mael@mail.com", true, "mael", "d4SIGx08pW4fFOFycWyscF9MwGhN5/1b0NC1Qk23YCw=", "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", new byte[] { 139, 244, 180, 246, 0, 73, 0, 219, 14, 221, 232, 49, 46, 122, 94, 50, 119, 154, 154, 53, 224, 187, 86, 230, 63, 73, 65, 232, 218, 136, 75, 142 } }, + { 3, "yanis@mail.com", true, "yanis", "rtqwioPIa+g4C7hlsJMynrxVjUYw1V09z21bA6nBORM=", "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", new byte[] { 154, 78, 98, 162, 75, 166, 161, 47, 28, 160, 107, 245, 28, 33, 244, 213, 64, 247, 249, 28, 216, 58, 63, 44, 71, 179, 227, 67, 81, 146, 81, 87 } }, + { 4, "simon@mail.com", true, "simon", "RWebQFKoA5GHSVibfFwKJ+YrgliWiCjzHmDCQYA6h9Y=", "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", new byte[] { 151, 193, 143, 48, 112, 90, 1, 91, 205, 85, 248, 129, 36, 50, 255, 5, 247, 95, 2, 156, 141, 189, 98, 4, 223, 179, 132, 19, 109, 43, 75, 43 } }, + { 5, "vivien@mail.com", true, "vivien", "aduT6b63cL7GYh6qX1VdL0YvQIDz7uXxwnqrM9SSzzU=", "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", new byte[] { 163, 203, 253, 50, 184, 48, 93, 231, 249, 199, 182, 214, 40, 190, 70, 79, 53, 18, 26, 151, 57, 183, 166, 150, 179, 165, 48, 68, 12, 31, 129, 242 } } + }); + + migrationBuilder.CreateIndex( + name: "IX_Members_UserId", + table: "Members", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_Tactics_OwnerId", + table: "Tactics", + column: "OwnerId"); + + migrationBuilder.CreateIndex( + name: "IX_TacticSteps_ParentId", + table: "TacticSteps", + column: "ParentId"); + + migrationBuilder.CreateIndex( + name: "IX_TacticSteps_TacticId", + table: "TacticSteps", + column: "TacticId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Members"); + + migrationBuilder.DropTable( + name: "TacticSteps"); + + migrationBuilder.DropTable( + name: "Teams"); + + migrationBuilder.DropTable( + name: "Tactics"); + + migrationBuilder.DropTable( + name: "Users"); + } + } +} diff --git a/StubContext/Migrations/20240306225043_m8.Designer.cs b/StubContext/Migrations/20240306225043_m8.Designer.cs new file mode 100644 index 0000000..b3fd8a1 --- /dev/null +++ b/StubContext/Migrations/20240306225043_m8.Designer.cs @@ -0,0 +1,265 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using StubContext; + +#nullable disable + +namespace StubContext.Migrations +{ + [DbContext(typeof(StubAppContext))] + [Migration("20240306225043_m8")] + partial class m8 + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.0"); + + modelBuilder.Entity("AppContext.Entities.MemberEntity", b => + { + b.Property("TeamId") + .HasColumnType("INTEGER"); + + b.Property("UserId") + .HasColumnType("INTEGER"); + + b.Property("Role") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("TeamId", "UserId"); + + b.HasIndex("UserId"); + + b.ToTable("Members"); + }); + + modelBuilder.Entity("AppContext.Entities.TacticEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("CreationDate") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("OwnerId") + .HasColumnType("INTEGER"); + + b.Property("Type") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("Tactics"); + }); + + modelBuilder.Entity("AppContext.Entities.TacticStepEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("JsonContent") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ParentId") + .HasColumnType("INTEGER"); + + b.Property("TacticId") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.HasIndex("TacticId"); + + b.ToTable("TacticSteps"); + }); + + modelBuilder.Entity("AppContext.Entities.TeamEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("MainColor") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Picture") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("SecondColor") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Teams"); + }); + + modelBuilder.Entity("AppContext.Entities.UserEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Email") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("IsAdmin") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Password") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ProfilePicture") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Salt") + .IsRequired() + .HasColumnType("BLOB"); + + b.HasKey("Id"); + + b.ToTable("Users"); + + b.HasData( + new + { + Id = 1, + Email = "maxime@mail.com", + IsAdmin = true, + Name = "maxime", + Password = "cs6sYeniFuGPCc9vpIqfT55QoM81UQmQfCXj5Zs7ntQ=", + ProfilePicture = "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", + Salt = new byte[] { 219, 58, 14, 214, 249, 185, 223, 243, 156, 162, 179, 40, 110, 116, 140, 235, 236, 189, 8, 126, 125, 98, 211, 121, 18, 143, 101, 72, 246, 167, 190, 180 } + }, + new + { + Id = 2, + Email = "mael@mail.com", + IsAdmin = true, + Name = "mael", + Password = "7KlgzhGDNvmU0U6XrLxn2yByXS3cH/zGhMdp7YfEB0I=", + ProfilePicture = "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", + Salt = new byte[] { 66, 149, 79, 107, 102, 133, 242, 64, 186, 228, 147, 19, 180, 220, 44, 136, 109, 113, 7, 105, 119, 124, 2, 143, 144, 210, 152, 190, 218, 198, 212, 20 } + }, + new + { + Id = 3, + Email = "yanis@mail.com", + IsAdmin = true, + Name = "yanis", + Password = "c4WNJmzdK+W2yobGFAHCoi4U9LIocZAprxD+CZYYH/U=", + ProfilePicture = "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", + Salt = new byte[] { 47, 0, 22, 126, 22, 151, 17, 116, 14, 185, 249, 205, 99, 227, 162, 199, 72, 196, 162, 149, 10, 80, 231, 77, 30, 156, 105, 208, 60, 50, 195, 10 } + }, + new + { + Id = 4, + Email = "simon@mail.com", + IsAdmin = true, + Name = "simon", + Password = "x/mFMIqJPOIOUQLPtWykgx5h+cr+CQCuPqRKaEat170=", + ProfilePicture = "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", + Salt = new byte[] { 125, 255, 139, 144, 133, 136, 63, 202, 189, 150, 61, 176, 48, 173, 95, 132, 57, 67, 19, 8, 183, 136, 252, 180, 167, 4, 159, 181, 191, 232, 116, 10 } + }, + new + { + Id = 5, + Email = "vivien@mail.com", + IsAdmin = true, + Name = "vivien", + Password = "WO9P7aYnSHFe6YZkhiaJhPNHsP4Kj/PdtHmFlGJ7Tog=", + ProfilePicture = "https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_960_720.png", + Salt = new byte[] { 182, 6, 140, 209, 134, 112, 40, 156, 196, 122, 95, 6, 97, 90, 172, 94, 224, 61, 31, 137, 148, 37, 128, 243, 66, 82, 115, 218, 53, 14, 144, 13 } + }); + }); + + modelBuilder.Entity("AppContext.Entities.MemberEntity", b => + { + b.HasOne("AppContext.Entities.TeamEntity", "Team") + .WithMany("Members") + .HasForeignKey("TeamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("AppContext.Entities.UserEntity", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Team"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("AppContext.Entities.TacticEntity", b => + { + b.HasOne("AppContext.Entities.UserEntity", "Owner") + .WithMany("Tactics") + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Owner"); + }); + + modelBuilder.Entity("AppContext.Entities.TacticStepEntity", b => + { + b.HasOne("AppContext.Entities.TacticStepEntity", "Parent") + .WithMany() + .HasForeignKey("ParentId"); + + b.HasOne("AppContext.Entities.TacticEntity", "Tactic") + .WithMany() + .HasForeignKey("TacticId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Parent"); + + b.Navigation("Tactic"); + }); + + modelBuilder.Entity("AppContext.Entities.TeamEntity", b => + { + b.Navigation("Members"); + }); + + modelBuilder.Entity("AppContext.Entities.UserEntity", b => + { + b.Navigation("Tactics"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/StubContext/Migrations/20240306225043_m8.cs b/StubContext/Migrations/20240306225043_m8.cs new file mode 100644 index 0000000..8933ec9 --- /dev/null +++ b/StubContext/Migrations/20240306225043_m8.cs @@ -0,0 +1,99 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace StubContext.Migrations +{ + /// + public partial class m8 : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "StepId", + table: "TacticSteps"); + + migrationBuilder.UpdateData( + table: "Users", + keyColumn: "Id", + keyValue: 1, + columns: new[] { "Password", "Salt" }, + values: new object[] { "cs6sYeniFuGPCc9vpIqfT55QoM81UQmQfCXj5Zs7ntQ=", new byte[] { 219, 58, 14, 214, 249, 185, 223, 243, 156, 162, 179, 40, 110, 116, 140, 235, 236, 189, 8, 126, 125, 98, 211, 121, 18, 143, 101, 72, 246, 167, 190, 180 } }); + + migrationBuilder.UpdateData( + table: "Users", + keyColumn: "Id", + keyValue: 2, + columns: new[] { "Password", "Salt" }, + values: new object[] { "7KlgzhGDNvmU0U6XrLxn2yByXS3cH/zGhMdp7YfEB0I=", new byte[] { 66, 149, 79, 107, 102, 133, 242, 64, 186, 228, 147, 19, 180, 220, 44, 136, 109, 113, 7, 105, 119, 124, 2, 143, 144, 210, 152, 190, 218, 198, 212, 20 } }); + + migrationBuilder.UpdateData( + table: "Users", + keyColumn: "Id", + keyValue: 3, + columns: new[] { "Password", "Salt" }, + values: new object[] { "c4WNJmzdK+W2yobGFAHCoi4U9LIocZAprxD+CZYYH/U=", new byte[] { 47, 0, 22, 126, 22, 151, 17, 116, 14, 185, 249, 205, 99, 227, 162, 199, 72, 196, 162, 149, 10, 80, 231, 77, 30, 156, 105, 208, 60, 50, 195, 10 } }); + + migrationBuilder.UpdateData( + table: "Users", + keyColumn: "Id", + keyValue: 4, + columns: new[] { "Password", "Salt" }, + values: new object[] { "x/mFMIqJPOIOUQLPtWykgx5h+cr+CQCuPqRKaEat170=", new byte[] { 125, 255, 139, 144, 133, 136, 63, 202, 189, 150, 61, 176, 48, 173, 95, 132, 57, 67, 19, 8, 183, 136, 252, 180, 167, 4, 159, 181, 191, 232, 116, 10 } }); + + migrationBuilder.UpdateData( + table: "Users", + keyColumn: "Id", + keyValue: 5, + columns: new[] { "Password", "Salt" }, + values: new object[] { "WO9P7aYnSHFe6YZkhiaJhPNHsP4Kj/PdtHmFlGJ7Tog=", new byte[] { 182, 6, 140, 209, 134, 112, 40, 156, 196, 122, 95, 6, 97, 90, 172, 94, 224, 61, 31, 137, 148, 37, 128, 243, 66, 82, 115, 218, 53, 14, 144, 13 } }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "StepId", + table: "TacticSteps", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.UpdateData( + table: "Users", + keyColumn: "Id", + keyValue: 1, + columns: new[] { "Password", "Salt" }, + values: new object[] { "MA/xRuayPtWrv8x3Cgz5OzmlHs/d2kdqpsejjELTgVo=", new byte[] { 150, 122, 99, 167, 226, 248, 165, 213, 13, 3, 4, 9, 173, 71, 224, 221, 124, 172, 97, 145, 188, 142, 224, 77, 247, 77, 124, 37, 24, 107, 43, 189 } }); + + migrationBuilder.UpdateData( + table: "Users", + keyColumn: "Id", + keyValue: 2, + columns: new[] { "Password", "Salt" }, + values: new object[] { "d4SIGx08pW4fFOFycWyscF9MwGhN5/1b0NC1Qk23YCw=", new byte[] { 139, 244, 180, 246, 0, 73, 0, 219, 14, 221, 232, 49, 46, 122, 94, 50, 119, 154, 154, 53, 224, 187, 86, 230, 63, 73, 65, 232, 218, 136, 75, 142 } }); + + migrationBuilder.UpdateData( + table: "Users", + keyColumn: "Id", + keyValue: 3, + columns: new[] { "Password", "Salt" }, + values: new object[] { "rtqwioPIa+g4C7hlsJMynrxVjUYw1V09z21bA6nBORM=", new byte[] { 154, 78, 98, 162, 75, 166, 161, 47, 28, 160, 107, 245, 28, 33, 244, 213, 64, 247, 249, 28, 216, 58, 63, 44, 71, 179, 227, 67, 81, 146, 81, 87 } }); + + migrationBuilder.UpdateData( + table: "Users", + keyColumn: "Id", + keyValue: 4, + columns: new[] { "Password", "Salt" }, + values: new object[] { "RWebQFKoA5GHSVibfFwKJ+YrgliWiCjzHmDCQYA6h9Y=", new byte[] { 151, 193, 143, 48, 112, 90, 1, 91, 205, 85, 248, 129, 36, 50, 255, 5, 247, 95, 2, 156, 141, 189, 98, 4, 223, 179, 132, 19, 109, 43, 75, 43 } }); + + migrationBuilder.UpdateData( + table: "Users", + keyColumn: "Id", + keyValue: 5, + columns: new[] { "Password", "Salt" }, + values: new object[] { "aduT6b63cL7GYh6qX1VdL0YvQIDz7uXxwnqrM9SSzzU=", new byte[] { 163, 203, 253, 50, 184, 48, 93, 231, 249, 199, 182, 214, 40, 190, 70, 79, 53, 18, 26, 151, 57, 183, 166, 150, 179, 165, 48, 68, 12, 31, 129, 242 } }); + } + } +}