Training progs improuvemeent

TrainingProgramService
Leo TUAILLON 4 months ago
parent d8b81f7566
commit 53d4dadf68

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

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

@ -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<Exercice> Exercices { get; set; } = new Collection<Exercice>();
}

@ -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<Session> Sessions { get; set; } = new Collection<Session>();
}

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

@ -0,0 +1,197 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Duration")
.HasColumnType("REAL");
b.Property<string>("Image")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbRepetitions")
.HasColumnType("INTEGER");
b.Property<int>("NbSeries")
.HasColumnType("INTEGER");
b.Property<string>("SessionId")
.HasColumnType("TEXT");
b.Property<string>("Video")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("SessionId");
b.ToTable("Exercices");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Duration")
.HasColumnType("REAL");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("TrainingProgramId")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("TrainingProgramId");
b.ToTable("Sessions");
});
modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Difficulty")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("WeekDuration")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Programs");
});
modelBuilder.Entity("Infrastructure.Entities.User", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("EGoal")
.HasColumnType("TEXT");
b.Property<int>("EHealthProblem")
.HasColumnType("INTEGER");
b.Property<int?>("ESleepLevel")
.HasColumnType("INTEGER");
b.Property<int?>("ESport")
.HasColumnType("INTEGER");
b.Property<int?>("ESportLevel")
.HasColumnType("INTEGER");
b.Property<string>("HashPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Height")
.HasColumnType("REAL");
b.Property<string>("Logo")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbSessionPerWeek")
.HasColumnType("INTEGER");
b.Property<string>("OAuthId")
.HasColumnType("TEXT");
b.Property<string>("OAuthProvider")
.HasColumnType("TEXT");
b.Property<bool>("Sexe")
.HasColumnType("INTEGER");
b.Property<float>("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
}
}
}

@ -0,0 +1,125 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Infrastructure.Migrations
{
/// <inheritdoc />
public partial class Initialize : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Programs",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
WeekDuration = table.Column<int>(type: "INTEGER", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
Difficulty = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Programs", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
Age = table.Column<int>(type: "INTEGER", nullable: false),
Height = table.Column<float>(type: "REAL", nullable: false),
Weight = table.Column<float>(type: "REAL", nullable: false),
Sexe = table.Column<bool>(type: "INTEGER", nullable: false),
Logo = table.Column<string>(type: "TEXT", nullable: false),
NbSessionPerWeek = table.Column<int>(type: "INTEGER", nullable: false),
EGoal = table.Column<string>(type: "TEXT", nullable: true),
EHealthProblem = table.Column<int>(type: "INTEGER", nullable: false),
ESport = table.Column<int>(type: "INTEGER", nullable: true),
ESleepLevel = table.Column<int>(type: "INTEGER", nullable: true),
ESportLevel = table.Column<int>(type: "INTEGER", nullable: true),
HashPassword = table.Column<string>(type: "TEXT", nullable: false),
OAuthProvider = table.Column<string>(type: "TEXT", nullable: true),
OAuthId = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Sessions",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
Duration = table.Column<float>(type: "REAL", nullable: false),
TrainingProgramId = table.Column<string>(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<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
Description = table.Column<string>(type: "TEXT", nullable: false),
Duration = table.Column<float>(type: "REAL", nullable: false),
Image = table.Column<string>(type: "TEXT", nullable: false),
Video = table.Column<string>(type: "TEXT", nullable: false),
NbSeries = table.Column<int>(type: "INTEGER", nullable: false),
NbRepetitions = table.Column<int>(type: "INTEGER", nullable: false),
SessionId = table.Column<string>(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");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Exercices");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Sessions");
migrationBuilder.DropTable(
name: "Programs");
}
}
}

