🚀 Create project on HeartTrack

WORK-WebAPI
Antoine PEREDERII 1 year ago
parent 159450f31d
commit 4362499396

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Entities\Entities.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,30 @@
using Entities;
using Microsoft.EntityFrameworkCore;
namespace DbContextLib;
public class LibraryContext : DbContext
{
public DbSet<AthleteEntity> AthletesSet { get; set; }
public LibraryContext()
:base()
{ }
public LibraryContext(DbContextOptions<LibraryContext> options)
:base(options)
{ }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if(!optionsBuilder.IsConfigured)
{
optionsBuilder.UseSqlite($"Data Source=uca.HeartTrack.db");
}
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}

@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Entities;
[Table("Activity")]
public class ActivityEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdActivity { get; set; }
public required string Type { get; set; }
public DateTime Date { get; set; }
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
public int EffortFelt { get; set; }
public float Variability { get; set; }
public float Variance { get; set; }
public float StandardDeviation { get; set; }
public float Average { get; set; }
public int Maximum { get; set; }
public int Minimum { get; set; }
public float AverageTemperature { get; set; }
public bool HasAutoPause { get; set; }
}

@ -0,0 +1,27 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Entities;
[Table("Athlete")]
public class AthleteEntity
{
// ! donner plus de contraintes !!
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdAthlete { get; set; }
[Required]
[MaxLength(100)]
public required string Username { get; set; }
[MaxLength(100)]
public required string LastName { get; set; }
[MaxLength(150)]
public required string FirstName { get; set; }
public required string Email { get; set; }
public required string Sexe { get; set; }
public float Lenght { get; set; }
public float Weight { get; set; }
public required string Password { get; set; }
public DateTime DateOfBirth { get; set; }
public bool IsCoach { get; set; }
}

@ -0,0 +1,15 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Entities;
[Table("DataSource")]
public class DataSourceEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdSource { get; set; }
public required string Type { get; set; }
public required string Modele { get; set; }
public float Precision { get; set; }
}

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Entities;
[Table("HeartRate")]
public class HeartRateEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdHeartRate { get; set; }
public double Altitude { get; set; }
public DateTime Time { get; set; }
public float Temperature { get; set; }
public int Bpm { get; set; }
public float Longitude { get; set; }
public float Latitude { get; set; }
}

@ -0,0 +1,16 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Entities;
[Table("Notification")]
public class NotificationEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdNotif { get; set; }
public required string Message { get; set; }
public DateTime Date { get; set; }
public required bool Statut { get; set; }
public required string Urgence { get; set; }
}

@ -0,0 +1,17 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Entities;
[Table("Statistic")]
public class StatisticEntity
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdStatistic { get; set; }
public float Weight { get; set; }
public double AverageHeartRate { get; set; }
public double MaximumHeartRate { get; set; }
public double AverageCaloriesBurned { get; set; }
public DateTime Date { get; set; }
}

@ -0,0 +1,20 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Entities;
[Table("Training")]
public class TrainingEntity
{
// ! donner plus de contraintes !!
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int IdTraining { get; set; }
public DateTime Date { get; set; }
[MaxLength(300)]
public string? Description { get; set; }
public float Latitude { get; set; }
public float Longitude { get; set; }
[MaxLength(300)]
public string? FeedBack { get; set; }
}

