Compare commits

...

3 Commits

@ -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,21 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Infrastructure.Base;
namespace Infrastructure.Entities;
[Table("Exercice_template")]
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
}
}
}

@ -9,6 +9,7 @@ namespace Infrastructure
public virtual DbSet<Exercice> Exercices { get; set; }
public virtual DbSet<Session> Sessions { get; set; }
public virtual DbSet<TrainingProgram> Programs { get; set; }
public virtual DbSet<Exercice_template> ExerciceTemplates { get; set; }
public OptifitDbContext()
{

@ -0,0 +1,10 @@
using Infrastructure.Entities;
namespace Infrastructure.Repositories;
public class ExerciceTemplateRepository : GenericRepository<Exercice_template>, IExerciceTemplateRepository
{
public ExerciceTemplateRepository(OptifitDbContext context) : base(context)
{
}
}

@ -0,0 +1,7 @@
using Infrastructure.Entities;
namespace Infrastructure.Repositories;
public interface IExerciceTemplateRepository : IRepository<Exercice_template>
{
}

@ -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,80 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Server.Dto.Request;
using Server.Dto.Response;
using Server.IServices;
using Shared;
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 IExerciceTemplateSercice _dataServices;
public ExercicesTemplateController(ILogger<ExercicesTemplateController> logger, IExerciceTemplateSercice dataServices)
{
_logger = logger;
_dataServices = dataServices;
}
[HttpGet]
[ProducesResponseType(typeof(IEnumerable<ResponseTemplateExerciceDto>), 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(ResponseTemplateExerciceDto), 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(ResponseTemplateExerciceDto), StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[AllowAnonymous]
public async Task<IActionResult> CreateExercice([FromBody] RequestTemplateExerciceDto 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(ResponseTemplateExerciceDto), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[AllowAnonymous]
public async Task<IActionResult> UpdateExercice(string id, [FromBody] RequestTemplateExerciceDto 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();
}
}

@ -1,22 +1,16 @@
using System.ComponentModel.DataAnnotations;
using Shared;
namespace Server.Dto.Request
{
public class RequestExerciceDto
{
[Required]
public string Name { get; set; }
public ECategory Category { get; set; }
public string Description { get; set; }
public int NbSets { get; set; }
public float Duration { get; set; }
public string Image { get; set; }
public string Video { get; set; }
public int NbSeries { get; set; }
public int NbRepetitions { get; set; }
public int NbReps { get; set; }
public int RestingTime { get; set; }
}
}

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using Shared;
namespace Server.Dto.Request
{
@ -9,8 +10,9 @@ namespace Server.Dto.Request
public string Description { get; set; }
public float Duration { get; set; }
public EDay Day { get; set; }
public ETarget Target { get; set; }
public List<string> ExerciceIds { get; set; } = new List<string>();
}
}

@ -0,0 +1,14 @@
namespace Server.Dto.Request;
public class RequestTemplateExerciceDto
{
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,20 +1,21 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Shared;
namespace Server.Dto.Request
{
public class RequestTrainingProgramDto
{
[Required]
public ELang Lang { get; set; }
public string Name { get; set; }
[Required]
public int WeekDuration { get; set; }
public string Description { get; set; }
public string Difficulty { get; set; }
public string? OwnerId { get; set; }
public int? WeekDuration { get; set; }
public EGoal EGoal { get; set; }
public EDifficulty EDifficulty { get; set; }
public List<RequestSessionDto> Sessions { get; set; } = new List<RequestSessionDto>();
}
}

@ -1,21 +1,27 @@
using Shared;
namespace Server.Dto.Response
{
public class ResponseExerciceDto
{
public string Id { get; set; }
public string TemplateId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public float Duration { get; set; }
public string TemplateName { get; set; }
public string Image { get; set; }
public string TemplateInstructions { get; set; }
public string? TemplateImageId { get; set; }
public string Video { get; set; }
public string? TemplateVideoId { get; set; }
public ECategory Category { get; set; }
public int NbSeries { get; set; }
public int NbSets { get; set; }
public int NbRepetitions { get; set; }
public int NbReps { get; set; }
public int RestingTime { get; set; }
}
}

@ -1,3 +1,5 @@
using Shared;
namespace Server.Dto.Response
{
public class ResponseSessionDto
@ -7,9 +9,12 @@ namespace Server.Dto.Response
public string Name { get; set; }
public string Description { get; set; }
public EDay Day { get; set; }
public ETarget Target { get; set; }
public float Duration { get; set; }
public List<ResponseExerciceDto> Exercices { get; set; } = new List<ResponseExerciceDto>();
}
}

@ -0,0 +1,18 @@
namespace Server.Dto.Response;
public class ResponseTemplateExerciceDto
{
public string Id { get; set; }
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,19 +1,22 @@
using System.Collections.Generic;
using Shared;
namespace Server.Dto.Response
{
public class ResponseTrainingProgramDto
{
public string Id { get; set; }
public ELang Lang { get; set; }
public string Name { get; set; }
public int WeekDuration { get; set; }
public string Description { get; set; }
public string Difficulty { get; set; }
public string? OwnerId { get; set; }
public int? WeekDuration { get; set; }
public EGoal EGoal { get; set; }
public EDifficulty EDifficulty { get; set; }
public List<ResponseSessionDto> Sessions { get; set; } = new List<ResponseSessionDto>();
}
}

@ -19,6 +19,6 @@ public class ResponseUserDto
public ESport ESport { get; set; }
public ESportLevel ESportLevel { get; set; }
public EDifficulty ESportLevel { get; set; }
}

Binary file not shown.

@ -0,0 +1,14 @@
using Server.Dto.Request;
using Server.Dto.Response;
using Shared;
namespace Server.IServices;
public interface IExerciceTemplateSercice
{
Task<PaginatedResult<ResponseTemplateExerciceDto>> GetExercices(int page, int size, bool ascending = true);
Task<ResponseTemplateExerciceDto?> GetExerciceById(string id);
Task<ResponseTemplateExerciceDto> CreateExercice(RequestTemplateExerciceDto request);
Task<ResponseTemplateExerciceDto?> UpdateExercice(string id, RequestTemplateExerciceDto request);
Task<bool> DeleteExercice(string id);
}

@ -3,13 +3,19 @@ using Infrastructure.Entities;
using Server.Dto.Request;
using Server.Dto.Response;
namespace Server.Mappers;
public class ExerciceProfile : Profile
namespace Server.Mappers
{
public ExerciceProfile()
public class ExerciceProfile : Profile
{
CreateMap<Exercice, ResponseExerciceDto>();
CreateMap<RequestExerciceDto, Exercice>();
public ExerciceProfile()
{
CreateMap<Exercice, ResponseExerciceDto>()
.ForMember(dest => dest.TemplateName, opt => opt.MapFrom(src => src.Template.Name))
.ForMember(dest => dest.TemplateInstructions, opt => opt.MapFrom(src => src.Template.Instructions))
.ForMember(dest => dest.TemplateImageId, opt => opt.MapFrom(src => src.Template.ImageId))
.ForMember(dest => dest.TemplateVideoId, opt => opt.MapFrom(src => src.Template.VideoId));
CreateMap<RequestExerciceDto, Exercice>();
}
}
}

@ -0,0 +1,33 @@
using AutoMapper;
using Infrastructure.Entities;
using Server.Dto.Request;
using Server.Dto.Response;
namespace Server.Mappers
{
public class ExerciceTemplateProfile : Profile
{
public ExerciceTemplateProfile()
{
// Mapping de l'entité vers le DTO de réponse
CreateMap<Exercice_template, ResponseTemplateExerciceDto>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
.ForMember(dest => dest.Equipment, opt => opt.MapFrom(src => src.Equipment))
.ForMember(dest => dest.Instructions, opt => opt.MapFrom(src => src.Instructions))
.ForMember(dest => dest.Duration, opt => opt.MapFrom(src => src.Duration))
.ForMember(dest => dest.ImageId, opt => opt.MapFrom(src => src.ImageId))
.ForMember(dest => dest.VideoId, opt => opt.MapFrom(src => src.VideoId));
// Mapping du DTO de requête vers l'entité
CreateMap<RequestTemplateExerciceDto, Exercice_template>()
// Comme la propriété Name n'est pas fournie dans le DTO, on l'ignore ici
.ForMember(dest => dest.Name, opt => opt.Ignore())
.ForMember(dest => dest.Equipment, opt => opt.MapFrom(src => src.Equipment))
.ForMember(dest => dest.Instructions, opt => opt.MapFrom(src => src.Instructions))
.ForMember(dest => dest.Duration, opt => opt.MapFrom(src => src.Duration))
.ForMember(dest => dest.ImageId, opt => opt.MapFrom(src => src.ImageId))
.ForMember(dest => dest.VideoId, opt => opt.MapFrom(src => src.VideoId));
}
}
}

@ -1,4 +1,5 @@
using AutoMapper;
using System.Linq;
using Infrastructure.Entities;
using Server.Dto.Request;
using Server.Dto.Response;
@ -10,7 +11,10 @@ namespace Server.Mappers
public SessionProfile()
{
CreateMap<Session, ResponseSessionDto>()
.ForMember(dest => dest.Exercices, opt => opt.MapFrom(src => src.Exercices));
.ForMember(dest => dest.Duration,
opt => opt.MapFrom(src => src.Exercices.Sum(e => e.Template.Duration)))
.ForMember(dest => dest.Exercices,
opt => opt.MapFrom(src => src.Exercices));
CreateMap<RequestSessionDto, Session>()
.ForMember(dest => dest.Exercices, opt => opt.Ignore());

@ -3,23 +3,30 @@ using Infrastructure.Entities;
using Server.Dto.Request;
using Server.Dto.Response;
namespace Server.Mappers;
public class TrainingProgramProfile : Profile
namespace Server.Mappers
{
public TrainingProgramProfile()
public class TrainingProgramProfile : Profile
{
CreateMap<TrainingProgram, ResponseTrainingProgramDto>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
.ForMember(dest => dest.Description, opt => opt.MapFrom(src => src.Description))
.ForMember(dest => dest.WeekDuration, opt => opt.MapFrom(src => src.WeekDuration))
.ForMember(dest => dest.Sessions, opt => opt.MapFrom(src => src.Sessions));
public TrainingProgramProfile()
{
CreateMap<TrainingProgram, ResponseTrainingProgramDto>()
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
.ForMember(dest => dest.Lang, opt => opt.MapFrom(src => src.Lang))
.ForMember(dest => dest.OwnerId, opt => opt.MapFrom(src => src.OwnerId))
.ForMember(dest => dest.WeekDuration, opt => opt.MapFrom(src => src.WeekDuration))
.ForMember(dest => dest.EGoal, opt => opt.MapFrom(src => src.Goal))
.ForMember(dest => dest.EDifficulty, opt => opt.MapFrom(src => src.Difficulty))
.ForMember(dest => dest.Sessions, opt => opt.MapFrom(src => src.Sessions));
CreateMap<RequestTrainingProgramDto, TrainingProgram>()
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
.ForMember(dest => dest.Description, opt => opt.MapFrom(src => src.Description))
.ForMember(dest => dest.WeekDuration, opt => opt.MapFrom(src => src.WeekDuration))
.ForMember(dest => dest.Sessions, opt => opt.MapFrom(src => src.Sessions));
CreateMap<RequestTrainingProgramDto, TrainingProgram>()
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
.ForMember(dest => dest.Lang, opt => opt.MapFrom(src => src.Lang))
.ForMember(dest => dest.OwnerId, opt => opt.MapFrom(src => src.OwnerId))
.ForMember(dest => dest.WeekDuration, opt => opt.MapFrom(src => src.WeekDuration.HasValue ? src.WeekDuration.Value : 0))
.ForMember(dest => dest.Goal, opt => opt.MapFrom(src => src.EGoal))
.ForMember(dest => dest.Difficulty, opt => opt.MapFrom(src => src.EDifficulty))
.ForMember(dest => dest.Sessions, opt => opt.MapFrom(src => src.Sessions));
}
}
}

@ -15,11 +15,13 @@ builder.Services.AddScoped<IUsersService, UsersService>();
builder.Services.AddScoped<IExerciceService, ExerciceService>();
builder.Services.AddScoped<ISessionService, SessionService>();
builder.Services.AddScoped<ITrainingProgramService, TrainingProgramService>();
builder.Services.AddScoped<IExerciceTemplateSercice, ExerciceTemplateService>();
builder.Services.AddScoped<IUserRepository, UserRepository>();
builder.Services.AddScoped<IExerciceRepository, ExerciceRepository>();
builder.Services.AddScoped<ISessionRepository, SessionRepository>();
builder.Services.AddScoped<ITrainingProgramRepository, TrainingProgramRepository>();
builder.Services.AddScoped<IExerciceTemplateRepository, ExerciceTemplateRepository>();
builder.Services.AddControllers();
@ -32,6 +34,7 @@ builder.Services.AddAutoMapper(typeof(ExerciceProfile));
builder.Services.AddAutoMapper(typeof(SessionProfile));
builder.Services.AddAutoMapper(typeof(PaginatedResultProfile));
builder.Services.AddAutoMapper(typeof(TrainingProgramProfile));
builder.Services.AddAutoMapper(typeof(ExerciceTemplateProfile));
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle

@ -0,0 +1,77 @@
using AutoMapper;
using Infrastructure;
using Infrastructure.Entities;
using Infrastructure.Repositories;
using Server.Dto.Request;
using Server.Dto.Response;
using Server.IServices;
using Shared;
namespace Server.Services
{
public class ExerciceTemplateService : IExerciceTemplateSercice
{
private readonly OptifitDbContext _context;
private readonly IExerciceTemplateRepository _exerciceTemplateRepository;
private readonly IMapper _mapper;
public ExerciceTemplateService(OptifitDbContext context, IExerciceTemplateRepository exerciceTemplateRepository, IMapper mapper)
{
_context = context;
_exerciceTemplateRepository = exerciceTemplateRepository;
_mapper = mapper;
}
public async Task<PaginatedResult<ResponseTemplateExerciceDto>> GetExercices(int page, int size, bool ascending = true)
{
// Ici, on part du principe que la méthode du repository attend un index de page à partir de 0.
// Vous pouvez adapter l'appel selon la signature de votre méthode.
var exercices = await _exerciceTemplateRepository.GetPaginatedListAsync(page - 1, size, null);
return _mapper.Map<PaginatedResult<ResponseTemplateExerciceDto>>(exercices);
}
public async Task<ResponseTemplateExerciceDto?> GetExerciceById(string id)
{
var exercice = await _exerciceTemplateRepository.GetByIdAsync(id);
return exercice == null ? null : _mapper.Map<ResponseTemplateExerciceDto>(exercice);
}
public async Task<ResponseTemplateExerciceDto> CreateExercice(RequestTemplateExerciceDto request)
{
// On mappe le DTO de requête vers l'entité
var exercice = _mapper.Map<Exercice_template>(request);
// Comme le DTO ne fournit pas le Name et que celui-ci est requis,
// vous pouvez ici définir une valeur par défaut ou appliquer une logique de création.
exercice.Name = string.IsNullOrWhiteSpace(exercice.Name) ? "Exercice Template" : exercice.Name;
await _exerciceTemplateRepository.InsertAsync(exercice);
await _context.SaveChangesAsync();
return _mapper.Map<ResponseTemplateExerciceDto>(exercice);
}
public async Task<ResponseTemplateExerciceDto?> UpdateExercice(string id, RequestTemplateExerciceDto request)
{
var exercice = await _exerciceTemplateRepository.GetByIdAsync(id);
if (exercice == null)
return null;
// Met à jour l'entité en mappant le DTO dans l'entité existante
_mapper.Map(request, exercice);
_exerciceTemplateRepository.Update(exercice);
await _context.SaveChangesAsync();
return _mapper.Map<ResponseTemplateExerciceDto>(exercice);
}
public async Task<bool> DeleteExercice(string id)
{
var exercice = await _exerciceTemplateRepository.GetByIdAsync(id);
if (exercice == null)
return false;
_exerciceTemplateRepository.Delete(id);
await _context.SaveChangesAsync();
return true;
}
}
}

@ -0,0 +1,8 @@
namespace Shared;
public enum ECategory
{
WARMUP,
TRAINING,
STRETCHING,
}

@ -0,0 +1,12 @@
namespace Shared;
public enum EDay
{
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY,
SUNDAY
}

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

@ -0,0 +1,8 @@
namespace Shared;
public enum EGoal
{
WEIGHT_LOSS,
MASS_GAIN,
FITNESS,
}

@ -0,0 +1,7 @@
namespace Shared;
public enum ELang
{
FR,
EN
}

@ -0,0 +1,11 @@
namespace Shared;
public enum ETarget
{
LEGS,
ARMS,
BACK,
CHEST,
ABS,
CARDIO
}

@ -8,7 +8,6 @@
<ItemGroup>
<Folder Include="Criteria\" />
<Folder Include="Enums\" />
</ItemGroup>
</Project>

Loading…
Cancel
Save