@ -0,0 +1,247 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("Category")
.HasColumnType("INTEGER");
b.Property<int>("NbReps")
.HasColumnType("INTEGER");
b.Property<int>("NbSets")
.HasColumnType("INTEGER");
b.Property<int>("RestingTime")
.HasColumnType("INTEGER");
b.Property<string>("SessionId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("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<string>("Id")
.HasColumnType("TEXT");
b.Property<float>("Duration")
.HasColumnType("REAL");
b.Property<string>("Equipment")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("ImageId")
.HasColumnType("TEXT");
b.Property<string>("Instructions")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("VideoId")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Exercice_template");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("Day")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Target")
.HasColumnType("INTEGER");
b.Property<string>("TrainingProgramId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("TrainingProgramId");
b.ToTable("Sessions");
});
modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("Difficulty")
.HasColumnType("INTEGER");
b.Property<int>("Goal")
.HasColumnType("INTEGER");
b.Property<int>("Lang")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("OwnerId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("WeekDuration")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Programs");
});
modelBuilder.Entity("Infrastructure.Entities.User", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("EGoal")
.HasColumnType("TEXT");
b.Property<int>("EHealthProblem")
.HasColumnType("INTEGER");
b.Property<int?>("ESleepLevel")
.HasColumnType("INTEGER");
b.Property<int?>("ESport")
.HasColumnType("INTEGER");
b.Property<int?>("ESportLevel")
.HasColumnType("INTEGER");
b.Property<string>("HashPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Height")
.HasColumnType("REAL");
b.Property<string>("Logo")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbSessionPerWeek")
.HasColumnType("INTEGER");
b.Property<string>("OAuthId")
.HasColumnType("TEXT");
b.Property<string>("OAuthProvider")
.HasColumnType("TEXT");
b.Property<bool>("Sexe")
.HasColumnType("INTEGER");
b.Property<float>("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
}
}
}

@ -0,0 +1,318 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Infrastructure.Migrations
{
/// <inheritdoc />
public partial class TESTTrainingProgMig : Migration
{
/// <inheritdoc />
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<string>(
name: "TrainingProgramId",
table: "Sessions",
type: "TEXT",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "TEXT",
oldNullable: true);
migrationBuilder.AddColumn<int>(
name: "Day",
table: "Sessions",
type: "INTEGER",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "Target",
table: "Sessions",
type: "INTEGER",
nullable: false,
defaultValue: 0);
migrationBuilder.AlterColumn<int>(
name: "Difficulty",
table: "Programs",
type: "INTEGER",
nullable: false,
oldClrType: typeof(string),
oldType: "TEXT");
migrationBuilder.AddColumn<int>(
name: "Goal",
table: "Programs",
type: "INTEGER",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "Lang",
table: "Programs",
type: "INTEGER",
nullable: false,
defaultValue: 0);
migrationBuilder.AlterColumn<string>(
name: "SessionId",
table: "Exercices",
type: "TEXT",
nullable: false,
defaultValue: "",
oldClrType: typeof(string),
oldType: "TEXT",
oldNullable: true);
migrationBuilder.AddColumn<int>(
name: "Category",
table: "Exercices",
type: "INTEGER",
nullable: false,
defaultValue: 0);
migrationBuilder.AddColumn<int>(
name: "NbReps",
table: "Exercices",
type: "INTEGER",
nullable: false,
defaultValue: 0);
migrationBuilder.CreateTable(
name: "Exercice_template",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: false),
Equipment = table.Column<string>(type: "TEXT", nullable: false),
Instructions = table.Column<string>(type: "TEXT", nullable: false),
Duration = table.Column<float>(type: "REAL", nullable: false),
ImageId = table.Column<string>(type: "TEXT", nullable: true),
VideoId = table.Column<string>(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);
}
/// <inheritdoc />
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<string>(
name: "TrainingProgramId",
table: "Sessions",
type: "TEXT",
nullable: true,
oldClrType: typeof(string),
oldType: "TEXT");
migrationBuilder.AddColumn<float>(
name: "Duration",
table: "Sessions",
type: "REAL",
nullable: false,
defaultValue: 0f);
migrationBuilder.AlterColumn<string>(
name: "Difficulty",
table: "Programs",
type: "TEXT",
nullable: false,
oldClrType: typeof(int),
oldType: "INTEGER");
migrationBuilder.AlterColumn<string>(
name: "SessionId",
table: "Exercices",
type: "TEXT",
nullable: true,
oldClrType: typeof(string),
oldType: "TEXT");
migrationBuilder.AddColumn<string>(
name: "Description",
table: "Exercices",
type: "TEXT",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<float>(
name: "Duration",
table: "Exercices",
type: "REAL",
nullable: false,
defaultValue: 0f);
migrationBuilder.AddColumn<string>(
name: "Image",
table: "Exercices",
type: "TEXT",
nullable: false,
defaultValue: "");
migrationBuilder.AddColumn<string>(
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");
}
}
}