@ -0,0 +1,52 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbContextLib", "DbContextLib\DbContextLib.csproj", "{330A5DA0-0B4E-48D4-9AF3-6DCB39EE9622}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Entities", "Entities\Entities.csproj", "{A07F86B3-555B-4B35-8BB1-25E844825A38}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubbedContextLib", "StubbedContextLib\StubbedContextLib.csproj", "{2F44DE6E-EFFC-42FE-AFF6-79CDC762E6D8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{2B227C67-3BEC-4A83-BDA0-F3918FBC0D18}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTestEntities", "Tests\ConsoleTestEntities\ConsoleTestEntities.csproj", "{477D2129-A6C9-4FF8-8BE9-5E9E8E5282F8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTestRelationships", "Tests\ConsoleTestRelationships\ConsoleTestRelationships.csproj", "{2D166FAD-4934-474B-96A8-6C0635156EC2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{330A5DA0-0B4E-48D4-9AF3-6DCB39EE9622}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{330A5DA0-0B4E-48D4-9AF3-6DCB39EE9622}.Debug|Any CPU.Build.0 = Debug|Any CPU
{330A5DA0-0B4E-48D4-9AF3-6DCB39EE9622}.Release|Any CPU.ActiveCfg = Release|Any CPU
{330A5DA0-0B4E-48D4-9AF3-6DCB39EE9622}.Release|Any CPU.Build.0 = Release|Any CPU
{A07F86B3-555B-4B35-8BB1-25E844825A38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A07F86B3-555B-4B35-8BB1-25E844825A38}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A07F86B3-555B-4B35-8BB1-25E844825A38}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A07F86B3-555B-4B35-8BB1-25E844825A38}.Release|Any CPU.Build.0 = Release|Any CPU
{2F44DE6E-EFFC-42FE-AFF6-79CDC762E6D8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F44DE6E-EFFC-42FE-AFF6-79CDC762E6D8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F44DE6E-EFFC-42FE-AFF6-79CDC762E6D8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F44DE6E-EFFC-42FE-AFF6-79CDC762E6D8}.Release|Any CPU.Build.0 = Release|Any CPU
{477D2129-A6C9-4FF8-8BE9-5E9E8E5282F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{477D2129-A6C9-4FF8-8BE9-5E9E8E5282F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{477D2129-A6C9-4FF8-8BE9-5E9E8E5282F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{477D2129-A6C9-4FF8-8BE9-5E9E8E5282F8}.Release|Any CPU.Build.0 = Release|Any CPU
{2D166FAD-4934-474B-96A8-6C0635156EC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D166FAD-4934-474B-96A8-6C0635156EC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D166FAD-4934-474B-96A8-6C0635156EC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D166FAD-4934-474B-96A8-6C0635156EC2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{477D2129-A6C9-4FF8-8BE9-5E9E8E5282F8} = {2B227C67-3BEC-4A83-BDA0-F3918FBC0D18}
{2D166FAD-4934-474B-96A8-6C0635156EC2} = {2B227C67-3BEC-4A83-BDA0-F3918FBC0D18}
EndGlobalSection
EndGlobal

@ -0,0 +1,31 @@
using DbContextLib;
using Entities;
using Microsoft.EntityFrameworkCore;
namespace StubbedContextLib;
public class ActivityStubbedContext : LibraryContext
{
public ActivityStubbedContext()
:base()
{ }
public ActivityStubbedContext(DbContextOptions<LibraryContext> options)
:base(options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<ActivityEntity>().HasData(
new ActivityEntity { IdActivity = 1, Type = "Running", Date = new DateTime(), StartTime = new DateTime(), EndTime = new DateTime(), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false },
new ActivityEntity { IdActivity = 2, Type = "Cycling", Date = new DateTime(), StartTime = new DateTime(), EndTime = new DateTime(), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false },
new ActivityEntity { IdActivity = 3, Type = "Swimming", Date = new DateTime(), StartTime = new DateTime(), EndTime = new DateTime(), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false },
new ActivityEntity { IdActivity = 4, Type = "Walking", Date = new DateTime(), StartTime = new DateTime(), EndTime = new DateTime(), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false },
new ActivityEntity { IdActivity = 5, Type = "Hiking", Date = new DateTime(), StartTime = new DateTime(), EndTime = new DateTime(), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false },
new ActivityEntity { IdActivity = 6, Type = "Climbing", Date = new DateTime(), StartTime = new DateTime(), EndTime = new DateTime(), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false },
new ActivityEntity { IdActivity = 7, Type = "Yoga", Date = new DateTime(), StartTime = new DateTime(), EndTime = new DateTime(), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false }
);
}
}

@ -0,0 +1,29 @@
using DbContextLib;
using Entities;
using Microsoft.EntityFrameworkCore;
namespace StubbedContextLib;
public class AthleteStubbedContext : LibraryContext
{
public AthleteStubbedContext()
:base()
{ }
public AthleteStubbedContext(DbContextOptions<LibraryContext> options)
:base(options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<AthleteEntity>().HasData(
new AthleteEntity { IdAthlete = 1, Username = "Doe", LastName = "Doe", FirstName = "John", Email = "john.doe@example.com", Password = "password123", Sexe = "M", Lenght = 1.80, Weight = 75, DateOfBirth = new DateTime(), IsCoach = true },
new AthleteEntity { IdAthlete = 2, Username = "Smith", LastName = "Smith", FirstName = "Jane", Email = "jane.smith@example.com", Password = "secure456", Sexe = "F", Lenght = 1.65, Weight = 60, DateOfBirth = new DateTime(), IsCoach = false },
new AthleteEntity { IdAthlete = 3, Username = "Martin", LastName = "Martin", FirstName = "Paul", Email = "paul.martin@example.com", Password = "super789", Sexe = "M", Lenght = 1.75, Weight = 68, DateOfBirth = new DateTime(), IsCoach = true },
new AthleteEntity { IdAthlete = 4, Username = "Brown", LastName = "Brown", FirstName = "Anna", Email = "anna.brown@example.com", Password = "test000", Sexe = "F", Lenght = 1.70, Weight = 58, DateOfBirth = new DateTime(), IsCoach = false },
new AthleteEntity { IdAthlete = 5, Username = "Lee", LastName = "Lee", FirstName ="Bruce", Email = "bruce.lee@example.com", Password = "hello321", Sexe = "M", Lenght = 2.0, Weight = 90, DateOfBirth = new DateTime(), IsCoach = false }
);
}
}

@ -0,0 +1,29 @@
using DbContextLib;
using Entities;
using Microsoft.EntityFrameworkCore;
namespace StubbedContextLib;
public class DataSourceStubbedContext : LibraryContext
{
public DataSourceStubbedContext()
:base()
{ }
public DataSourceStubbedContext(DbContextOptions<LibraryContext> options)
:base(options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<DataSourceEntity>().HasData(
new DataSourceEntity { IdSource = 1, Type = "Smartwatch", Modele = "Garmin", Precision = 0.5f },
new DataSourceEntity { IdSource = 2, Type = "Smartwatch", Modele = "Polar", Precision = 0.5f },
new DataSourceEntity { IdSource = 3, Type = "Smartwatch", Modele = "Suunto", Precision = 0.5f },
new DataSourceEntity { IdSource = 4, Type = "Smartwatch", Modele = "Fitbit", Precision = 0.5f },
new DataSourceEntity { IdSource = 5, Type = "Smartwatch", Modele = "Apple Watch", Precision = 0.5f }
);
}
}

@ -0,0 +1,29 @@
using DbContextLib;
using Entities;
using Microsoft.EntityFrameworkCore;
namespace StubbedContextLib;
public class HeartRateStubbedContext : LibraryContext
{
public HeartRateStubbedContext()
:base()
{ }
public HeartRateStubbedContext(DbContextOptions<LibraryContext> options)
:base(options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<HeartRateEntity>().HasData(
new HeartRateEntity { IdHeartRate = 1, Altitude = 0.0, Time = new DateTime(), Temperature = 20.0f, Bpm = 60, Longitude = 35f, Latitude = 66f },
new HeartRateEntity { IdHeartRate = 2, Altitude = 10, Time = new DateTime(), Temperature = 20.5f, Bpm = 65, Longitude = 35f, Latitude = 67f },
new HeartRateEntity { IdHeartRate = 3, Altitude = 11, Time = new DateTime(), Temperature = 20.0f, Bpm = 71, Longitude = 36f, Latitude = 66f },
new HeartRateEntity { IdHeartRate = 4, Altitude = 12, Time = new DateTime(), Temperature = 20.5f, Bpm = 75, Longitude = 36f, Latitude = 67f },
new HeartRateEntity { IdHeartRate = 5, Altitude = 13, Time = new DateTime(), Temperature = 20.0f, Bpm = 80, Longitude = 37f, Latitude = 66f }
);
}
}

@ -0,0 +1,147 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using StubbedContextLib;
#nullable disable
namespace StubbedContextLib.Migrations
{
[DbContext(typeof(AthleteStubbedContext))]
[Migration("20240216134447_MyMirgations")]
partial class MyMirgations
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
modelBuilder.Entity("Entities.AthleteEntity", b =>
{
b.Property<int>("IdAthlete")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("DateOfBirth")
.HasColumnType("TEXT");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FirstName")
.IsRequired()
.HasMaxLength(150)
.HasColumnType("TEXT");
b.Property<bool>("IsCoach")
.HasColumnType("INTEGER");
b.Property<string>("LastName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<double>("Lenght")
.HasColumnType("REAL");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Sexe")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<float>("Weight")
.HasColumnType("REAL");
b.HasKey("IdAthlete");
b.ToTable("Athlete");
b.HasData(
new
{
IdAthlete = 1,
DateOfBirth = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Email = "john.doe@example.com",
FirstName = "John",
IsCoach = true,
LastName = "Doe",
Lenght = 1.8,
Password = "password123",
Sexe = "M",
Username = "Doe",
Weight = 75f
},
new
{
IdAthlete = 2,
DateOfBirth = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Email = "jane.smith@example.com",
FirstName = "Jane",
IsCoach = false,
LastName = "Smith",
Lenght = 1.6499999999999999,
Password = "secure456",
Sexe = "F",
Username = "Smith",
Weight = 60f
},
new
{
IdAthlete = 3,
DateOfBirth = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Email = "paul.martin@example.com",
FirstName = "Paul",
IsCoach = true,
LastName = "Martin",
Lenght = 1.75,
Password = "super789",
Sexe = "M",
Username = "Martin",
Weight = 68f
},
new
{
IdAthlete = 4,
DateOfBirth = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Email = "anna.brown@example.com",
FirstName = "Anna",
IsCoach = false,
LastName = "Brown",
Lenght = 1.7,
Password = "test000",
Sexe = "F",
Username = "Brown",
Weight = 58f
},
new
{
IdAthlete = 5,
DateOfBirth = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Email = "bruce.lee@example.com",
FirstName = "Bruce",
IsCoach = false,
LastName = "Lee",
Lenght = 2.0,
Password = "hello321",
Sexe = "M",
Username = "Lee",
Weight = 90f
});
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,58 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
namespace StubbedContextLib.Migrations
{
/// <inheritdoc />
public partial class MyMirgations : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Athlete",
columns: table => new
{
IdAthlete = table.Column<int>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Username = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
LastName = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
FirstName = table.Column<string>(type: "TEXT", maxLength: 150, nullable: false),
Email = table.Column<string>(type: "TEXT", nullable: false),
Sexe = table.Column<string>(type: "TEXT", nullable: false),
Lenght = table.Column<double>(type: "REAL", nullable: false),
Weight = table.Column<float>(type: "REAL", nullable: false),
Password = table.Column<string>(type: "TEXT", nullable: false),
DateOfBirth = table.Column<DateTime>(type: "TEXT", nullable: false),
IsCoach = table.Column<bool>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Athlete", x => x.IdAthlete);
});
migrationBuilder.InsertData(
table: "Athlete",
columns: new[] { "IdAthlete", "DateOfBirth", "Email", "FirstName", "IsCoach", "LastName", "Lenght", "Password", "Sexe", "Username", "Weight" },
values: new object[,]
{
{ 1, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "john.doe@example.com", "John", true, "Doe", 1.8, "password123", "M", "Doe", 75f },
{ 2, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "jane.smith@example.com", "Jane", false, "Smith", 1.6499999999999999, "secure456", "F", "Smith", 60f },
{ 3, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "paul.martin@example.com", "Paul", true, "Martin", 1.75, "super789", "M", "Martin", 68f },
{ 4, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "anna.brown@example.com", "Anna", false, "Brown", 1.7, "test000", "F", "Brown", 58f },
{ 5, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), "bruce.lee@example.com", "Bruce", false, "Lee", 2.0, "hello321", "M", "Lee", 90f }
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Athlete");
}
}
}

@ -0,0 +1,144 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using StubbedContextLib;
#nullable disable
namespace StubbedContextLib.Migrations
{
[DbContext(typeof(AthleteStubbedContext))]
partial class AthleteStubbedContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
modelBuilder.Entity("Entities.AthleteEntity", b =>
{
b.Property<int>("IdAthlete")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER");
b.Property<DateTime>("DateOfBirth")
.HasColumnType("TEXT");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("FirstName")
.IsRequired()
.HasMaxLength(150)
.HasColumnType("TEXT");
b.Property<bool>("IsCoach")
.HasColumnType("INTEGER");
b.Property<string>("LastName")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<double>("Lenght")
.HasColumnType("REAL");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Sexe")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Username")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<float>("Weight")
.HasColumnType("REAL");
b.HasKey("IdAthlete");
b.ToTable("Athlete");
b.HasData(
new
{
IdAthlete = 1,
DateOfBirth = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Email = "john.doe@example.com",
FirstName = "John",
IsCoach = true,
LastName = "Doe",
Lenght = 1.8,
Password = "password123",
Sexe = "M",
Username = "Doe",
Weight = 75f
},
new
{
IdAthlete = 2,
DateOfBirth = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Email = "jane.smith@example.com",
FirstName = "Jane",
IsCoach = false,
LastName = "Smith",
Lenght = 1.6499999999999999,
Password = "secure456",
Sexe = "F",
Username = "Smith",
Weight = 60f
},
new
{
IdAthlete = 3,
DateOfBirth = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Email = "paul.martin@example.com",
FirstName = "Paul",
IsCoach = true,
LastName = "Martin",
Lenght = 1.75,
Password = "super789",
Sexe = "M",
Username = "Martin",
Weight = 68f
},
new
{
IdAthlete = 4,
DateOfBirth = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Email = "anna.brown@example.com",
FirstName = "Anna",
IsCoach = false,
LastName = "Brown",
Lenght = 1.7,
Password = "test000",
Sexe = "F",
Username = "Brown",
Weight = 58f
},
new
{
IdAthlete = 5,
DateOfBirth = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
Email = "bruce.lee@example.com",
FirstName = "Bruce",
IsCoach = false,
LastName = "Lee",
Lenght = 2.0,
Password = "hello321",
Sexe = "M",
Username = "Lee",
Weight = 90f
});
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,29 @@
using DbContextLib;
using Entities;
using Microsoft.EntityFrameworkCore;
namespace StubbedContextLib;
public class NotificationStubbedContext : LibraryContext
{
public NotificationStubbedContext()
:base()
{ }
public NotificationStubbedContext(DbContextOptions<LibraryContext> options)
:base(options)
{ }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<NotificationEntity>().HasData(
new NotificationEntity { IdNotif = 1, Message = "You have a new activity to check", Date = new DateTime(), Statut = true, Urgence = "A" },
new NotificationEntity { IdNotif = 2, Message = "You have a new athlete to check", Date = new DateTime(), Statut = false, Urgence = "3" },
new NotificationEntity { IdNotif = 3, Message = "You have a new heart rate to check", Date = new DateTime(), Statut = true, Urgence = "2" },
new NotificationEntity { IdNotif = 4, Message = "You have a new data source to check", Date = new DateTime(), Statut = false, Urgence = "1" },
new NotificationEntity { IdNotif = 5, Message = "You have a new notification to check", Date = new DateTime(), Statut = true, Urgence = "3" }
);
}
}

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\DbContextLib\DbContextLib.csproj" />
<ProjectReference Include="..\Entities\Entities.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\..\Entities\Entities.csproj" />
<ProjectReference Include="..\..\DbContextLib\DbContextLib.csproj" />
<ProjectReference Include="..\..\StubbedContextLib\StubbedContextLib.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<StartWorkingDirectory>$(MSBuildProjectDirectory)</StartWorkingDirectory>
</PropertyGroup>
</Project>

@ -0,0 +1,229 @@
using DbContextLib;
using StubbedContextLib;
using Microsoft.EntityFrameworkCore;
class Program
{
static void Main(string[] args)
{
try {
using (LibraryContext db = new AthleteStubbedContext())
{
AthletesTests(db);
// // Test d'ajout, de modification et de suppression
// AddUpdateDeleteOperations(db);
// // Test d'emprunt et de retour de livre
// BorrowAndReturnBook(db);
}
}
catch (Exception ex)
{
Console.WriteLine($"Une erreur s'est produite : {ex.Message}");
}
}
static void AthletesTests(LibraryContext db)
{
Console.WriteLine("Accès à tous les athletes :");
// Affichage des livres
Console.WriteLine("Athletes :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet)
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
Console.WriteLine("Accès à l'athlete d'id '2' :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.IdAthlete == 2))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
Console.WriteLine("Accès à l'athlete de username 'Doe' :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.Username == "Doe"))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
Console.WriteLine("Accès à l'athlete de sexe 'F' :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.Sexe == "F"))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
Console.WriteLine("Accès à l'athlete de email 'bruce.lee@example.com' :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.Email == "bruce.lee@example.com"))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
Console.WriteLine("Accès à l'athlete de poids '90' :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.Weight == 90))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
Console.WriteLine("Accès à l'athlete de taille '1.80' :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.Lenght == 1.80))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
// ! A revoir !!
Console.WriteLine("Accès à l'athlete de date de naissance '01/01/2000' :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.DateOfBirth == new DateTime()))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
Console.WriteLine("Accès à l'athlete de nom 'Martin' :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.LastName == "Martin"))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
Console.WriteLine("Accès à l'athlete de prénom 'Anna' :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.FirstName == "Anna"))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
Console.WriteLine("Accès à l'athlete de nom 'Brown' et de prénom 'Anna' :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.LastName == "Brown" && a.FirstName == "Anna"))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
Console.WriteLine("Accès au coachs :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.IsCoach == true))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.Username}, {athlete.LastName}, {athlete.FirstName}, {athlete.Email}, {athlete.Sexe}, {athlete.Lenght}, {athlete.Weight}, {athlete.DateOfBirth}, {athlete.IsCoach}");
}
Console.WriteLine("---------------------------------\n");
}
// /// <summary>
// /// Test d'ajout, de modification et de suppression de livres.
// /// </summary>
// /// <param name="db">Contexte de la base de données.</param>
// static void AddUpdateDeleteOperations(LibraryContext db)
// {
// Console.WriteLine("Test d'ajout, de modification et de suppression :");
// // Ajout d'un nouveau livre
// var newBook = new BookEntity { Title = "Comment bien réussir son stage", Author = "Abdelfettah HASBANI", Isbn = "TheBest" };
// // par defaut, l'Id en long est égale à zero et se mettre par la BDD
// db.BooksSet.Add(newBook);
// db.SaveChanges();
// // Affichage des livres après ajout
// Console.WriteLine("Livres après ajout :");
// // .Include pour importer les personnes, ne pas le mettre si pas besoins de personnes
// foreach (var book in db.BooksSet.Include(b => b.Person))
// {
// Console.WriteLine($"\t{book.Id}, {book.Title}, {book.Author}, {book.Isbn}, {book.Person?.FirstName} {book.Person?.LastName}");
// }
// // Modification du titre du nouveau livre
// newBook.Title = "Mes nouvelles dates de stage";
// db.SaveChanges();
// // Affichage des livres après modification
// Console.WriteLine("Livres après modification :");
// foreach (var book in db.BooksSet.Include(b => b.Person))
// {
// Console.WriteLine($"\t{book.Id}, {book.Title}, {book.Author}, {book.Isbn}, {book.Person?.FirstName} {book.Person?.LastName}");
// }
// // Suppression du nouveau livre
// db.BooksSet.Remove(newBook);
// db.SaveChanges();
// // Affichage des livres après suppression
// Console.WriteLine("Livres après suppression :");
// foreach (var book in db.BooksSet.Include(b => b.Person))
// {
// Console.WriteLine($"\t{book.Id}, {book.Title}, {book.Author}, {book.Isbn}, {book.Person?.FirstName} {book.Person?.LastName}");
// }
// }
// /// <summary>
// /// Test d'emprunt et de retour de livre.
// /// </summary>
// /// <param name="db">Contexte de la base de données.</param>
// static void BorrowAndReturnBook(LibraryContext db)
// {
// Console.WriteLine("Test d'emprunt et de retour de livre :");
// var person = db.PersonsSet.FirstOrDefault();
// var bookToBorrow = db.BooksSet.FirstOrDefault();
// // Retour du livre 1
// if (bookToBorrow != null)
// {
// bookToBorrow.Person = null;
// db.SaveChanges();
// }
// // Affichage des livres après retour
// Console.WriteLine("Livres après retour :");
// foreach (var book in db.BooksSet.Include(b => b.Person))
// {
// Console.WriteLine($"\t{book.Id}, {book.Title}, {book.Author}, {book.Isbn}, {book.Person?.FirstName} {book.Person?.LastName}");
// }
// // Emprunt d'un livre par une personne existante
// if (person != null && bookToBorrow != null)
// {
// bookToBorrow.Person = person;
// db.SaveChanges();
// }
// // Affichage des livres après emprunt
// Console.WriteLine("Livres après emprunt :");
// foreach (var book in db.BooksSet.Include(b => b.Person))
// {
// Console.WriteLine($"\t{book.Id}, {book.Title}, {book.Author}, {book.Isbn}, {book.Person?.FirstName} {book.Person?.LastName}");
// }
// }
}

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

@ -0,0 +1,2 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
Loading…
Cancel
Save