Fixing problem with Sessions routes and add TrainingProgram backend logic

main
Leo TUAILLON 5 months ago
parent 14247ce133
commit 09bcd36070

@ -4,7 +4,7 @@ using Infrastructure.Base;
namespace Infrastructure.Entities; namespace Infrastructure.Entities;
public class Program : EntityBase public class TrainingProgram : EntityBase
{ {
[Required] [Required]
public string Name { get; set; } public string Name { get; set; }

@ -0,0 +1,191 @@
// <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("20250109094119_TrainingProgram")]
partial class TrainingProgram
{
/// <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.Program", 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.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>("ProgramId")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ProgramId");
b.ToTable("Sessions");
});
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<string>("ESleepLevel")
.HasColumnType("TEXT");
b.Property<string>("ESportLevel")
.HasColumnType("TEXT");
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.Program", null)
.WithMany("Sessions")
.HasForeignKey("ProgramId");
});
modelBuilder.Entity("Infrastructure.Entities.Program", b =>
{
b.Navigation("Sessions");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.Navigation("Exercices");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,94 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Infrastructure.Migrations
{
/// <inheritdoc />
public partial class TrainingProgram : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "SessionId",
table: "Exercices",
type: "TEXT",
nullable: true);
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: "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),
ProgramId = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Sessions", x => x.Id);
table.ForeignKey(
name: "FK_Sessions_Programs_ProgramId",
column: x => x.ProgramId,
principalTable: "Programs",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_Exercices_SessionId",
table: "Exercices",
column: "SessionId");
migrationBuilder.CreateIndex(
name: "IX_Sessions_ProgramId",
table: "Sessions",
column: "ProgramId");
migrationBuilder.AddForeignKey(
name: "FK_Exercices_Sessions_SessionId",
table: "Exercices",
column: "SessionId",
principalTable: "Sessions",
principalColumn: "Id");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Exercices_Sessions_SessionId",
table: "Exercices");
migrationBuilder.DropTable(
name: "Sessions");
migrationBuilder.DropTable(
name: "Programs");
migrationBuilder.DropIndex(
name: "IX_Exercices_SessionId",
table: "Exercices");
migrationBuilder.DropColumn(
name: "SessionId",
table: "Exercices");
}
}
}

@ -42,15 +42,71 @@ namespace Infrastructure.Migrations
b.Property<int>("NbSeries") b.Property<int>("NbSeries")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<string>("SessionId")
.HasColumnType("TEXT");
b.Property<string>("Video") b.Property<string>("Video")
.IsRequired() .IsRequired()
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("SessionId");
b.ToTable("Exercices"); b.ToTable("Exercices");
}); });
modelBuilder.Entity("Infrastructure.Entities.Program", 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.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>("ProgramId")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("ProgramId");
b.ToTable("Sessions");
});
modelBuilder.Entity("Infrastructure.Entities.User", b => modelBuilder.Entity("Infrastructure.Entities.User", b =>
{ {
b.Property<string>("Id") b.Property<string>("Id")
@ -102,6 +158,30 @@ namespace Infrastructure.Migrations
b.ToTable("Users"); 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.Program", null)
.WithMany("Sessions")
.HasForeignKey("ProgramId");
});
modelBuilder.Entity("Infrastructure.Entities.Program", b =>
{
b.Navigation("Sessions");
});
modelBuilder.Entity("Infrastructure.Entities.Session", b =>
{
b.Navigation("Exercices");
});
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
} }

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

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

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

@ -0,0 +1,6 @@
namespace Server.Controller.v1;
public class TrainingProgramController
{
}

@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations;
namespace Server.Dto.Request namespace Server.Dto.Request
{ {
public class RequestProgramDto public class RequestTrainingProgramDto
{ {
[Required] [Required]
public string Name { get; set; } public string Name { get; set; }

@ -2,7 +2,7 @@ using System.Collections.Generic;
namespace Server.Dto.Response namespace Server.Dto.Response
{ {
public class ResponseProgramDto public class ResponseTrainingProgramDto
{ {
public string Id { get; set; } public string Id { get; set; }

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

@ -0,0 +1,6 @@
namespace Server.Mappers;
public class TrainingProgramProfile
{
}

@ -0,0 +1,6 @@
namespace Server.Services;
public class TrainingProgramService
{
}
Loading…
Cancel
Save