@ -0,0 +1,244 @@
// <auto-generated />
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<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("Category")
.HasColumnType("INTEGER");
b.Property<int>("NbReps")
.HasColumnType("INTEGER");
b.Property<int>("NbSets")
.HasColumnType("INTEGER");
b.Property<int>("RestingTime")
.HasColumnType("INTEGER");
b.Property<string>("SessionId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("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<string>("Id")
.HasColumnType("TEXT");
b.Property<float>("Duration")
.HasColumnType("REAL");
b.Property<string>("Equipment")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("ImageId")
.HasColumnType("TEXT");
b.Property<string>("Instructions")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("VideoId")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Exercice_template");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("Day")
.HasColumnType("INTEGER");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Target")
.HasColumnType("INTEGER");
b.Property<string>("TrainingProgramId")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("TrainingProgramId");
b.ToTable("Sessions");
});
modelBuilder.Entity("Infrastructure.Entities.TrainingProgram", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("Difficulty")
.HasColumnType("INTEGER");
b.Property<int>("Goal")
.HasColumnType("INTEGER");
b.Property<int>("Lang")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("OwnerId")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("WeekDuration")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Programs");
});
modelBuilder.Entity("Infrastructure.Entities.User", b =>
{
b.Property<string>("Id")
.HasColumnType("TEXT");
b.Property<int>("Age")
.HasColumnType("INTEGER");
b.Property<string>("EGoal")
.HasColumnType("TEXT");
b.Property<int>("EHealthProblem")
.HasColumnType("INTEGER");
b.Property<int?>("ESleepLevel")
.HasColumnType("INTEGER");
b.Property<int?>("ESport")
.HasColumnType("INTEGER");
b.Property<int?>("ESportLevel")
.HasColumnType("INTEGER");
b.Property<string>("HashPassword")
.IsRequired()
.HasColumnType("TEXT");
b.Property<float>("Height")
.HasColumnType("REAL");
b.Property<string>("Logo")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("NbSessionPerWeek")
.HasColumnType("INTEGER");
b.Property<string>("OAuthId")
.HasColumnType("TEXT");
b.Property<string>("OAuthProvider")
.HasColumnType("TEXT");
b.Property<bool>("Sexe")
.HasColumnType("INTEGER");
b.Property<float>("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
}
}
}

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

@ -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<ExercicesTemplateController> _logger;
private readonly IExerciceService _dataServices;
public ExercicesTemplateController(ILogger<ExercicesDataController> logger, IExerciceTemplateService dataServices)
{
_logger = logger;
_dataServices = dataServices;
}
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<ResponseExerciceDto>), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status204NoContent)]
[AllowAnonymous]
public async Task<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> DeleteExercice(string id)
{
var deleted = await _dataServices.DeleteExercice(id);
return deleted ? NoContent() : NotFound();
}
}

@ -0,0 +1,6 @@
namespace Server.IServices;
public class IExerciceTemplateSercice
{
}

@ -1,9 +0,0 @@
namespace Shared;
public enum ESportLevel
{
NOT_SPORTY,
BEGINNER,
SPORTY,
VERY_SPORTY
}

@ -0,0 +1,6 @@
namespace Shared;
public enum ECategory
{
}

@ -0,0 +1,6 @@
namespace Shared;
public enum EDay
{
}

@ -0,0 +1,6 @@
namespace Shared;
public enum EDifficulty
{
}

@ -0,0 +1,6 @@
namespace Shared;
public enum EGoal
{
}

@ -0,0 +1,6 @@
namespace Shared;
public enum ELang
{
}

@ -0,0 +1,6 @@
namespace Shared;
public enum ETarget
{
}
Loading…
Cancel
Save