From 53d4dadf68c712c18c499f72b6148ec0d759e422 Mon Sep 17 00:00:00 2001 From: tleodev Date: Fri, 7 Feb 2025 11:37:42 +0100 Subject: [PATCH] Training progs improuvemeent --- Infrastructure/Entities/Exercice.cs | 24 +- Infrastructure/Entities/Exercice_template.cs | 19 ++ Infrastructure/Entities/Session.cs | 11 +- Infrastructure/Entities/TrainingProgram.cs | 9 +- Infrastructure/Entities/User.cs | 2 +- .../20250110151624_Initialize.Designer.cs | 197 +++++++++++ .../Migrations/20250110151624_Initialize.cs | 125 +++++++ ...0207101932_TESTTrainingProgMig.Designer.cs | 247 ++++++++++++++ .../20250207101932_TESTTrainingProgMig.cs | 318 ++++++++++++++++++ .../OptifitDbContextModelSnapshot.cs | 244 ++++++++++++++ Infrastructure/Stub/StubbedContext.cs | 4 +- .../v1/ExercicesTemplateController.cs | 79 +++++ Server/IServices/IExerciceTemplateSercice.cs | 6 + Shared/ESportLevel.cs | 9 - Shared/Enums/ECategory.cs | 6 + Shared/Enums/EDay.cs | 6 + Shared/Enums/EDifficulty.cs | 6 + Shared/Enums/EGoal.cs | 6 + Shared/{ => Enums}/EHealthProblem.cs | 0 Shared/Enums/ELang.cs | 6 + Shared/{ => Enums}/ESleepLevel.cs | 0 Shared/{ => Enums}/ESport.cs | 0 Shared/Enums/ETarget.cs | 6 + 23 files changed, 1300 insertions(+), 30 deletions(-) create mode 100644 Infrastructure/Entities/Exercice_template.cs create mode 100644 Infrastructure/Migrations/20250110151624_Initialize.Designer.cs create mode 100644 Infrastructure/Migrations/20250110151624_Initialize.cs create mode 100644 Infrastructure/Migrations/20250207101932_TESTTrainingProgMig.Designer.cs create mode 100644 Infrastructure/Migrations/20250207101932_TESTTrainingProgMig.cs create mode 100644 Infrastructure/Migrations/OptifitDbContextModelSnapshot.cs create mode 100644 Server/Controller/v1/ExercicesTemplateController.cs create mode 100644 Server/IServices/IExerciceTemplateSercice.cs delete mode 100644 Shared/ESportLevel.cs create mode 100644 Shared/Enums/ECategory.cs create mode 100644 Shared/Enums/EDay.cs create mode 100644 Shared/Enums/EDifficulty.cs create mode 100644 Shared/Enums/EGoal.cs rename Shared/{ => Enums}/EHealthProblem.cs (100%) create mode 100644 Shared/Enums/ELang.cs rename Shared/{ => Enums}/ESleepLevel.cs (100%) rename Shared/{ => Enums}/ESport.cs (100%) create mode 100644 Shared/Enums/ETarget.cs diff --git a/Infrastructure/Entities/Exercice.cs b/Infrastructure/Entities/Exercice.cs index bfad362..24bd87e 100644 --- a/Infrastructure/Entities/Exercice.cs +++ b/Infrastructure/Entities/Exercice.cs @@ -1,22 +1,22 @@ using System.ComponentModel.DataAnnotations; using Infrastructure.Base; +using Shared; namespace Infrastructure.Entities; public class Exercice : EntityBase { [Required] - public string Name { get; set; } - - public string Description { get; set; } - - public float Duration { get; set; } + public string TemplateId { get; set; } + public Exercice_template Template { get; set; } - public string Image { get; set; } - - public string Video { get; set; } - - public int NbSeries { get; set; } - - public int NbRepetitions { get; set; } + public ECategory Category { get; set; } + public int NbSets { get; set; } + public int NbReps { get; set; } + public int RestingTime { get; set; } + + // Clé étrangère explicite vers Session + [Required] + public string SessionId { get; set; } + public Session Session { get; set; } } \ No newline at end of file diff --git a/Infrastructure/Entities/Exercice_template.cs b/Infrastructure/Entities/Exercice_template.cs new file mode 100644 index 0000000..57b9d45 --- /dev/null +++ b/Infrastructure/Entities/Exercice_template.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations; +using Infrastructure.Base; + +namespace Infrastructure.Entities; + +public class Exercice_template : EntityBase +{ + [Required] + public string Name { get; set; } + + public string Equipment { get; set; } + public string Instructions { get; set; } + + public float Duration { get; set; } + + public string? ImageId { get; set; } + + public string? VideoId { get; set; } +} \ No newline at end of file diff --git a/Infrastructure/Entities/Session.cs b/Infrastructure/Entities/Session.cs index a17cf14..f315084 100644 --- a/Infrastructure/Entities/Session.cs +++ b/Infrastructure/Entities/Session.cs @@ -1,6 +1,7 @@ using System.Collections.ObjectModel; using System.ComponentModel.DataAnnotations; using Infrastructure.Base; +using Shared; namespace Infrastructure.Entities; @@ -8,10 +9,14 @@ public class Session : EntityBase { [Required] public string Name { get; set; } - public string Description { get; set; } - - public float Duration { get; set; } + public EDay Day { get; set; } + public ETarget Target { get; set; } + + // Clé étrangère explicite vers TrainingProgram + [Required] + public string TrainingProgramId { get; set; } + public TrainingProgram TrainingProgram { get; set; } public virtual ICollection Exercices { get; set; } = new Collection(); } \ No newline at end of file diff --git a/Infrastructure/Entities/TrainingProgram.cs b/Infrastructure/Entities/TrainingProgram.cs index 6df8f45..4de93d1 100644 --- a/Infrastructure/Entities/TrainingProgram.cs +++ b/Infrastructure/Entities/TrainingProgram.cs @@ -1,6 +1,7 @@ using System.Collections.ObjectModel; using System.ComponentModel.DataAnnotations; using Infrastructure.Base; +using Shared; namespace Infrastructure.Entities; @@ -8,12 +9,14 @@ public class TrainingProgram : EntityBase { [Required] public string Name { get; set; } + + public ELang Lang { get; set; } public int WeekDuration { get; set; } + public string OwnerId { get; set; } + public EGoal Goal { get; set; } - public string Description { get; set; } - - public string Difficulty { get; set; } + public EDifficulty Difficulty { get; set; } public virtual ICollection Sessions { get; set; } = new Collection(); } \ No newline at end of file diff --git a/Infrastructure/Entities/User.cs b/Infrastructure/Entities/User.cs index 8f52c97..e9654f0 100644 --- a/Infrastructure/Entities/User.cs +++ b/Infrastructure/Entities/User.cs @@ -26,7 +26,7 @@ public class User : EntityBase public EHealthProblem EHealthProblem { get; set; } public ESport? ESport { get; set; } public ESleepLevel? ESleepLevel { get; set; } - public ESportLevel? ESportLevel { get; set; } + public EDifficulty? ESportLevel { get; set; } public string HashPassword { get; set; } public string? OAuthProvider { get; set; } diff --git a/Infrastructure/Migrations/20250110151624_Initialize.Designer.cs b/Infrastructure/Migrations/20250110151624_Initialize.Designer.cs new file mode 100644 index 0000000..6fe4bb4 --- /dev/null +++ b/Infrastructure/Migrations/20250110151624_Initialize.Designer.cs @@ -0,0 +1,197 @@ +// +using Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Infrastructure.Migrations +{ + [DbContext(typeof(OptifitDbContext))] + [Migration("20250110151624_Initialize")] + partial class Initialize + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.1"); + + modelBuilder.Entity("Infrastructure.Entities.Exercice", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Duration") + .HasColumnType("REAL"); + + b.Property("Image") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NbRepetitions") + .HasColumnType("INTEGER"); + + b.Property("NbSeries") + .HasColumnType("INTEGER"); + + b.Property("SessionId") + .HasColumnType("TEXT"); + + b.Property("Video") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("SessionId"); + + b.ToTable("Exercices"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Session", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Duration") + .HasColumnType("REAL"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TrainingProgramId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("TrainingProgramId"); + + b.ToTable("Sessions"); + }); + + modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Difficulty") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("WeekDuration") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Programs"); + }); + + modelBuilder.Entity("Infrastructure.Entities.User", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Age") + .HasColumnType("INTEGER"); + + b.Property("EGoal") + .HasColumnType("TEXT"); + + b.Property("EHealthProblem") + .HasColumnType("INTEGER"); + + b.Property("ESleepLevel") + .HasColumnType("INTEGER"); + + b.Property("ESport") + .HasColumnType("INTEGER"); + + b.Property("ESportLevel") + .HasColumnType("INTEGER"); + + b.Property("HashPassword") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Height") + .HasColumnType("REAL"); + + b.Property("Logo") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NbSessionPerWeek") + .HasColumnType("INTEGER"); + + b.Property("OAuthId") + .HasColumnType("TEXT"); + + b.Property("OAuthProvider") + .HasColumnType("TEXT"); + + b.Property("Sexe") + .HasColumnType("INTEGER"); + + b.Property("Weight") + .HasColumnType("REAL"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Exercice", b => + { + b.HasOne("Infrastructure.Entities.Session", null) + .WithMany("Exercices") + .HasForeignKey("SessionId"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Session", b => + { + b.HasOne("Infrastructure.Entities.TrainingProgram", null) + .WithMany("Sessions") + .HasForeignKey("TrainingProgramId"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Session", b => + { + b.Navigation("Exercices"); + }); + + modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b => + { + b.Navigation("Sessions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Infrastructure/Migrations/20250110151624_Initialize.cs b/Infrastructure/Migrations/20250110151624_Initialize.cs new file mode 100644 index 0000000..103621f --- /dev/null +++ b/Infrastructure/Migrations/20250110151624_Initialize.cs @@ -0,0 +1,125 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Infrastructure.Migrations +{ + /// + public partial class Initialize : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Programs", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", nullable: false), + WeekDuration = table.Column(type: "INTEGER", nullable: false), + Description = table.Column(type: "TEXT", nullable: false), + Difficulty = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Programs", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Users", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", nullable: false), + Age = table.Column(type: "INTEGER", nullable: false), + Height = table.Column(type: "REAL", nullable: false), + Weight = table.Column(type: "REAL", nullable: false), + Sexe = table.Column(type: "INTEGER", nullable: false), + Logo = table.Column(type: "TEXT", nullable: false), + NbSessionPerWeek = table.Column(type: "INTEGER", nullable: false), + EGoal = table.Column(type: "TEXT", nullable: true), + EHealthProblem = table.Column(type: "INTEGER", nullable: false), + ESport = table.Column(type: "INTEGER", nullable: true), + ESleepLevel = table.Column(type: "INTEGER", nullable: true), + ESportLevel = table.Column(type: "INTEGER", nullable: true), + HashPassword = table.Column(type: "TEXT", nullable: false), + OAuthProvider = table.Column(type: "TEXT", nullable: true), + OAuthId = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Users", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Sessions", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: false), + Duration = table.Column(type: "REAL", nullable: false), + TrainingProgramId = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Sessions", x => x.Id); + table.ForeignKey( + name: "FK_Sessions_Programs_TrainingProgramId", + column: x => x.TrainingProgramId, + principalTable: "Programs", + principalColumn: "Id"); + }); + + migrationBuilder.CreateTable( + name: "Exercices", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", nullable: false), + Duration = table.Column(type: "REAL", nullable: false), + Image = table.Column(type: "TEXT", nullable: false), + Video = table.Column(type: "TEXT", nullable: false), + NbSeries = table.Column(type: "INTEGER", nullable: false), + NbRepetitions = table.Column(type: "INTEGER", nullable: false), + SessionId = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Exercices", x => x.Id); + table.ForeignKey( + name: "FK_Exercices_Sessions_SessionId", + column: x => x.SessionId, + principalTable: "Sessions", + principalColumn: "Id"); + }); + + migrationBuilder.CreateIndex( + name: "IX_Exercices_SessionId", + table: "Exercices", + column: "SessionId"); + + migrationBuilder.CreateIndex( + name: "IX_Sessions_TrainingProgramId", + table: "Sessions", + column: "TrainingProgramId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Exercices"); + + migrationBuilder.DropTable( + name: "Users"); + + migrationBuilder.DropTable( + name: "Sessions"); + + migrationBuilder.DropTable( + name: "Programs"); + } + } +} diff --git a/Infrastructure/Migrations/20250207101932_TESTTrainingProgMig.Designer.cs b/Infrastructure/Migrations/20250207101932_TESTTrainingProgMig.Designer.cs new file mode 100644 index 0000000..7d4fb96 --- /dev/null +++ b/Infrastructure/Migrations/20250207101932_TESTTrainingProgMig.Designer.cs @@ -0,0 +1,247 @@ +// +using Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Infrastructure.Migrations +{ + [DbContext(typeof(OptifitDbContext))] + [Migration("20250207101932_TESTTrainingProgMig")] + partial class TESTTrainingProgMig + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.1"); + + modelBuilder.Entity("Infrastructure.Entities.Exercice", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Category") + .HasColumnType("INTEGER"); + + b.Property("NbReps") + .HasColumnType("INTEGER"); + + b.Property("NbSets") + .HasColumnType("INTEGER"); + + b.Property("RestingTime") + .HasColumnType("INTEGER"); + + b.Property("SessionId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TemplateId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("SessionId"); + + b.HasIndex("TemplateId"); + + b.ToTable("Exercices"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Exercice_template", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Duration") + .HasColumnType("REAL"); + + b.Property("Equipment") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("TEXT"); + + b.Property("Instructions") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("VideoId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Exercice_template"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Session", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Day") + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Target") + .HasColumnType("INTEGER"); + + b.Property("TrainingProgramId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("TrainingProgramId"); + + b.ToTable("Sessions"); + }); + + modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Difficulty") + .HasColumnType("INTEGER"); + + b.Property("Goal") + .HasColumnType("INTEGER"); + + b.Property("Lang") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("OwnerId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("WeekDuration") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Programs"); + }); + + modelBuilder.Entity("Infrastructure.Entities.User", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Age") + .HasColumnType("INTEGER"); + + b.Property("EGoal") + .HasColumnType("TEXT"); + + b.Property("EHealthProblem") + .HasColumnType("INTEGER"); + + b.Property("ESleepLevel") + .HasColumnType("INTEGER"); + + b.Property("ESport") + .HasColumnType("INTEGER"); + + b.Property("ESportLevel") + .HasColumnType("INTEGER"); + + b.Property("HashPassword") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Height") + .HasColumnType("REAL"); + + b.Property("Logo") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NbSessionPerWeek") + .HasColumnType("INTEGER"); + + b.Property("OAuthId") + .HasColumnType("TEXT"); + + b.Property("OAuthProvider") + .HasColumnType("TEXT"); + + b.Property("Sexe") + .HasColumnType("INTEGER"); + + b.Property("Weight") + .HasColumnType("REAL"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Exercice", b => + { + b.HasOne("Infrastructure.Entities.Session", "Session") + .WithMany("Exercices") + .HasForeignKey("SessionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Infrastructure.Entities.Exercice_template", "Template") + .WithMany() + .HasForeignKey("TemplateId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Session"); + + b.Navigation("Template"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Session", b => + { + b.HasOne("Infrastructure.Entities.TrainingProgram", "TrainingProgram") + .WithMany("Sessions") + .HasForeignKey("TrainingProgramId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("TrainingProgram"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Session", b => + { + b.Navigation("Exercices"); + }); + + modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b => + { + b.Navigation("Sessions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Infrastructure/Migrations/20250207101932_TESTTrainingProgMig.cs b/Infrastructure/Migrations/20250207101932_TESTTrainingProgMig.cs new file mode 100644 index 0000000..8935af2 --- /dev/null +++ b/Infrastructure/Migrations/20250207101932_TESTTrainingProgMig.cs @@ -0,0 +1,318 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Infrastructure.Migrations +{ + /// + public partial class TESTTrainingProgMig : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Exercices_Sessions_SessionId", + table: "Exercices"); + + migrationBuilder.DropForeignKey( + name: "FK_Sessions_Programs_TrainingProgramId", + table: "Sessions"); + + migrationBuilder.DropColumn( + name: "Duration", + table: "Sessions"); + + migrationBuilder.DropColumn( + name: "Description", + table: "Exercices"); + + migrationBuilder.DropColumn( + name: "Duration", + table: "Exercices"); + + migrationBuilder.DropColumn( + name: "Image", + table: "Exercices"); + + migrationBuilder.DropColumn( + name: "Name", + table: "Exercices"); + + migrationBuilder.RenameColumn( + name: "Description", + table: "Programs", + newName: "OwnerId"); + + migrationBuilder.RenameColumn( + name: "Video", + table: "Exercices", + newName: "TemplateId"); + + migrationBuilder.RenameColumn( + name: "NbSeries", + table: "Exercices", + newName: "RestingTime"); + + migrationBuilder.RenameColumn( + name: "NbRepetitions", + table: "Exercices", + newName: "NbSets"); + + migrationBuilder.AlterColumn( + name: "TrainingProgramId", + table: "Sessions", + type: "TEXT", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AddColumn( + name: "Day", + table: "Sessions", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "Target", + table: "Sessions", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.AlterColumn( + name: "Difficulty", + table: "Programs", + type: "INTEGER", + nullable: false, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AddColumn( + name: "Goal", + table: "Programs", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "Lang", + table: "Programs", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.AlterColumn( + name: "SessionId", + table: "Exercices", + type: "TEXT", + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "TEXT", + oldNullable: true); + + migrationBuilder.AddColumn( + name: "Category", + table: "Exercices", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "NbReps", + table: "Exercices", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateTable( + name: "Exercice_template", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", nullable: false), + Equipment = table.Column(type: "TEXT", nullable: false), + Instructions = table.Column(type: "TEXT", nullable: false), + Duration = table.Column(type: "REAL", nullable: false), + ImageId = table.Column(type: "TEXT", nullable: true), + VideoId = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Exercice_template", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_Exercices_TemplateId", + table: "Exercices", + column: "TemplateId"); + + migrationBuilder.AddForeignKey( + name: "FK_Exercices_Exercice_template_TemplateId", + table: "Exercices", + column: "TemplateId", + principalTable: "Exercice_template", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Exercices_Sessions_SessionId", + table: "Exercices", + column: "SessionId", + principalTable: "Sessions", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_Sessions_Programs_TrainingProgramId", + table: "Sessions", + column: "TrainingProgramId", + principalTable: "Programs", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Exercices_Exercice_template_TemplateId", + table: "Exercices"); + + migrationBuilder.DropForeignKey( + name: "FK_Exercices_Sessions_SessionId", + table: "Exercices"); + + migrationBuilder.DropForeignKey( + name: "FK_Sessions_Programs_TrainingProgramId", + table: "Sessions"); + + migrationBuilder.DropTable( + name: "Exercice_template"); + + migrationBuilder.DropIndex( + name: "IX_Exercices_TemplateId", + table: "Exercices"); + + migrationBuilder.DropColumn( + name: "Day", + table: "Sessions"); + + migrationBuilder.DropColumn( + name: "Target", + table: "Sessions"); + + migrationBuilder.DropColumn( + name: "Goal", + table: "Programs"); + + migrationBuilder.DropColumn( + name: "Lang", + table: "Programs"); + + migrationBuilder.DropColumn( + name: "Category", + table: "Exercices"); + + migrationBuilder.DropColumn( + name: "NbReps", + table: "Exercices"); + + migrationBuilder.RenameColumn( + name: "OwnerId", + table: "Programs", + newName: "Description"); + + migrationBuilder.RenameColumn( + name: "TemplateId", + table: "Exercices", + newName: "Video"); + + migrationBuilder.RenameColumn( + name: "RestingTime", + table: "Exercices", + newName: "NbSeries"); + + migrationBuilder.RenameColumn( + name: "NbSets", + table: "Exercices", + newName: "NbRepetitions"); + + migrationBuilder.AlterColumn( + name: "TrainingProgramId", + table: "Sessions", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AddColumn( + name: "Duration", + table: "Sessions", + type: "REAL", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AlterColumn( + name: "Difficulty", + table: "Programs", + type: "TEXT", + nullable: false, + oldClrType: typeof(int), + oldType: "INTEGER"); + + migrationBuilder.AlterColumn( + name: "SessionId", + table: "Exercices", + type: "TEXT", + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT"); + + migrationBuilder.AddColumn( + name: "Description", + table: "Exercices", + type: "TEXT", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "Duration", + table: "Exercices", + type: "REAL", + nullable: false, + defaultValue: 0f); + + migrationBuilder.AddColumn( + name: "Image", + table: "Exercices", + type: "TEXT", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddColumn( + name: "Name", + table: "Exercices", + type: "TEXT", + nullable: false, + defaultValue: ""); + + migrationBuilder.AddForeignKey( + name: "FK_Exercices_Sessions_SessionId", + table: "Exercices", + column: "SessionId", + principalTable: "Sessions", + principalColumn: "Id"); + + migrationBuilder.AddForeignKey( + name: "FK_Sessions_Programs_TrainingProgramId", + table: "Sessions", + column: "TrainingProgramId", + principalTable: "Programs", + principalColumn: "Id"); + } + } +} diff --git a/Infrastructure/Migrations/OptifitDbContextModelSnapshot.cs b/Infrastructure/Migrations/OptifitDbContextModelSnapshot.cs new file mode 100644 index 0000000..e586b6c --- /dev/null +++ b/Infrastructure/Migrations/OptifitDbContextModelSnapshot.cs @@ -0,0 +1,244 @@ +// +using Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Infrastructure.Migrations +{ + [DbContext(typeof(OptifitDbContext))] + partial class OptifitDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "8.0.1"); + + modelBuilder.Entity("Infrastructure.Entities.Exercice", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Category") + .HasColumnType("INTEGER"); + + b.Property("NbReps") + .HasColumnType("INTEGER"); + + b.Property("NbSets") + .HasColumnType("INTEGER"); + + b.Property("RestingTime") + .HasColumnType("INTEGER"); + + b.Property("SessionId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TemplateId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("SessionId"); + + b.HasIndex("TemplateId"); + + b.ToTable("Exercices"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Exercice_template", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Duration") + .HasColumnType("REAL"); + + b.Property("Equipment") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ImageId") + .HasColumnType("TEXT"); + + b.Property("Instructions") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("VideoId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Exercice_template"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Session", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Day") + .HasColumnType("INTEGER"); + + b.Property("Description") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Target") + .HasColumnType("INTEGER"); + + b.Property("TrainingProgramId") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("TrainingProgramId"); + + b.ToTable("Sessions"); + }); + + modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Difficulty") + .HasColumnType("INTEGER"); + + b.Property("Goal") + .HasColumnType("INTEGER"); + + b.Property("Lang") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("OwnerId") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("WeekDuration") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.ToTable("Programs"); + }); + + modelBuilder.Entity("Infrastructure.Entities.User", b => + { + b.Property("Id") + .HasColumnType("TEXT"); + + b.Property("Age") + .HasColumnType("INTEGER"); + + b.Property("EGoal") + .HasColumnType("TEXT"); + + b.Property("EHealthProblem") + .HasColumnType("INTEGER"); + + b.Property("ESleepLevel") + .HasColumnType("INTEGER"); + + b.Property("ESport") + .HasColumnType("INTEGER"); + + b.Property("ESportLevel") + .HasColumnType("INTEGER"); + + b.Property("HashPassword") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Height") + .HasColumnType("REAL"); + + b.Property("Logo") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("NbSessionPerWeek") + .HasColumnType("INTEGER"); + + b.Property("OAuthId") + .HasColumnType("TEXT"); + + b.Property("OAuthProvider") + .HasColumnType("TEXT"); + + b.Property("Sexe") + .HasColumnType("INTEGER"); + + b.Property("Weight") + .HasColumnType("REAL"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Exercice", b => + { + b.HasOne("Infrastructure.Entities.Session", "Session") + .WithMany("Exercices") + .HasForeignKey("SessionId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Infrastructure.Entities.Exercice_template", "Template") + .WithMany() + .HasForeignKey("TemplateId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Session"); + + b.Navigation("Template"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Session", b => + { + b.HasOne("Infrastructure.Entities.TrainingProgram", "TrainingProgram") + .WithMany("Sessions") + .HasForeignKey("TrainingProgramId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("TrainingProgram"); + }); + + modelBuilder.Entity("Infrastructure.Entities.Session", b => + { + b.Navigation("Exercices"); + }); + + modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b => + { + b.Navigation("Sessions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Infrastructure/Stub/StubbedContext.cs b/Infrastructure/Stub/StubbedContext.cs index 0d46c2f..a46adfc 100644 --- a/Infrastructure/Stub/StubbedContext.cs +++ b/Infrastructure/Stub/StubbedContext.cs @@ -33,7 +33,7 @@ public class StubbedContext : OptifitDbContext NbSessionPerWeek = GenerateRandomInt(1, 7), EGoal = GenerateRandomString(10), ESleepLevel = ESleepLevel.GOOD, - ESportLevel = ESportLevel.BEGINNER, + ESportLevel = EDifficulty.BEGINNER, HashPassword = GenerateRandomString(10), OAuthProvider = null, OAuthId = null @@ -50,7 +50,7 @@ public class StubbedContext : OptifitDbContext NbSessionPerWeek = GenerateRandomInt(1, 7), EGoal = GenerateRandomString(10), ESleepLevel = ESleepLevel.GOOD, - ESportLevel = ESportLevel.BEGINNER, + ESportLevel = EDifficulty.BEGINNER, HashPassword = GenerateRandomString(10), OAuthProvider = null, OAuthId = null diff --git a/Server/Controller/v1/ExercicesTemplateController.cs b/Server/Controller/v1/ExercicesTemplateController.cs new file mode 100644 index 0000000..5d840df --- /dev/null +++ b/Server/Controller/v1/ExercicesTemplateController.cs @@ -0,0 +1,79 @@ +using Asp.Versioning; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Server.Dto.Request; +using Server.Dto.Response; +using Server.IServices; + +namespace Server.Controller.v1; + +[ApiController] +[ApiVersion("1.0")] +[Route("api/v{version:apiVersion}/[controller]")] +public class ExercicesTemplateController : ControllerBase +{ + private readonly ILogger _logger; + private readonly IExerciceService _dataServices; + + public ExercicesTemplateController(ILogger logger, IExerciceTemplateService dataServices) + { + _logger = logger; + _dataServices = dataServices; + } + + [HttpGet] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [AllowAnonymous] + public async Task GetExercices([FromQuery] int pageIndex = 1, [FromQuery] int pageSize = 5, [FromQuery] bool ascending = true) + { + var exercices = await _dataServices.GetExercices(pageIndex, pageSize, ascending); + return exercices.TotalCount == 0 ? NoContent() : Ok(exercices); + } + + [HttpGet("{id}")] + [ProducesResponseType(typeof(ResponseExerciceDto), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [AllowAnonymous] + public async Task GetExerciceById(string id) + { + var exercice = await _dataServices.GetExerciceById(id); + return exercice == null ? NotFound() : Ok(exercice); + } + + [HttpPost] + [ProducesResponseType(typeof(ResponseExerciceDto), StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [AllowAnonymous] + public async Task CreateExercice([FromBody] RequestExerciceDto request) + { + if (!ModelState.IsValid) return BadRequest(ModelState); + + var createdExercice = await _dataServices.CreateExercice(request); + return CreatedAtAction(nameof(GetExerciceById), new { id = createdExercice.Id }, createdExercice); + } + + [HttpPut("{id}")] + [ProducesResponseType(typeof(ResponseExerciceDto), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] + [AllowAnonymous] + public async Task UpdateExercice(string id, [FromBody] RequestExerciceDto request) + { + if (!ModelState.IsValid) return BadRequest(ModelState); + + var updatedExercice = await _dataServices.UpdateExercice(id, request); + return updatedExercice == null ? NotFound() : Ok(updatedExercice); + } + + [HttpDelete("{id}")] + [ProducesResponseType(StatusCodes.Status204NoContent)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + [RequireHttps] + [AllowAnonymous] + public async Task DeleteExercice(string id) + { + var deleted = await _dataServices.DeleteExercice(id); + return deleted ? NoContent() : NotFound(); + } +} \ No newline at end of file diff --git a/Server/IServices/IExerciceTemplateSercice.cs b/Server/IServices/IExerciceTemplateSercice.cs new file mode 100644 index 0000000..cf513b8 --- /dev/null +++ b/Server/IServices/IExerciceTemplateSercice.cs @@ -0,0 +1,6 @@ +namespace Server.IServices; + +public class IExerciceTemplateSercice +{ + +} \ No newline at end of file diff --git a/Shared/ESportLevel.cs b/Shared/ESportLevel.cs deleted file mode 100644 index aa1b4f6..0000000 --- a/Shared/ESportLevel.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Shared; - -public enum ESportLevel -{ - NOT_SPORTY, - BEGINNER, - SPORTY, - VERY_SPORTY -} diff --git a/Shared/Enums/ECategory.cs b/Shared/Enums/ECategory.cs new file mode 100644 index 0000000..645a5f4 --- /dev/null +++ b/Shared/Enums/ECategory.cs @@ -0,0 +1,6 @@ +namespace Shared; + +public enum ECategory +{ + +} \ No newline at end of file diff --git a/Shared/Enums/EDay.cs b/Shared/Enums/EDay.cs new file mode 100644 index 0000000..7245e1a --- /dev/null +++ b/Shared/Enums/EDay.cs @@ -0,0 +1,6 @@ +namespace Shared; + +public enum EDay +{ + +} \ No newline at end of file diff --git a/Shared/Enums/EDifficulty.cs b/Shared/Enums/EDifficulty.cs new file mode 100644 index 0000000..b039f8c --- /dev/null +++ b/Shared/Enums/EDifficulty.cs @@ -0,0 +1,6 @@ +namespace Shared; + +public enum EDifficulty +{ + +} \ No newline at end of file diff --git a/Shared/Enums/EGoal.cs b/Shared/Enums/EGoal.cs new file mode 100644 index 0000000..b3efb61 --- /dev/null +++ b/Shared/Enums/EGoal.cs @@ -0,0 +1,6 @@ +namespace Shared; + +public enum EGoal +{ + +} \ No newline at end of file diff --git a/Shared/EHealthProblem.cs b/Shared/Enums/EHealthProblem.cs similarity index 100% rename from Shared/EHealthProblem.cs rename to Shared/Enums/EHealthProblem.cs diff --git a/Shared/Enums/ELang.cs b/Shared/Enums/ELang.cs new file mode 100644 index 0000000..83a3dd9 --- /dev/null +++ b/Shared/Enums/ELang.cs @@ -0,0 +1,6 @@ +namespace Shared; + +public enum ELang +{ + +} \ No newline at end of file diff --git a/Shared/ESleepLevel.cs b/Shared/Enums/ESleepLevel.cs similarity index 100% rename from Shared/ESleepLevel.cs rename to Shared/Enums/ESleepLevel.cs diff --git a/Shared/ESport.cs b/Shared/Enums/ESport.cs similarity index 100% rename from Shared/ESport.cs rename to Shared/Enums/ESport.cs diff --git a/Shared/Enums/ETarget.cs b/Shared/Enums/ETarget.cs new file mode 100644 index 0000000..93a51fa --- /dev/null +++ b/Shared/Enums/ETarget.cs @@ -0,0 +1,6 @@ +namespace Shared; + +public enum ETarget +{ + +} \ No newline at end of file