diff --git a/BeReadyBackend/BeReadyBackend.csproj b/BeReadyBackend/BeReadyBackend.csproj index bc6fe49..3b6044a 100644 --- a/BeReadyBackend/BeReadyBackend.csproj +++ b/BeReadyBackend/BeReadyBackend.csproj @@ -30,7 +30,6 @@ - diff --git a/BeReadyBackend/Migrations/20260221161039_EditedDesignationFieldInUserEntity.Designer.cs b/BeReadyBackend/Migrations/20260221161039_EditedDesignationFieldInUserEntity.Designer.cs new file mode 100644 index 0000000..bef6e15 --- /dev/null +++ b/BeReadyBackend/Migrations/20260221161039_EditedDesignationFieldInUserEntity.Designer.cs @@ -0,0 +1,440 @@ +// +using System; +using BeReadyBackend; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace BeReadyBackend.Migrations +{ + [DbContext(typeof(BeReadyDbContext))] + [Migration("20260221161039_EditedDesignationFieldInUserEntity")] + partial class EditedDesignationFieldInUserEntity + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.20") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("BeReadyBackend.Models.Achievement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Label") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Achievements"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.Designation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Label") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Designations"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.Group", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Duration") + .HasColumnType("int"); + + b.Property("IsFinished") + .HasColumnType("bit"); + + b.Property("Label") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("Title") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.Message", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("GroupId") + .HasColumnType("int"); + + b.Property("Libelle") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SendDate") + .HasColumnType("datetime2"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.HasIndex("UserId"); + + b.ToTable("Messages"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.RandomChallenge", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Duration") + .HasColumnType("int"); + + b.Property("IsAlreadyPast") + .HasColumnType("bit"); + + b.Property("Libelle") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("RandomChallenges"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreationDate") + .HasColumnType("datetime2"); + + b.Property("DesignationId") + .HasColumnType("int"); + + b.Property("Email") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("nvarchar(100)"); + + b.Property("FirstName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.Property("Password") + .IsRequired() + .HasMaxLength(60) + .HasColumnType("nvarchar(60)"); + + b.Property("Salt") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Score") + .HasColumnType("int"); + + b.Property("Series") + .HasColumnType("int"); + + b.Property("TotalBonusChallenge") + .HasColumnType("int"); + + b.Property("TotalChallenge") + .HasColumnType("int"); + + b.Property("TotalPodium") + .HasColumnType("int"); + + b.Property("TotalWin") + .HasColumnType("int"); + + b.Property("Username") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("nvarchar(50)"); + + b.HasKey("Id"); + + b.HasIndex("DesignationId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.UserAchievement", b => + { + b.Property("UserId") + .HasColumnType("int"); + + b.Property("AchievementId") + .HasColumnType("int"); + + b.HasKey("UserId", "AchievementId"); + + b.HasIndex("AchievementId"); + + b.ToTable("UserAchievements"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.UserFriend", b => + { + b.Property("UserId") + .HasColumnType("int"); + + b.Property("FriendId") + .HasColumnType("int"); + + b.Property("IsAccepted") + .HasColumnType("bit"); + + b.HasKey("UserId", "FriendId"); + + b.HasIndex("FriendId"); + + b.ToTable("UserFriends"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.UserGroup", b => + { + b.Property("UserId") + .HasColumnType("int"); + + b.Property("GroupId") + .HasColumnType("int"); + + b.Property("Grade") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Proof") + .HasColumnType("nvarchar(max)"); + + b.Property("Score") + .HasColumnType("int"); + + b.Property("VotedProofId") + .HasColumnType("int"); + + b.HasKey("UserId", "GroupId"); + + b.HasIndex("GroupId"); + + b.ToTable("UserGroups"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.UserRandomChallenge", b => + { + b.Property("UserId") + .HasColumnType("int"); + + b.Property("RandomChallengeId") + .HasColumnType("int"); + + b.Property("Proof") + .HasColumnType("nvarchar(max)"); + + b.HasKey("UserId", "RandomChallengeId"); + + b.HasIndex("RandomChallengeId"); + + b.ToTable("UserRandomChallenges"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.Message", b => + { + b.HasOne("BeReadyBackend.Models.Group", "Group") + .WithMany("Messages") + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BeReadyBackend.Models.User", "User") + .WithMany("Messages") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.User", b => + { + b.HasOne("BeReadyBackend.Models.Designation", "Designation") + .WithMany("Users") + .HasForeignKey("DesignationId"); + + b.Navigation("Designation"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.UserAchievement", b => + { + b.HasOne("BeReadyBackend.Models.Achievement", "Achievement") + .WithMany("UserAchievements") + .HasForeignKey("AchievementId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BeReadyBackend.Models.User", "User") + .WithMany("UserAchievements") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Achievement"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.UserFriend", b => + { + b.HasOne("BeReadyBackend.Models.User", "Friend") + .WithMany() + .HasForeignKey("FriendId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.HasOne("BeReadyBackend.Models.User", "User") + .WithMany("UserFriends") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Friend"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.UserGroup", b => + { + b.HasOne("BeReadyBackend.Models.Group", "Group") + .WithMany() + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BeReadyBackend.Models.User", "User") + .WithMany("UserGroups") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Group"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.UserRandomChallenge", b => + { + b.HasOne("BeReadyBackend.Models.RandomChallenge", "RandomChallenge") + .WithMany("UserRandomChallenges") + .HasForeignKey("RandomChallengeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("BeReadyBackend.Models.User", "User") + .WithMany("UserRandomChallenges") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("RandomChallenge"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.Achievement", b => + { + b.Navigation("UserAchievements"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.Designation", b => + { + b.Navigation("Users"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.Group", b => + { + b.Navigation("Messages"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.RandomChallenge", b => + { + b.Navigation("UserRandomChallenges"); + }); + + modelBuilder.Entity("BeReadyBackend.Models.User", b => + { + b.Navigation("Messages"); + + b.Navigation("UserAchievements"); + + b.Navigation("UserFriends"); + + b.Navigation("UserGroups"); + + b.Navigation("UserRandomChallenges"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/BeReadyBackend/Migrations/20260221161039_EditedDesignationFieldInUserEntity.cs b/BeReadyBackend/Migrations/20260221161039_EditedDesignationFieldInUserEntity.cs new file mode 100644 index 0000000..a73221a --- /dev/null +++ b/BeReadyBackend/Migrations/20260221161039_EditedDesignationFieldInUserEntity.cs @@ -0,0 +1,59 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BeReadyBackend.Migrations +{ + /// + public partial class EditedDesignationFieldInUserEntity : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Users_Designations_DesignationId", + table: "Users"); + + migrationBuilder.AlterColumn( + name: "DesignationId", + table: "Users", + type: "int", + nullable: true, + oldClrType: typeof(int), + oldType: "int"); + + migrationBuilder.AddForeignKey( + name: "FK_Users_Designations_DesignationId", + table: "Users", + column: "DesignationId", + principalTable: "Designations", + principalColumn: "Id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Users_Designations_DesignationId", + table: "Users"); + + migrationBuilder.AlterColumn( + name: "DesignationId", + table: "Users", + type: "int", + nullable: false, + defaultValue: 0, + oldClrType: typeof(int), + oldType: "int", + oldNullable: true); + + migrationBuilder.AddForeignKey( + name: "FK_Users_Designations_DesignationId", + table: "Users", + column: "DesignationId", + principalTable: "Designations", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/BeReadyBackend/Migrations/BeReadyDbContextModelSnapshot.cs b/BeReadyBackend/Migrations/BeReadyDbContextModelSnapshot.cs index 54e4c5e..b5b98c0 100644 --- a/BeReadyBackend/Migrations/BeReadyDbContextModelSnapshot.cs +++ b/BeReadyBackend/Migrations/BeReadyDbContextModelSnapshot.cs @@ -159,7 +159,7 @@ namespace BeReadyBackend.Migrations b.Property("CreationDate") .HasColumnType("datetime2"); - b.Property("DesignationId") + b.Property("DesignationId") .HasColumnType("int"); b.Property("Email") @@ -318,9 +318,7 @@ namespace BeReadyBackend.Migrations { b.HasOne("BeReadyBackend.Models.Designation", "Designation") .WithMany("Users") - .HasForeignKey("DesignationId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("DesignationId"); b.Navigation("Designation"); }); diff --git a/BeReadyBackend/Models/User.cs b/BeReadyBackend/Models/User.cs index 0e74ff8..7652f98 100644 --- a/BeReadyBackend/Models/User.cs +++ b/BeReadyBackend/Models/User.cs @@ -20,7 +20,7 @@ public class User [Required] public int Series { get; set; } public Designation? Designation { get; set; } - [Required] public int DesignationId { get; set; } + public int? DesignationId { get; set; } public List? UserFriends { get; set; } public List? Messages { get; set; }