diff --git a/docs/doxygen/Doxyfile b/docs/doxygen/Doxyfile index acd0c86..12f9ffe 100644 --- a/docs/doxygen/Doxyfile +++ b/docs/doxygen/Doxyfile @@ -125,7 +125,7 @@ WARN_LOGFILE = # Configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = ../../src +INPUT = src/ INPUT_ENCODING = UTF-8 FILE_PATTERNS = *.c \ *.cc \ @@ -223,7 +223,7 @@ GENERATE_HTML = YES HTML_OUTPUT = html HTML_FILE_EXTENSION = .html HTML_HEADER = -HTML_FOOTER = footer.html +HTML_FOOTER = HTML_STYLESHEET = HTML_EXTRA_STYLESHEET = HTML_EXTRA_FILES = images/CodeFirst.png images/clubinfo.png diff --git a/src/DbContextLib/LibraryContext.cs b/src/DbContextLib/LibraryContext.cs index 2a41084..1cf6224 100644 --- a/src/DbContextLib/LibraryContext.cs +++ b/src/DbContextLib/LibraryContext.cs @@ -81,6 +81,103 @@ namespace DbContextLib protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); + + modelBuilder.Entity() + .HasKey(a => a.IdActivity); + //generation mode (at insertion) + modelBuilder.Entity() + .Property(a => a.IdActivity) + .ValueGeneratedOnAdd(); + + //primary key of HeartRateEntity + modelBuilder.Entity() + .HasKey(h => h.IdHeartRate); + //generation mode (at insertion) + modelBuilder.Entity() + .Property(h => h.IdHeartRate) + .ValueGeneratedOnAdd(); + + //primary key of DataSourceEntity + modelBuilder.Entity() + .HasKey(d => d.IdSource); + //generation mode (at insertion) + modelBuilder.Entity() + .Property(d => d.IdSource) + .ValueGeneratedOnAdd(); + + //primary key of AthleteEntity + modelBuilder.Entity() + .HasKey(at => at.IdAthlete); + //generation mode (at insertion) + modelBuilder.Entity() + .Property(at => at.IdAthlete) + .ValueGeneratedOnAdd(); + + //primary key of StatisticEntity + modelBuilder.Entity() + .HasKey(s => s.IdStatistic); + //generation mode (at insertion) + modelBuilder.Entity() + .Property(s => s.IdStatistic) + .ValueGeneratedOnAdd(); + + //primary key of + modelBuilder.Entity() + .HasKey(t => t.IdTraining); + //generation mode (at insertion) + modelBuilder.Entity() + .Property(t => t.IdTraining) + .ValueGeneratedOnAdd(); + + //primary key of + modelBuilder.Entity() + .HasKey(n => n.IdNotif); + //generation mode (at insertion) + modelBuilder.Entity() + .Property(n => n.IdNotif) + .ValueGeneratedOnAdd(); + + modelBuilder.Entity() + .HasMany(at => at.Trainings) + .WithOne(n => n.Athlete) + .HasForeignKey(n => n.AthleteId) + .IsRequired(); + + modelBuilder.Entity() + .HasMany(at => at.Trainings) + .WithOne(t => t.Athlete) + .HasForeignKey(t => t.AthleteId) + .IsRequired(); + + modelBuilder.Entity() + .HasMany(at => at.Statistics) + .WithOne(s => s.Athlete) + .HasForeignKey(s => s.AthleteId) + .IsRequired(); + + modelBuilder.Entity() + .HasMany(at => at.Activities) + .WithOne(a => a.Athlete) + .HasForeignKey(a => a.AthleteId) + .IsRequired(); + + modelBuilder.Entity() + .HasMany(d => d.Activities) + .WithOne(a => a.DataSource) + .HasForeignKey(a => a.DataSourceId) + .IsRequired(); + + modelBuilder.Entity() + .HasMany(a => a.HeartRates) + .WithOne(h => h.Activity) + .HasForeignKey(h => h.ActivityId) + .IsRequired(); + + modelBuilder.Entity() + .HasMany(ds => ds.Activities) + .WithOne(at => at.DataSource) + .HasForeignKey(at => at.DataSourceId) + .IsRequired(false); } } } \ No newline at end of file diff --git a/src/Entities/ActivityEntity.cs b/src/Entities/ActivityEntity.cs index 1f89d06..ab26369 100644 --- a/src/Entities/ActivityEntity.cs +++ b/src/Entities/ActivityEntity.cs @@ -29,7 +29,7 @@ namespace Entities /// [Required] [MaxLength(100)] - public string Type { get; set; } + public string Type { get; set; } = null!; /// /// Gets or sets the date of the activity. @@ -96,5 +96,15 @@ namespace Entities /// Gets or sets whether the activity has an automatic pause feature. /// public bool HasAutoPause { get; set; } + + public ICollection HeartRates { get; set; } = new List(); + + public int DataSourceId { get; set; } + + public DataSourceEntity DataSource { get; set; } = null!; + + public int AthleteId { get; set; } + + public AthleteEntity Athlete { get; set; } = null!; } } \ No newline at end of file diff --git a/src/Entities/AthleteEntity.cs b/src/Entities/AthleteEntity.cs index 7138fd8..ee6c0b0 100644 --- a/src/Entities/AthleteEntity.cs +++ b/src/Entities/AthleteEntity.cs @@ -86,5 +86,19 @@ namespace Entities /// Gets or sets whether the athlete is a coach. /// public bool IsCoach { get; set; } + + public ICollection Activities { get; set; } = new List(); + + public ICollection Statistics { get; set; } = new List(); + + public ICollection Trainings { get; set; } = new List(); + + public ICollection Notifications { get; set; } = new List(); + + public int? DataSourceId { get; set; } + + public DataSourceEntity? DataSource { get; set; } + + public ICollection } } \ No newline at end of file diff --git a/src/Entities/DataSourceEntity.cs b/src/Entities/DataSourceEntity.cs index 37d339a..adef299 100644 --- a/src/Entities/DataSourceEntity.cs +++ b/src/Entities/DataSourceEntity.cs @@ -42,5 +42,9 @@ namespace Entities /// Gets or sets the precision of the data source. /// public float Precision { get; set; } + + public ICollection Activities { get; set; } = new List(); + + public ICollection Athletes { get; set; } = new List(); } } \ No newline at end of file diff --git a/src/Entities/HeartRateEntity.cs b/src/Entities/HeartRateEntity.cs index 3e11017..8104a99 100644 --- a/src/Entities/HeartRateEntity.cs +++ b/src/Entities/HeartRateEntity.cs @@ -55,5 +55,9 @@ namespace Entities /// Gets or sets the latitude. /// public float Latitude { get; set; } + + public int ActivityId { get; set; } + + public ActivityEntity Activity { get; set; } = null!; } } \ No newline at end of file diff --git a/src/Entities/NotificationEntity.cs b/src/Entities/NotificationEntity.cs index 1d93b99..d7973b7 100644 --- a/src/Entities/NotificationEntity.cs +++ b/src/Entities/NotificationEntity.cs @@ -48,5 +48,9 @@ namespace Entities /// [MaxLength(100)] public string Urgence { get; set; } = null!; + + public int AthleteId { get; set; } + + public AthleteEntity Athlete { get; set; } = null!; } } \ No newline at end of file diff --git a/src/Entities/StatisticEntity.cs b/src/Entities/StatisticEntity.cs index f3e8381..7f00fb4 100644 --- a/src/Entities/StatisticEntity.cs +++ b/src/Entities/StatisticEntity.cs @@ -50,5 +50,9 @@ namespace Entities [Required(ErrorMessage = "Statistic Date is required")] [DisplayFormat(DataFormatString = "{0:MM/dd/yyyy}", ApplyFormatInEditMode = true)] public DateOnly Date { get; set; } + + public int AthleteId { get; set; } + + public AthleteEntity Athlete { get; set; } = null!; } } \ No newline at end of file diff --git a/src/Entities/TrainingEntity.cs b/src/Entities/TrainingEntity.cs index ca5e0f8..7f467ef 100644 --- a/src/Entities/TrainingEntity.cs +++ b/src/Entities/TrainingEntity.cs @@ -52,5 +52,9 @@ namespace Entities /// [MaxLength(300)] public string? FeedBack { get; set; } + + public int AthleteId { get; set; } + + public AthleteEntity Athlete { get; set; } = null!; } } \ No newline at end of file diff --git a/src/StubbedContextLib/ActivityStubbedContext.cs b/src/StubbedContextLib/ActivityStubbedContext.cs index 1eddac9..e5379f6 100644 --- a/src/StubbedContextLib/ActivityStubbedContext.cs +++ b/src/StubbedContextLib/ActivityStubbedContext.cs @@ -38,13 +38,13 @@ namespace StubbedContextLib // Seed data for activities modelBuilder.Entity().HasData( - new ActivityEntity { IdActivity = 1, Type = "Running", Date = new DateOnly(2023, 01, 10), StartTime = new TimeOnly(13, 00, 34), EndTime = new TimeOnly(14, 00, 22), 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 DateOnly(2023, 01, 25), StartTime = new TimeOnly(13, 04, 34), EndTime = new TimeOnly(14, 00, 22), 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 DateOnly(2023, 12, 10), StartTime = new TimeOnly(13, 30, 34), EndTime = new TimeOnly(15, 02, 22), 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 DateOnly(2024, 01, 02), StartTime = new TimeOnly(15, 00, 00), EndTime = new TimeOnly(16, 01, 55), 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 DateOnly(2024, 01, 12), StartTime = new TimeOnly(07, 45, 34), EndTime = new TimeOnly(09, 00, 22), 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 DateOnly(2024, 01, 27), StartTime = new TimeOnly(13, 30, 01), EndTime = new TimeOnly(14, 00, 22), 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 DateOnly(2024, 02, 22), StartTime = new TimeOnly(22, 00, 34), EndTime = new TimeOnly(23, 50, 58), 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 = 1, Type = "Running", Date = new DateOnly(2023, 01, 10), StartTime = new TimeOnly(13, 00, 34), EndTime = new TimeOnly(14, 00, 22), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false, DataSourceId = 1, AthleteId = 1 }, + new ActivityEntity { IdActivity = 2, Type = "Cycling", Date = new DateOnly(2023, 01, 25), StartTime = new TimeOnly(13, 04, 34), EndTime = new TimeOnly(14, 00, 22), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false, DataSourceId = 2, AthleteId = 2 }, + new ActivityEntity { IdActivity = 3, Type = "Swimming", Date = new DateOnly(2023, 12, 10), StartTime = new TimeOnly(13, 30, 34), EndTime = new TimeOnly(15, 02, 22), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false, DataSourceId = 1, AthleteId = 1 }, + new ActivityEntity { IdActivity = 4, Type = "Walking", Date = new DateOnly(2024, 01, 02), StartTime = new TimeOnly(15, 00, 00), EndTime = new TimeOnly(16, 01, 55), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false, DataSourceId = 3, AthleteId = 5 }, + new ActivityEntity { IdActivity = 5, Type = "Hiking", Date = new DateOnly(2024, 01, 12), StartTime = new TimeOnly(07, 45, 34), EndTime = new TimeOnly(09, 00, 22), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false, DataSourceId = 4, AthleteId = 4 }, + new ActivityEntity { IdActivity = 6, Type = "Climbing", Date = new DateOnly(2024, 01, 27), StartTime = new TimeOnly(13, 30, 01), EndTime = new TimeOnly(14, 00, 22), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false, DataSourceId = 4, AthleteId = 4 }, + new ActivityEntity { IdActivity = 7, Type = "Yoga", Date = new DateOnly(2024, 02, 22), StartTime = new TimeOnly(22, 00, 34), EndTime = new TimeOnly(23, 50, 58), EffortFelt = 5, Variability = 0.5f, Variance = 0.5f, StandardDeviation = 0.5f, Average = 0.5f, Maximum = 0, Minimum = 0, AverageTemperature = 20.0f, HasAutoPause = false, DataSourceId = 5, AthleteId = 3 } ); } } diff --git a/src/StubbedContextLib/AthleteStubbedContext.cs b/src/StubbedContextLib/AthleteStubbedContext.cs index cf1ea01..24cbfaf 100644 --- a/src/StubbedContextLib/AthleteStubbedContext.cs +++ b/src/StubbedContextLib/AthleteStubbedContext.cs @@ -38,10 +38,10 @@ namespace StubbedContextLib modelBuilder.Entity().HasData( new AthleteEntity { IdAthlete = 1, Username = "Doe", LastName = "Doe", FirstName = "John", Email = "john.doe@example.com", Password = "password123", Sexe = "M", Length = 1.80, Weight = 75, DateOfBirth = new DateOnly(1990, 01, 01), IsCoach = true }, - new AthleteEntity { IdAthlete = 2, Username = "Smith", LastName = "Smith", FirstName = "Jane", Email = "jane.smith@exemple.com", Password = "secure456", Sexe = "F", Length = 1.65, Weight = 60, DateOfBirth = new DateOnly(1995, 01, 01), IsCoach = false }, + new AthleteEntity { IdAthlete = 2, Username = "Smith", LastName = "Smith", FirstName = "Jane", Email = "jane.smith@exemple.com", Password = "secure456", Sexe = "F", Length = 1.65, Weight = 60, DateOfBirth = new DateOnly(1995, 01, 01), IsCoach = false, DataSourceId = 1 }, new AthleteEntity { IdAthlete = 3, Username = "Martin", LastName = "Martin", FirstName = "Paul", Email = "paul.martin@example.com", Password = "super789", Sexe = "M", Length = 1.75, Weight = 68, DateOfBirth = new DateOnly(1992, 01, 01), IsCoach = true }, new AthleteEntity { IdAthlete = 4, Username = "Brown", LastName = "Brown", FirstName = "Anna", Email = "anna.brown@example.com", Password = "test000", Sexe = "F", Length = 1.70, Weight = 58, DateOfBirth = new DateOnly(1993, 01, 01), IsCoach = false }, - new AthleteEntity { IdAthlete = 5, Username = "Lee", LastName = "Lee", FirstName = "Bruce", Email = "bruce.lee@example.com", Password = "hello321", Sexe = "M", Length = 2.0, Weight = 90, DateOfBirth = new DateOnly(1991, 01, 01), IsCoach = false } + new AthleteEntity { IdAthlete = 5, Username = "Lee", LastName = "Lee", FirstName = "Bruce", Email = "bruce.lee@example.com", Password = "hello321", Sexe = "M", Length = 2.0, Weight = 90, DateOfBirth = new DateOnly(1991, 01, 01), IsCoach = false, DataSourceId = 3 } ); } } diff --git a/src/StubbedContextLib/HeartRateStubbedContext.cs b/src/StubbedContextLib/HeartRateStubbedContext.cs index 501302a..6fbaa9e 100644 --- a/src/StubbedContextLib/HeartRateStubbedContext.cs +++ b/src/StubbedContextLib/HeartRateStubbedContext.cs @@ -37,11 +37,11 @@ namespace StubbedContextLib base.OnModelCreating(modelBuilder); modelBuilder.Entity().HasData( - new HeartRateEntity { IdHeartRate = 1, Altitude = 0.0, Time = new TimeOnly(13, 00, 30), Temperature = 20.0f, Bpm = 60, Longitude = 35f, Latitude = 66f }, - new HeartRateEntity { IdHeartRate = 2, Altitude = 10, Time = new TimeOnly(13, 00, 31), Temperature = 20.5f, Bpm = 65, Longitude = 35f, Latitude = 67f }, - new HeartRateEntity { IdHeartRate = 3, Altitude = 11, Time = new TimeOnly(13, 00, 32), Temperature = 20.0f, Bpm = 71, Longitude = 36f, Latitude = 66f }, - new HeartRateEntity { IdHeartRate = 4, Altitude = 12, Time = new TimeOnly(13, 00, 33), Temperature = 20.5f, Bpm = 75, Longitude = 36f, Latitude = 67f }, - new HeartRateEntity { IdHeartRate = 5, Altitude = 13, Time = new TimeOnly(13, 00, 34), Temperature = 20.0f, Bpm = 80, Longitude = 37f, Latitude = 66f } + new HeartRateEntity { IdHeartRate = 1, Altitude = 0.0, Time = new TimeOnly(13, 00, 30), Temperature = 20.0f, Bpm = 60, Longitude = 35f, Latitude = 66f, ActivityId = 1 }, + new HeartRateEntity { IdHeartRate = 2, Altitude = 10, Time = new TimeOnly(13, 00, 31), Temperature = 20.5f, Bpm = 65, Longitude = 35f, Latitude = 67f, ActivityId = 2 }, + new HeartRateEntity { IdHeartRate = 3, Altitude = 11, Time = new TimeOnly(13, 00, 32), Temperature = 20.0f, Bpm = 71, Longitude = 36f, Latitude = 66f, ActivityId = 1 }, + new HeartRateEntity { IdHeartRate = 4, Altitude = 12, Time = new TimeOnly(13, 00, 33), Temperature = 20.5f, Bpm = 75, Longitude = 36f, Latitude = 67f, ActivityId = 2 }, + new HeartRateEntity { IdHeartRate = 5, Altitude = 13, Time = new TimeOnly(13, 00, 34), Temperature = 20.0f, Bpm = 80, Longitude = 37f, Latitude = 66f, ActivityId = 4 } ); } } diff --git a/src/StubbedContextLib/Migrations/20240222104952_MyMigrations.cs b/src/StubbedContextLib/Migrations/20240222104952_MyMigrations.cs deleted file mode 100644 index ef7f153..0000000 --- a/src/StubbedContextLib/Migrations/20240222104952_MyMigrations.cs +++ /dev/null @@ -1,258 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional - -namespace StubbedContextLib.Migrations -{ - /// - public partial class MyMigrations : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Activity", - columns: table => new - { - IdActivity = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Type = table.Column(type: "TEXT", maxLength: 100, nullable: false), - Date = table.Column(type: "TEXT", nullable: false), - StartTime = table.Column(type: "TEXT", nullable: false), - EndTime = table.Column(type: "TEXT", nullable: false), - EffortFelt = table.Column(type: "INTEGER", nullable: false), - Variability = table.Column(type: "REAL", nullable: false), - Variance = table.Column(type: "REAL", nullable: false), - StandardDeviation = table.Column(type: "REAL", nullable: false), - Average = table.Column(type: "REAL", nullable: false), - Maximum = table.Column(type: "INTEGER", nullable: false), - Minimum = table.Column(type: "INTEGER", nullable: false), - AverageTemperature = table.Column(type: "REAL", nullable: false), - HasAutoPause = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Activity", x => x.IdActivity); - }); - - migrationBuilder.CreateTable( - name: "Athlete", - columns: table => new - { - IdAthlete = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Username = table.Column(type: "TEXT", maxLength: 100, nullable: false), - LastName = table.Column(type: "TEXT", maxLength: 100, nullable: false), - FirstName = table.Column(type: "TEXT", maxLength: 150, nullable: false), - Email = table.Column(type: "TEXT", maxLength: 100, nullable: false), - Sexe = table.Column(type: "TEXT", maxLength: 1, nullable: false), - Length = table.Column(type: "REAL", nullable: false), - Weight = table.Column(type: "REAL", nullable: false), - Password = table.Column(type: "TEXT", nullable: false), - DateOfBirth = table.Column(type: "TEXT", nullable: false), - IsCoach = table.Column(type: "INTEGER", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Athlete", x => x.IdAthlete); - }); - - migrationBuilder.CreateTable( - name: "DataSource", - columns: table => new - { - IdSource = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Type = table.Column(type: "TEXT", maxLength: 100, nullable: false), - Model = table.Column(type: "TEXT", maxLength: 100, nullable: false), - Precision = table.Column(type: "REAL", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_DataSource", x => x.IdSource); - }); - - migrationBuilder.CreateTable( - name: "HeartRate", - columns: table => new - { - IdHeartRate = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Altitude = table.Column(type: "REAL", nullable: false), - Time = table.Column(type: "TEXT", nullable: false), - Temperature = table.Column(type: "REAL", nullable: false), - Bpm = table.Column(type: "INTEGER", nullable: false), - Longitude = table.Column(type: "REAL", nullable: false), - Latitude = table.Column(type: "REAL", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_HeartRate", x => x.IdHeartRate); - }); - - migrationBuilder.CreateTable( - name: "Notification", - columns: table => new - { - IdNotif = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Message = table.Column(type: "TEXT", maxLength: 100, nullable: false), - Date = table.Column(type: "TEXT", nullable: false), - Statut = table.Column(type: "INTEGER", nullable: false), - Urgence = table.Column(type: "TEXT", maxLength: 100, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Notification", x => x.IdNotif); - }); - - migrationBuilder.CreateTable( - name: "Statistic", - columns: table => new - { - IdStatistic = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Weight = table.Column(type: "REAL", nullable: false), - AverageHeartRate = table.Column(type: "REAL", nullable: false), - MaximumHeartRate = table.Column(type: "REAL", nullable: false), - AverageCaloriesBurned = table.Column(type: "REAL", nullable: false), - Date = table.Column(type: "TEXT", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Statistic", x => x.IdStatistic); - }); - - migrationBuilder.CreateTable( - name: "Training", - columns: table => new - { - IdTraining = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Date = table.Column(type: "TEXT", nullable: false), - Description = table.Column(type: "TEXT", maxLength: 300, nullable: true), - Latitude = table.Column(type: "REAL", nullable: false), - Longitude = table.Column(type: "REAL", nullable: false), - FeedBack = table.Column(type: "TEXT", maxLength: 300, nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Training", x => x.IdTraining); - }); - - migrationBuilder.InsertData( - table: "Activity", - columns: new[] { "IdActivity", "Average", "AverageTemperature", "Date", "EffortFelt", "EndTime", "HasAutoPause", "Maximum", "Minimum", "StandardDeviation", "StartTime", "Type", "Variability", "Variance" }, - values: new object[,] - { - { 1, 0.5f, 20f, new DateOnly(2023, 1, 10), 5, new TimeOnly(14, 0, 22), false, 0, 0, 0.5f, new TimeOnly(13, 0, 34), "Running", 0.5f, 0.5f }, - { 2, 0.5f, 20f, new DateOnly(2023, 1, 25), 5, new TimeOnly(14, 0, 22), false, 0, 0, 0.5f, new TimeOnly(13, 4, 34), "Cycling", 0.5f, 0.5f }, - { 3, 0.5f, 20f, new DateOnly(2023, 12, 10), 5, new TimeOnly(15, 2, 22), false, 0, 0, 0.5f, new TimeOnly(13, 30, 34), "Swimming", 0.5f, 0.5f }, - { 4, 0.5f, 20f, new DateOnly(2024, 1, 2), 5, new TimeOnly(16, 1, 55), false, 0, 0, 0.5f, new TimeOnly(15, 0, 0), "Walking", 0.5f, 0.5f }, - { 5, 0.5f, 20f, new DateOnly(2024, 1, 12), 5, new TimeOnly(9, 0, 22), false, 0, 0, 0.5f, new TimeOnly(7, 45, 34), "Hiking", 0.5f, 0.5f }, - { 6, 0.5f, 20f, new DateOnly(2024, 1, 27), 5, new TimeOnly(14, 0, 22), false, 0, 0, 0.5f, new TimeOnly(13, 30, 1), "Climbing", 0.5f, 0.5f }, - { 7, 0.5f, 20f, new DateOnly(2024, 2, 22), 5, new TimeOnly(23, 50, 58), false, 0, 0, 0.5f, new TimeOnly(22, 0, 34), "Yoga", 0.5f, 0.5f } - }); - - migrationBuilder.InsertData( - table: "Athlete", - columns: new[] { "IdAthlete", "DateOfBirth", "Email", "FirstName", "IsCoach", "LastName", "Length", "Password", "Sexe", "Username", "Weight" }, - values: new object[,] - { - { 1, new DateOnly(1990, 1, 1), "john.doe@example.com", "John", true, "Doe", 1.8, "password123", "M", "Doe", 75f }, - { 2, new DateOnly(1995, 1, 1), "jane.smith@exemple.com", "Jane", false, "Smith", 1.6499999999999999, "secure456", "F", "Smith", 60f }, - { 3, new DateOnly(1992, 1, 1), "paul.martin@example.com", "Paul", true, "Martin", 1.75, "super789", "M", "Martin", 68f }, - { 4, new DateOnly(1993, 1, 1), "anna.brown@example.com", "Anna", false, "Brown", 1.7, "test000", "F", "Brown", 58f }, - { 5, new DateOnly(1991, 1, 1), "bruce.lee@example.com", "Bruce", false, "Lee", 2.0, "hello321", "M", "Lee", 90f } - }); - - migrationBuilder.InsertData( - table: "DataSource", - columns: new[] { "IdSource", "Model", "Precision", "Type" }, - values: new object[,] - { - { 1, "Garmin", 0.5f, "Smartwatch" }, - { 2, "Polar", 0.5f, "Smartwatch" }, - { 3, "Suunto", 0.5f, "Smartwatch" }, - { 4, "Fitbit", 0.5f, "Smartwatch" }, - { 5, "Apple Watch", 0.5f, "Smartwatch" } - }); - - migrationBuilder.InsertData( - table: "HeartRate", - columns: new[] { "IdHeartRate", "Altitude", "Bpm", "Latitude", "Longitude", "Temperature", "Time" }, - values: new object[,] - { - { 1, 0.0, 60, 66f, 35f, 20f, new TimeOnly(13, 0, 30) }, - { 2, 10.0, 65, 67f, 35f, 20.5f, new TimeOnly(13, 0, 31) }, - { 3, 11.0, 71, 66f, 36f, 20f, new TimeOnly(13, 0, 32) }, - { 4, 12.0, 75, 67f, 36f, 20.5f, new TimeOnly(13, 0, 33) }, - { 5, 13.0, 80, 66f, 37f, 20f, new TimeOnly(13, 0, 34) } - }); - - migrationBuilder.InsertData( - table: "Notification", - columns: new[] { "IdNotif", "Date", "Message", "Statut", "Urgence" }, - values: new object[,] - { - { 1, new DateTime(2023, 12, 25, 13, 0, 40, 0, DateTimeKind.Unspecified), "You have a new activity to check", true, "A" }, - { 2, new DateTime(2023, 12, 26, 13, 10, 40, 0, DateTimeKind.Unspecified), "You have a new athlete to check", false, "3" }, - { 3, new DateTime(2023, 12, 26, 16, 10, 4, 0, DateTimeKind.Unspecified), "You have a new heart rate to check", true, "2" }, - { 4, new DateTime(2024, 1, 12, 9, 30, 50, 0, DateTimeKind.Unspecified), "You have a new data source to check", false, "1" }, - { 5, new DateTime(2024, 2, 22, 12, 10, 0, 0, DateTimeKind.Unspecified), "You have a new notification to check", true, "3" } - }); - - migrationBuilder.InsertData( - table: "Statistic", - columns: new[] { "IdStatistic", "AverageCaloriesBurned", "AverageHeartRate", "Date", "MaximumHeartRate", "Weight" }, - values: new object[,] - { - { 1, 500.0, 120.0, new DateOnly(2021, 12, 12), 180.0, 75f }, - { 2, 600.0, 130.0, new DateOnly(2021, 1, 11), 190.0, 60f }, - { 3, 550.0, 125.0, new DateOnly(2022, 12, 30), 185.0, 68f }, - { 4, 650.0, 135.0, new DateOnly(2023, 2, 20), 195.0, 58f }, - { 5, 450.0, 110.0, new DateOnly(2024, 1, 10), 170.0, 90f } - }); - - migrationBuilder.InsertData( - table: "Training", - columns: new[] { "IdTraining", "Date", "Description", "FeedBack", "Latitude", "Longitude" }, - values: new object[,] - { - { 1, new DateOnly(2024, 1, 19), "Running", "Good", 48.8566f, 2.3522f }, - { 2, new DateOnly(2024, 2, 20), "Cycling", null, 48.8566f, 2.3522f }, - { 3, new DateOnly(2024, 2, 21), null, "Good", 48.8566f, 2.3522f }, - { 4, new DateOnly(2024, 2, 22), "Running", "Good", 48.8566f, 2.3522f }, - { 5, new DateOnly(2024, 2, 23), "Cycling", null, 48.8566f, 2.3522f } - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Activity"); - - migrationBuilder.DropTable( - name: "Athlete"); - - migrationBuilder.DropTable( - name: "DataSource"); - - migrationBuilder.DropTable( - name: "HeartRate"); - - migrationBuilder.DropTable( - name: "Notification"); - - migrationBuilder.DropTable( - name: "Statistic"); - - migrationBuilder.DropTable( - name: "Training"); - } - } -} diff --git a/src/StubbedContextLib/Migrations/20240222104952_MyMigrations.Designer.cs b/src/StubbedContextLib/Migrations/20240226170604_MyMigrations.Designer.cs similarity index 81% rename from src/StubbedContextLib/Migrations/20240222104952_MyMigrations.Designer.cs rename to src/StubbedContextLib/Migrations/20240226170604_MyMigrations.Designer.cs index 08cb864..25efb7d 100644 --- a/src/StubbedContextLib/Migrations/20240222104952_MyMigrations.Designer.cs +++ b/src/StubbedContextLib/Migrations/20240226170604_MyMigrations.Designer.cs @@ -11,7 +11,7 @@ using StubbedContextLib; namespace StubbedContextLib.Migrations { [DbContext(typeof(TrainingStubbedContext))] - [Migration("20240222104952_MyMigrations")] + [Migration("20240226170604_MyMigrations")] partial class MyMigrations { /// @@ -26,12 +26,18 @@ namespace StubbedContextLib.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("AthleteId") + .HasColumnType("INTEGER"); + b.Property("Average") .HasColumnType("REAL"); b.Property("AverageTemperature") .HasColumnType("REAL"); + b.Property("DataSourceId") + .HasColumnType("INTEGER"); + b.Property("Date") .HasColumnType("TEXT"); @@ -69,14 +75,20 @@ namespace StubbedContextLib.Migrations b.HasKey("IdActivity"); + b.HasIndex("AthleteId"); + + b.HasIndex("DataSourceId"); + b.ToTable("Activity"); b.HasData( new { IdActivity = 1, + AthleteId = 1, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 1, Date = new DateOnly(2023, 1, 10), EffortFelt = 5, EndTime = new TimeOnly(14, 0, 22), @@ -92,8 +104,10 @@ namespace StubbedContextLib.Migrations new { IdActivity = 2, + AthleteId = 2, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 2, Date = new DateOnly(2023, 1, 25), EffortFelt = 5, EndTime = new TimeOnly(14, 0, 22), @@ -109,8 +123,10 @@ namespace StubbedContextLib.Migrations new { IdActivity = 3, + AthleteId = 1, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 1, Date = new DateOnly(2023, 12, 10), EffortFelt = 5, EndTime = new TimeOnly(15, 2, 22), @@ -126,8 +142,10 @@ namespace StubbedContextLib.Migrations new { IdActivity = 4, + AthleteId = 5, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 3, Date = new DateOnly(2024, 1, 2), EffortFelt = 5, EndTime = new TimeOnly(16, 1, 55), @@ -143,8 +161,10 @@ namespace StubbedContextLib.Migrations new { IdActivity = 5, + AthleteId = 4, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 4, Date = new DateOnly(2024, 1, 12), EffortFelt = 5, EndTime = new TimeOnly(9, 0, 22), @@ -160,8 +180,10 @@ namespace StubbedContextLib.Migrations new { IdActivity = 6, + AthleteId = 4, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 4, Date = new DateOnly(2024, 1, 27), EffortFelt = 5, EndTime = new TimeOnly(14, 0, 22), @@ -177,8 +199,10 @@ namespace StubbedContextLib.Migrations new { IdActivity = 7, + AthleteId = 3, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 5, Date = new DateOnly(2024, 2, 22), EffortFelt = 5, EndTime = new TimeOnly(23, 50, 58), @@ -199,6 +223,9 @@ namespace StubbedContextLib.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("DataSourceId") + .HasColumnType("INTEGER"); + b.Property("DateOfBirth") .HasColumnType("TEXT"); @@ -242,6 +269,8 @@ namespace StubbedContextLib.Migrations b.HasKey("IdAthlete"); + b.HasIndex("DataSourceId"); + b.ToTable("Athlete"); b.HasData( @@ -262,6 +291,7 @@ namespace StubbedContextLib.Migrations new { IdAthlete = 2, + DataSourceId = 1, DateOfBirth = new DateOnly(1995, 1, 1), Email = "jane.smith@exemple.com", FirstName = "Jane", @@ -304,6 +334,7 @@ namespace StubbedContextLib.Migrations new { IdAthlete = 5, + DataSourceId = 3, DateOfBirth = new DateOnly(1991, 1, 1), Email = "bruce.lee@example.com", FirstName = "Bruce", @@ -384,6 +415,9 @@ namespace StubbedContextLib.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("ActivityId") + .HasColumnType("INTEGER"); + b.Property("Altitude") .HasColumnType("REAL"); @@ -404,12 +438,15 @@ namespace StubbedContextLib.Migrations b.HasKey("IdHeartRate"); + b.HasIndex("ActivityId"); + b.ToTable("HeartRate"); b.HasData( new { IdHeartRate = 1, + ActivityId = 1, Altitude = 0.0, Bpm = 60, Latitude = 66f, @@ -420,6 +457,7 @@ namespace StubbedContextLib.Migrations new { IdHeartRate = 2, + ActivityId = 2, Altitude = 10.0, Bpm = 65, Latitude = 67f, @@ -430,6 +468,7 @@ namespace StubbedContextLib.Migrations new { IdHeartRate = 3, + ActivityId = 1, Altitude = 11.0, Bpm = 71, Latitude = 66f, @@ -440,6 +479,7 @@ namespace StubbedContextLib.Migrations new { IdHeartRate = 4, + ActivityId = 2, Altitude = 12.0, Bpm = 75, Latitude = 67f, @@ -450,6 +490,7 @@ namespace StubbedContextLib.Migrations new { IdHeartRate = 5, + ActivityId = 4, Altitude = 13.0, Bpm = 80, Latitude = 66f, @@ -465,6 +506,9 @@ namespace StubbedContextLib.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("AthleteId") + .HasColumnType("INTEGER"); + b.Property("Date") .HasColumnType("TEXT"); @@ -483,12 +527,15 @@ namespace StubbedContextLib.Migrations b.HasKey("IdNotif"); + b.HasIndex("AthleteId"); + b.ToTable("Notification"); b.HasData( new { IdNotif = 1, + AthleteId = 1, Date = new DateTime(2023, 12, 25, 13, 0, 40, 0, DateTimeKind.Unspecified), Message = "You have a new activity to check", Statut = true, @@ -497,6 +544,7 @@ namespace StubbedContextLib.Migrations new { IdNotif = 2, + AthleteId = 2, Date = new DateTime(2023, 12, 26, 13, 10, 40, 0, DateTimeKind.Unspecified), Message = "You have a new athlete to check", Statut = false, @@ -505,6 +553,7 @@ namespace StubbedContextLib.Migrations new { IdNotif = 3, + AthleteId = 3, Date = new DateTime(2023, 12, 26, 16, 10, 4, 0, DateTimeKind.Unspecified), Message = "You have a new heart rate to check", Statut = true, @@ -513,6 +562,7 @@ namespace StubbedContextLib.Migrations new { IdNotif = 4, + AthleteId = 4, Date = new DateTime(2024, 1, 12, 9, 30, 50, 0, DateTimeKind.Unspecified), Message = "You have a new data source to check", Statut = false, @@ -521,6 +571,7 @@ namespace StubbedContextLib.Migrations new { IdNotif = 5, + AthleteId = 5, Date = new DateTime(2024, 2, 22, 12, 10, 0, 0, DateTimeKind.Unspecified), Message = "You have a new notification to check", Statut = true, @@ -534,6 +585,9 @@ namespace StubbedContextLib.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("AthleteId") + .HasColumnType("INTEGER"); + b.Property("AverageCaloriesBurned") .HasColumnType("REAL"); @@ -551,12 +605,15 @@ namespace StubbedContextLib.Migrations b.HasKey("IdStatistic"); + b.HasIndex("AthleteId"); + b.ToTable("Statistic"); b.HasData( new { IdStatistic = 1, + AthleteId = 1, AverageCaloriesBurned = 500.0, AverageHeartRate = 120.0, Date = new DateOnly(2021, 12, 12), @@ -566,6 +623,7 @@ namespace StubbedContextLib.Migrations new { IdStatistic = 2, + AthleteId = 2, AverageCaloriesBurned = 600.0, AverageHeartRate = 130.0, Date = new DateOnly(2021, 1, 11), @@ -575,6 +633,7 @@ namespace StubbedContextLib.Migrations new { IdStatistic = 3, + AthleteId = 1, AverageCaloriesBurned = 550.0, AverageHeartRate = 125.0, Date = new DateOnly(2022, 12, 30), @@ -584,6 +643,7 @@ namespace StubbedContextLib.Migrations new { IdStatistic = 4, + AthleteId = 3, AverageCaloriesBurned = 650.0, AverageHeartRate = 135.0, Date = new DateOnly(2023, 2, 20), @@ -593,6 +653,7 @@ namespace StubbedContextLib.Migrations new { IdStatistic = 5, + AthleteId = 4, AverageCaloriesBurned = 450.0, AverageHeartRate = 110.0, Date = new DateOnly(2024, 1, 10), @@ -607,6 +668,9 @@ namespace StubbedContextLib.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("AthleteId") + .HasColumnType("INTEGER"); + b.Property("Date") .HasColumnType("TEXT"); @@ -626,12 +690,15 @@ namespace StubbedContextLib.Migrations b.HasKey("IdTraining"); + b.HasIndex("AthleteId"); + b.ToTable("Training"); b.HasData( new { IdTraining = 1, + AthleteId = 1, Date = new DateOnly(2024, 1, 19), Description = "Running", FeedBack = "Good", @@ -641,6 +708,7 @@ namespace StubbedContextLib.Migrations new { IdTraining = 2, + AthleteId = 5, Date = new DateOnly(2024, 2, 20), Description = "Cycling", Latitude = 48.8566f, @@ -649,6 +717,7 @@ namespace StubbedContextLib.Migrations new { IdTraining = 3, + AthleteId = 4, Date = new DateOnly(2024, 2, 21), FeedBack = "Good", Latitude = 48.8566f, @@ -657,6 +726,7 @@ namespace StubbedContextLib.Migrations new { IdTraining = 4, + AthleteId = 3, Date = new DateOnly(2024, 2, 22), Description = "Running", FeedBack = "Good", @@ -666,12 +736,106 @@ namespace StubbedContextLib.Migrations new { IdTraining = 5, + AthleteId = 1, Date = new DateOnly(2024, 2, 23), Description = "Cycling", Latitude = 48.8566f, Longitude = 2.3522f }); }); + + modelBuilder.Entity("Entities.ActivityEntity", b => + { + b.HasOne("Entities.AthleteEntity", "Athlete") + .WithMany("Activities") + .HasForeignKey("AthleteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entities.DataSourceEntity", "DataSource") + .WithMany("Activities") + .HasForeignKey("DataSourceId"); + + b.Navigation("Athlete"); + + b.Navigation("DataSource"); + }); + + modelBuilder.Entity("Entities.AthleteEntity", b => + { + b.HasOne("Entities.DataSourceEntity", "DataSource") + .WithMany("Athletes") + .HasForeignKey("DataSourceId"); + + b.Navigation("DataSource"); + }); + + modelBuilder.Entity("Entities.HeartRateEntity", b => + { + b.HasOne("Entities.ActivityEntity", "Activity") + .WithMany("HeartRates") + .HasForeignKey("ActivityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Activity"); + }); + + modelBuilder.Entity("Entities.NotificationEntity", b => + { + b.HasOne("Entities.AthleteEntity", "Athlete") + .WithMany("Notifications") + .HasForeignKey("AthleteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Athlete"); + }); + + modelBuilder.Entity("Entities.StatisticEntity", b => + { + b.HasOne("Entities.AthleteEntity", "Athlete") + .WithMany("Statistics") + .HasForeignKey("AthleteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Athlete"); + }); + + modelBuilder.Entity("Entities.TrainingEntity", b => + { + b.HasOne("Entities.AthleteEntity", "Athlete") + .WithMany("Trainings") + .HasForeignKey("AthleteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Athlete"); + }); + + modelBuilder.Entity("Entities.ActivityEntity", b => + { + b.Navigation("HeartRates"); + }); + + modelBuilder.Entity("Entities.AthleteEntity", b => + { + b.Navigation("Activities"); + + b.Navigation("Notifications"); + + b.Navigation("Statistics"); + + b.Navigation("Trainings"); + }); + + modelBuilder.Entity("Entities.DataSourceEntity", b => + { + b.Navigation("Activities"); + + b.Navigation("Athletes"); + }); #pragma warning restore 612, 618 } } diff --git a/src/StubbedContextLib/Migrations/20240226170604_MyMigrations.cs b/src/StubbedContextLib/Migrations/20240226170604_MyMigrations.cs new file mode 100644 index 0000000..2473ddc --- /dev/null +++ b/src/StubbedContextLib/Migrations/20240226170604_MyMigrations.cs @@ -0,0 +1,376 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional + +namespace StubbedContextLib.Migrations +{ + /// + public partial class MyMigrations : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "DataSource", + columns: table => new + { + IdSource = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Type = table.Column(type: "TEXT", maxLength: 100, nullable: false), + Model = table.Column(type: "TEXT", maxLength: 100, nullable: false), + Precision = table.Column(type: "REAL", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_DataSource", x => x.IdSource); + }); + + migrationBuilder.CreateTable( + name: "Athlete", + columns: table => new + { + IdAthlete = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Username = table.Column(type: "TEXT", maxLength: 100, nullable: false), + LastName = table.Column(type: "TEXT", maxLength: 100, nullable: false), + FirstName = table.Column(type: "TEXT", maxLength: 150, nullable: false), + Email = table.Column(type: "TEXT", maxLength: 100, nullable: false), + Sexe = table.Column(type: "TEXT", maxLength: 1, nullable: false), + Length = table.Column(type: "REAL", nullable: false), + Weight = table.Column(type: "REAL", nullable: false), + Password = table.Column(type: "TEXT", nullable: false), + DateOfBirth = table.Column(type: "TEXT", nullable: false), + IsCoach = table.Column(type: "INTEGER", nullable: false), + DataSourceId = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Athlete", x => x.IdAthlete); + table.ForeignKey( + name: "FK_Athlete_DataSource_DataSourceId", + column: x => x.DataSourceId, + principalTable: "DataSource", + principalColumn: "IdSource"); + }); + + migrationBuilder.CreateTable( + name: "Activity", + columns: table => new + { + IdActivity = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Type = table.Column(type: "TEXT", maxLength: 100, nullable: false), + Date = table.Column(type: "TEXT", nullable: false), + StartTime = table.Column(type: "TEXT", nullable: false), + EndTime = table.Column(type: "TEXT", nullable: false), + EffortFelt = table.Column(type: "INTEGER", nullable: false), + Variability = table.Column(type: "REAL", nullable: false), + Variance = table.Column(type: "REAL", nullable: false), + StandardDeviation = table.Column(type: "REAL", nullable: false), + Average = table.Column(type: "REAL", nullable: false), + Maximum = table.Column(type: "INTEGER", nullable: false), + Minimum = table.Column(type: "INTEGER", nullable: false), + AverageTemperature = table.Column(type: "REAL", nullable: false), + HasAutoPause = table.Column(type: "INTEGER", nullable: false), + DataSourceId = table.Column(type: "INTEGER", nullable: false), + AthleteId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Activity", x => x.IdActivity); + table.ForeignKey( + name: "FK_Activity_Athlete_AthleteId", + column: x => x.AthleteId, + principalTable: "Athlete", + principalColumn: "IdAthlete", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Activity_DataSource_DataSourceId", + column: x => x.DataSourceId, + principalTable: "DataSource", + principalColumn: "IdSource"); + }); + + migrationBuilder.CreateTable( + name: "Notification", + columns: table => new + { + IdNotif = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Message = table.Column(type: "TEXT", maxLength: 100, nullable: false), + Date = table.Column(type: "TEXT", nullable: false), + Statut = table.Column(type: "INTEGER", nullable: false), + Urgence = table.Column(type: "TEXT", maxLength: 100, nullable: false), + AthleteId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Notification", x => x.IdNotif); + table.ForeignKey( + name: "FK_Notification_Athlete_AthleteId", + column: x => x.AthleteId, + principalTable: "Athlete", + principalColumn: "IdAthlete", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Statistic", + columns: table => new + { + IdStatistic = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Weight = table.Column(type: "REAL", nullable: false), + AverageHeartRate = table.Column(type: "REAL", nullable: false), + MaximumHeartRate = table.Column(type: "REAL", nullable: false), + AverageCaloriesBurned = table.Column(type: "REAL", nullable: false), + Date = table.Column(type: "TEXT", nullable: false), + AthleteId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Statistic", x => x.IdStatistic); + table.ForeignKey( + name: "FK_Statistic_Athlete_AthleteId", + column: x => x.AthleteId, + principalTable: "Athlete", + principalColumn: "IdAthlete", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Training", + columns: table => new + { + IdTraining = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Date = table.Column(type: "TEXT", nullable: false), + Description = table.Column(type: "TEXT", maxLength: 300, nullable: true), + Latitude = table.Column(type: "REAL", nullable: false), + Longitude = table.Column(type: "REAL", nullable: false), + FeedBack = table.Column(type: "TEXT", maxLength: 300, nullable: true), + AthleteId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Training", x => x.IdTraining); + table.ForeignKey( + name: "FK_Training_Athlete_AthleteId", + column: x => x.AthleteId, + principalTable: "Athlete", + principalColumn: "IdAthlete", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "HeartRate", + columns: table => new + { + IdHeartRate = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Altitude = table.Column(type: "REAL", nullable: false), + Time = table.Column(type: "TEXT", nullable: false), + Temperature = table.Column(type: "REAL", nullable: false), + Bpm = table.Column(type: "INTEGER", nullable: false), + Longitude = table.Column(type: "REAL", nullable: false), + Latitude = table.Column(type: "REAL", nullable: false), + ActivityId = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_HeartRate", x => x.IdHeartRate); + table.ForeignKey( + name: "FK_HeartRate_Activity_ActivityId", + column: x => x.ActivityId, + principalTable: "Activity", + principalColumn: "IdActivity", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.InsertData( + table: "Athlete", + columns: new[] { "IdAthlete", "DataSourceId", "DateOfBirth", "Email", "FirstName", "IsCoach", "LastName", "Length", "Password", "Sexe", "Username", "Weight" }, + values: new object[,] + { + { 1, null, new DateOnly(1990, 1, 1), "john.doe@example.com", "John", true, "Doe", 1.8, "password123", "M", "Doe", 75f }, + { 3, null, new DateOnly(1992, 1, 1), "paul.martin@example.com", "Paul", true, "Martin", 1.75, "super789", "M", "Martin", 68f }, + { 4, null, new DateOnly(1993, 1, 1), "anna.brown@example.com", "Anna", false, "Brown", 1.7, "test000", "F", "Brown", 58f } + }); + + migrationBuilder.InsertData( + table: "DataSource", + columns: new[] { "IdSource", "Model", "Precision", "Type" }, + values: new object[,] + { + { 1, "Garmin", 0.5f, "Smartwatch" }, + { 2, "Polar", 0.5f, "Smartwatch" }, + { 3, "Suunto", 0.5f, "Smartwatch" }, + { 4, "Fitbit", 0.5f, "Smartwatch" }, + { 5, "Apple Watch", 0.5f, "Smartwatch" } + }); + + migrationBuilder.InsertData( + table: "Activity", + columns: new[] { "IdActivity", "AthleteId", "Average", "AverageTemperature", "DataSourceId", "Date", "EffortFelt", "EndTime", "HasAutoPause", "Maximum", "Minimum", "StandardDeviation", "StartTime", "Type", "Variability", "Variance" }, + values: new object[,] + { + { 1, 1, 0.5f, 20f, 1, new DateOnly(2023, 1, 10), 5, new TimeOnly(14, 0, 22), false, 0, 0, 0.5f, new TimeOnly(13, 0, 34), "Running", 0.5f, 0.5f }, + { 3, 1, 0.5f, 20f, 1, new DateOnly(2023, 12, 10), 5, new TimeOnly(15, 2, 22), false, 0, 0, 0.5f, new TimeOnly(13, 30, 34), "Swimming", 0.5f, 0.5f }, + { 5, 4, 0.5f, 20f, 4, new DateOnly(2024, 1, 12), 5, new TimeOnly(9, 0, 22), false, 0, 0, 0.5f, new TimeOnly(7, 45, 34), "Hiking", 0.5f, 0.5f }, + { 6, 4, 0.5f, 20f, 4, new DateOnly(2024, 1, 27), 5, new TimeOnly(14, 0, 22), false, 0, 0, 0.5f, new TimeOnly(13, 30, 1), "Climbing", 0.5f, 0.5f }, + { 7, 3, 0.5f, 20f, 5, new DateOnly(2024, 2, 22), 5, new TimeOnly(23, 50, 58), false, 0, 0, 0.5f, new TimeOnly(22, 0, 34), "Yoga", 0.5f, 0.5f } + }); + + migrationBuilder.InsertData( + table: "Athlete", + columns: new[] { "IdAthlete", "DataSourceId", "DateOfBirth", "Email", "FirstName", "IsCoach", "LastName", "Length", "Password", "Sexe", "Username", "Weight" }, + values: new object[,] + { + { 2, 1, new DateOnly(1995, 1, 1), "jane.smith@exemple.com", "Jane", false, "Smith", 1.6499999999999999, "secure456", "F", "Smith", 60f }, + { 5, 3, new DateOnly(1991, 1, 1), "bruce.lee@example.com", "Bruce", false, "Lee", 2.0, "hello321", "M", "Lee", 90f } + }); + + migrationBuilder.InsertData( + table: "Notification", + columns: new[] { "IdNotif", "AthleteId", "Date", "Message", "Statut", "Urgence" }, + values: new object[,] + { + { 1, 1, new DateTime(2023, 12, 25, 13, 0, 40, 0, DateTimeKind.Unspecified), "You have a new activity to check", true, "A" }, + { 3, 3, new DateTime(2023, 12, 26, 16, 10, 4, 0, DateTimeKind.Unspecified), "You have a new heart rate to check", true, "2" }, + { 4, 4, new DateTime(2024, 1, 12, 9, 30, 50, 0, DateTimeKind.Unspecified), "You have a new data source to check", false, "1" } + }); + + migrationBuilder.InsertData( + table: "Statistic", + columns: new[] { "IdStatistic", "AthleteId", "AverageCaloriesBurned", "AverageHeartRate", "Date", "MaximumHeartRate", "Weight" }, + values: new object[,] + { + { 1, 1, 500.0, 120.0, new DateOnly(2021, 12, 12), 180.0, 75f }, + { 3, 1, 550.0, 125.0, new DateOnly(2022, 12, 30), 185.0, 68f }, + { 4, 3, 650.0, 135.0, new DateOnly(2023, 2, 20), 195.0, 58f }, + { 5, 4, 450.0, 110.0, new DateOnly(2024, 1, 10), 170.0, 90f } + }); + + migrationBuilder.InsertData( + table: "Training", + columns: new[] { "IdTraining", "AthleteId", "Date", "Description", "FeedBack", "Latitude", "Longitude" }, + values: new object[,] + { + { 1, 1, new DateOnly(2024, 1, 19), "Running", "Good", 48.8566f, 2.3522f }, + { 3, 4, new DateOnly(2024, 2, 21), null, "Good", 48.8566f, 2.3522f }, + { 4, 3, new DateOnly(2024, 2, 22), "Running", "Good", 48.8566f, 2.3522f }, + { 5, 1, new DateOnly(2024, 2, 23), "Cycling", null, 48.8566f, 2.3522f } + }); + + migrationBuilder.InsertData( + table: "Activity", + columns: new[] { "IdActivity", "AthleteId", "Average", "AverageTemperature", "DataSourceId", "Date", "EffortFelt", "EndTime", "HasAutoPause", "Maximum", "Minimum", "StandardDeviation", "StartTime", "Type", "Variability", "Variance" }, + values: new object[,] + { + { 2, 2, 0.5f, 20f, 2, new DateOnly(2023, 1, 25), 5, new TimeOnly(14, 0, 22), false, 0, 0, 0.5f, new TimeOnly(13, 4, 34), "Cycling", 0.5f, 0.5f }, + { 4, 5, 0.5f, 20f, 3, new DateOnly(2024, 1, 2), 5, new TimeOnly(16, 1, 55), false, 0, 0, 0.5f, new TimeOnly(15, 0, 0), "Walking", 0.5f, 0.5f } + }); + + migrationBuilder.InsertData( + table: "HeartRate", + columns: new[] { "IdHeartRate", "ActivityId", "Altitude", "Bpm", "Latitude", "Longitude", "Temperature", "Time" }, + values: new object[,] + { + { 1, 1, 0.0, 60, 66f, 35f, 20f, new TimeOnly(13, 0, 30) }, + { 3, 1, 11.0, 71, 66f, 36f, 20f, new TimeOnly(13, 0, 32) } + }); + + migrationBuilder.InsertData( + table: "Notification", + columns: new[] { "IdNotif", "AthleteId", "Date", "Message", "Statut", "Urgence" }, + values: new object[,] + { + { 2, 2, new DateTime(2023, 12, 26, 13, 10, 40, 0, DateTimeKind.Unspecified), "You have a new athlete to check", false, "3" }, + { 5, 5, new DateTime(2024, 2, 22, 12, 10, 0, 0, DateTimeKind.Unspecified), "You have a new notification to check", true, "3" } + }); + + migrationBuilder.InsertData( + table: "Statistic", + columns: new[] { "IdStatistic", "AthleteId", "AverageCaloriesBurned", "AverageHeartRate", "Date", "MaximumHeartRate", "Weight" }, + values: new object[] { 2, 2, 600.0, 130.0, new DateOnly(2021, 1, 11), 190.0, 60f }); + + migrationBuilder.InsertData( + table: "Training", + columns: new[] { "IdTraining", "AthleteId", "Date", "Description", "FeedBack", "Latitude", "Longitude" }, + values: new object[] { 2, 5, new DateOnly(2024, 2, 20), "Cycling", null, 48.8566f, 2.3522f }); + + migrationBuilder.InsertData( + table: "HeartRate", + columns: new[] { "IdHeartRate", "ActivityId", "Altitude", "Bpm", "Latitude", "Longitude", "Temperature", "Time" }, + values: new object[,] + { + { 2, 2, 10.0, 65, 67f, 35f, 20.5f, new TimeOnly(13, 0, 31) }, + { 4, 2, 12.0, 75, 67f, 36f, 20.5f, new TimeOnly(13, 0, 33) }, + { 5, 4, 13.0, 80, 66f, 37f, 20f, new TimeOnly(13, 0, 34) } + }); + + migrationBuilder.CreateIndex( + name: "IX_Activity_AthleteId", + table: "Activity", + column: "AthleteId"); + + migrationBuilder.CreateIndex( + name: "IX_Activity_DataSourceId", + table: "Activity", + column: "DataSourceId"); + + migrationBuilder.CreateIndex( + name: "IX_Athlete_DataSourceId", + table: "Athlete", + column: "DataSourceId"); + + migrationBuilder.CreateIndex( + name: "IX_HeartRate_ActivityId", + table: "HeartRate", + column: "ActivityId"); + + migrationBuilder.CreateIndex( + name: "IX_Notification_AthleteId", + table: "Notification", + column: "AthleteId"); + + migrationBuilder.CreateIndex( + name: "IX_Statistic_AthleteId", + table: "Statistic", + column: "AthleteId"); + + migrationBuilder.CreateIndex( + name: "IX_Training_AthleteId", + table: "Training", + column: "AthleteId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "HeartRate"); + + migrationBuilder.DropTable( + name: "Notification"); + + migrationBuilder.DropTable( + name: "Statistic"); + + migrationBuilder.DropTable( + name: "Training"); + + migrationBuilder.DropTable( + name: "Activity"); + + migrationBuilder.DropTable( + name: "Athlete"); + + migrationBuilder.DropTable( + name: "DataSource"); + } + } +} diff --git a/src/StubbedContextLib/Migrations/TrainingStubbedContextModelSnapshot.cs b/src/StubbedContextLib/Migrations/TrainingStubbedContextModelSnapshot.cs index cbca83e..d1047be 100644 --- a/src/StubbedContextLib/Migrations/TrainingStubbedContextModelSnapshot.cs +++ b/src/StubbedContextLib/Migrations/TrainingStubbedContextModelSnapshot.cs @@ -23,12 +23,18 @@ namespace StubbedContextLib.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("AthleteId") + .HasColumnType("INTEGER"); + b.Property("Average") .HasColumnType("REAL"); b.Property("AverageTemperature") .HasColumnType("REAL"); + b.Property("DataSourceId") + .HasColumnType("INTEGER"); + b.Property("Date") .HasColumnType("TEXT"); @@ -66,14 +72,20 @@ namespace StubbedContextLib.Migrations b.HasKey("IdActivity"); + b.HasIndex("AthleteId"); + + b.HasIndex("DataSourceId"); + b.ToTable("Activity"); b.HasData( new { IdActivity = 1, + AthleteId = 1, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 1, Date = new DateOnly(2023, 1, 10), EffortFelt = 5, EndTime = new TimeOnly(14, 0, 22), @@ -89,8 +101,10 @@ namespace StubbedContextLib.Migrations new { IdActivity = 2, + AthleteId = 2, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 2, Date = new DateOnly(2023, 1, 25), EffortFelt = 5, EndTime = new TimeOnly(14, 0, 22), @@ -106,8 +120,10 @@ namespace StubbedContextLib.Migrations new { IdActivity = 3, + AthleteId = 1, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 1, Date = new DateOnly(2023, 12, 10), EffortFelt = 5, EndTime = new TimeOnly(15, 2, 22), @@ -123,8 +139,10 @@ namespace StubbedContextLib.Migrations new { IdActivity = 4, + AthleteId = 5, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 3, Date = new DateOnly(2024, 1, 2), EffortFelt = 5, EndTime = new TimeOnly(16, 1, 55), @@ -140,8 +158,10 @@ namespace StubbedContextLib.Migrations new { IdActivity = 5, + AthleteId = 4, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 4, Date = new DateOnly(2024, 1, 12), EffortFelt = 5, EndTime = new TimeOnly(9, 0, 22), @@ -157,8 +177,10 @@ namespace StubbedContextLib.Migrations new { IdActivity = 6, + AthleteId = 4, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 4, Date = new DateOnly(2024, 1, 27), EffortFelt = 5, EndTime = new TimeOnly(14, 0, 22), @@ -174,8 +196,10 @@ namespace StubbedContextLib.Migrations new { IdActivity = 7, + AthleteId = 3, Average = 0.5f, AverageTemperature = 20f, + DataSourceId = 5, Date = new DateOnly(2024, 2, 22), EffortFelt = 5, EndTime = new TimeOnly(23, 50, 58), @@ -196,6 +220,9 @@ namespace StubbedContextLib.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("DataSourceId") + .HasColumnType("INTEGER"); + b.Property("DateOfBirth") .HasColumnType("TEXT"); @@ -239,6 +266,8 @@ namespace StubbedContextLib.Migrations b.HasKey("IdAthlete"); + b.HasIndex("DataSourceId"); + b.ToTable("Athlete"); b.HasData( @@ -259,6 +288,7 @@ namespace StubbedContextLib.Migrations new { IdAthlete = 2, + DataSourceId = 1, DateOfBirth = new DateOnly(1995, 1, 1), Email = "jane.smith@exemple.com", FirstName = "Jane", @@ -301,6 +331,7 @@ namespace StubbedContextLib.Migrations new { IdAthlete = 5, + DataSourceId = 3, DateOfBirth = new DateOnly(1991, 1, 1), Email = "bruce.lee@example.com", FirstName = "Bruce", @@ -381,6 +412,9 @@ namespace StubbedContextLib.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("ActivityId") + .HasColumnType("INTEGER"); + b.Property("Altitude") .HasColumnType("REAL"); @@ -401,12 +435,15 @@ namespace StubbedContextLib.Migrations b.HasKey("IdHeartRate"); + b.HasIndex("ActivityId"); + b.ToTable("HeartRate"); b.HasData( new { IdHeartRate = 1, + ActivityId = 1, Altitude = 0.0, Bpm = 60, Latitude = 66f, @@ -417,6 +454,7 @@ namespace StubbedContextLib.Migrations new { IdHeartRate = 2, + ActivityId = 2, Altitude = 10.0, Bpm = 65, Latitude = 67f, @@ -427,6 +465,7 @@ namespace StubbedContextLib.Migrations new { IdHeartRate = 3, + ActivityId = 1, Altitude = 11.0, Bpm = 71, Latitude = 66f, @@ -437,6 +476,7 @@ namespace StubbedContextLib.Migrations new { IdHeartRate = 4, + ActivityId = 2, Altitude = 12.0, Bpm = 75, Latitude = 67f, @@ -447,6 +487,7 @@ namespace StubbedContextLib.Migrations new { IdHeartRate = 5, + ActivityId = 4, Altitude = 13.0, Bpm = 80, Latitude = 66f, @@ -462,6 +503,9 @@ namespace StubbedContextLib.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("AthleteId") + .HasColumnType("INTEGER"); + b.Property("Date") .HasColumnType("TEXT"); @@ -480,12 +524,15 @@ namespace StubbedContextLib.Migrations b.HasKey("IdNotif"); + b.HasIndex("AthleteId"); + b.ToTable("Notification"); b.HasData( new { IdNotif = 1, + AthleteId = 1, Date = new DateTime(2023, 12, 25, 13, 0, 40, 0, DateTimeKind.Unspecified), Message = "You have a new activity to check", Statut = true, @@ -494,6 +541,7 @@ namespace StubbedContextLib.Migrations new { IdNotif = 2, + AthleteId = 2, Date = new DateTime(2023, 12, 26, 13, 10, 40, 0, DateTimeKind.Unspecified), Message = "You have a new athlete to check", Statut = false, @@ -502,6 +550,7 @@ namespace StubbedContextLib.Migrations new { IdNotif = 3, + AthleteId = 3, Date = new DateTime(2023, 12, 26, 16, 10, 4, 0, DateTimeKind.Unspecified), Message = "You have a new heart rate to check", Statut = true, @@ -510,6 +559,7 @@ namespace StubbedContextLib.Migrations new { IdNotif = 4, + AthleteId = 4, Date = new DateTime(2024, 1, 12, 9, 30, 50, 0, DateTimeKind.Unspecified), Message = "You have a new data source to check", Statut = false, @@ -518,6 +568,7 @@ namespace StubbedContextLib.Migrations new { IdNotif = 5, + AthleteId = 5, Date = new DateTime(2024, 2, 22, 12, 10, 0, 0, DateTimeKind.Unspecified), Message = "You have a new notification to check", Statut = true, @@ -531,6 +582,9 @@ namespace StubbedContextLib.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("AthleteId") + .HasColumnType("INTEGER"); + b.Property("AverageCaloriesBurned") .HasColumnType("REAL"); @@ -548,12 +602,15 @@ namespace StubbedContextLib.Migrations b.HasKey("IdStatistic"); + b.HasIndex("AthleteId"); + b.ToTable("Statistic"); b.HasData( new { IdStatistic = 1, + AthleteId = 1, AverageCaloriesBurned = 500.0, AverageHeartRate = 120.0, Date = new DateOnly(2021, 12, 12), @@ -563,6 +620,7 @@ namespace StubbedContextLib.Migrations new { IdStatistic = 2, + AthleteId = 2, AverageCaloriesBurned = 600.0, AverageHeartRate = 130.0, Date = new DateOnly(2021, 1, 11), @@ -572,6 +630,7 @@ namespace StubbedContextLib.Migrations new { IdStatistic = 3, + AthleteId = 1, AverageCaloriesBurned = 550.0, AverageHeartRate = 125.0, Date = new DateOnly(2022, 12, 30), @@ -581,6 +640,7 @@ namespace StubbedContextLib.Migrations new { IdStatistic = 4, + AthleteId = 3, AverageCaloriesBurned = 650.0, AverageHeartRate = 135.0, Date = new DateOnly(2023, 2, 20), @@ -590,6 +650,7 @@ namespace StubbedContextLib.Migrations new { IdStatistic = 5, + AthleteId = 4, AverageCaloriesBurned = 450.0, AverageHeartRate = 110.0, Date = new DateOnly(2024, 1, 10), @@ -604,6 +665,9 @@ namespace StubbedContextLib.Migrations .ValueGeneratedOnAdd() .HasColumnType("INTEGER"); + b.Property("AthleteId") + .HasColumnType("INTEGER"); + b.Property("Date") .HasColumnType("TEXT"); @@ -623,12 +687,15 @@ namespace StubbedContextLib.Migrations b.HasKey("IdTraining"); + b.HasIndex("AthleteId"); + b.ToTable("Training"); b.HasData( new { IdTraining = 1, + AthleteId = 1, Date = new DateOnly(2024, 1, 19), Description = "Running", FeedBack = "Good", @@ -638,6 +705,7 @@ namespace StubbedContextLib.Migrations new { IdTraining = 2, + AthleteId = 5, Date = new DateOnly(2024, 2, 20), Description = "Cycling", Latitude = 48.8566f, @@ -646,6 +714,7 @@ namespace StubbedContextLib.Migrations new { IdTraining = 3, + AthleteId = 4, Date = new DateOnly(2024, 2, 21), FeedBack = "Good", Latitude = 48.8566f, @@ -654,6 +723,7 @@ namespace StubbedContextLib.Migrations new { IdTraining = 4, + AthleteId = 3, Date = new DateOnly(2024, 2, 22), Description = "Running", FeedBack = "Good", @@ -663,12 +733,106 @@ namespace StubbedContextLib.Migrations new { IdTraining = 5, + AthleteId = 1, Date = new DateOnly(2024, 2, 23), Description = "Cycling", Latitude = 48.8566f, Longitude = 2.3522f }); }); + + modelBuilder.Entity("Entities.ActivityEntity", b => + { + b.HasOne("Entities.AthleteEntity", "Athlete") + .WithMany("Activities") + .HasForeignKey("AthleteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Entities.DataSourceEntity", "DataSource") + .WithMany("Activities") + .HasForeignKey("DataSourceId"); + + b.Navigation("Athlete"); + + b.Navigation("DataSource"); + }); + + modelBuilder.Entity("Entities.AthleteEntity", b => + { + b.HasOne("Entities.DataSourceEntity", "DataSource") + .WithMany("Athletes") + .HasForeignKey("DataSourceId"); + + b.Navigation("DataSource"); + }); + + modelBuilder.Entity("Entities.HeartRateEntity", b => + { + b.HasOne("Entities.ActivityEntity", "Activity") + .WithMany("HeartRates") + .HasForeignKey("ActivityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Activity"); + }); + + modelBuilder.Entity("Entities.NotificationEntity", b => + { + b.HasOne("Entities.AthleteEntity", "Athlete") + .WithMany("Notifications") + .HasForeignKey("AthleteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Athlete"); + }); + + modelBuilder.Entity("Entities.StatisticEntity", b => + { + b.HasOne("Entities.AthleteEntity", "Athlete") + .WithMany("Statistics") + .HasForeignKey("AthleteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Athlete"); + }); + + modelBuilder.Entity("Entities.TrainingEntity", b => + { + b.HasOne("Entities.AthleteEntity", "Athlete") + .WithMany("Trainings") + .HasForeignKey("AthleteId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Athlete"); + }); + + modelBuilder.Entity("Entities.ActivityEntity", b => + { + b.Navigation("HeartRates"); + }); + + modelBuilder.Entity("Entities.AthleteEntity", b => + { + b.Navigation("Activities"); + + b.Navigation("Notifications"); + + b.Navigation("Statistics"); + + b.Navigation("Trainings"); + }); + + modelBuilder.Entity("Entities.DataSourceEntity", b => + { + b.Navigation("Activities"); + + b.Navigation("Athletes"); + }); #pragma warning restore 612, 618 } } diff --git a/src/StubbedContextLib/NotificationStubbedContext.cs b/src/StubbedContextLib/NotificationStubbedContext.cs index ce55815..6a15a4f 100644 --- a/src/StubbedContextLib/NotificationStubbedContext.cs +++ b/src/StubbedContextLib/NotificationStubbedContext.cs @@ -37,11 +37,11 @@ namespace StubbedContextLib base.OnModelCreating(modelBuilder); modelBuilder.Entity().HasData( - new NotificationEntity { IdNotif = 1, Message = "You have a new activity to check", Date = new DateTime(2023, 12, 25, 13, 00, 40), Statut = true, Urgence = "A" }, - new NotificationEntity { IdNotif = 2, Message = "You have a new athlete to check", Date = new DateTime(2023, 12, 26, 13, 10, 40), Statut = false, Urgence = "3" }, - new NotificationEntity { IdNotif = 3, Message = "You have a new heart rate to check", Date = new DateTime(2023, 12, 26, 16, 10, 04), Statut = true, Urgence = "2" }, - new NotificationEntity { IdNotif = 4, Message = "You have a new data source to check", Date = new DateTime(2024, 01, 12, 09, 30, 50), Statut = false, Urgence = "1" }, - new NotificationEntity { IdNotif = 5, Message = "You have a new notification to check", Date = new DateTime(2024, 02, 22, 12, 10, 00), Statut = true, Urgence = "3" } + new NotificationEntity { IdNotif = 1, Message = "You have a new activity to check", Date = new DateTime(2023, 12, 25, 13, 00, 40), Statut = true, Urgence = "A", AthleteId = 1 }, + new NotificationEntity { IdNotif = 2, Message = "You have a new athlete to check", Date = new DateTime(2023, 12, 26, 13, 10, 40), Statut = false, Urgence = "3", AthleteId = 2 }, + new NotificationEntity { IdNotif = 3, Message = "You have a new heart rate to check", Date = new DateTime(2023, 12, 26, 16, 10, 04), Statut = true, Urgence = "2", AthleteId = 3 }, + new NotificationEntity { IdNotif = 4, Message = "You have a new data source to check", Date = new DateTime(2024, 01, 12, 09, 30, 50), Statut = false, Urgence = "1", AthleteId = 4 }, + new NotificationEntity { IdNotif = 5, Message = "You have a new notification to check", Date = new DateTime(2024, 02, 22, 12, 10, 00), Statut = true, Urgence = "3", AthleteId = 5 } ); } } diff --git a/src/StubbedContextLib/StatisticStubbedContext.cs b/src/StubbedContextLib/StatisticStubbedContext.cs index d4a3ae7..a1733c9 100644 --- a/src/StubbedContextLib/StatisticStubbedContext.cs +++ b/src/StubbedContextLib/StatisticStubbedContext.cs @@ -37,11 +37,11 @@ namespace StubbedContextLib base.OnModelCreating(modelBuilder); modelBuilder.Entity().HasData( - new StatisticEntity { IdStatistic = 1, Weight = 75, AverageHeartRate = 120, MaximumHeartRate = 180, AverageCaloriesBurned = 500, Date = new DateOnly(2021, 12, 12) }, - new StatisticEntity { IdStatistic = 2, Weight = 60, AverageHeartRate = 130, MaximumHeartRate = 190, AverageCaloriesBurned = 600, Date = new DateOnly(2021, 01, 11) }, - new StatisticEntity { IdStatistic = 3, Weight = 68, AverageHeartRate = 125, MaximumHeartRate = 185, AverageCaloriesBurned = 550, Date = new DateOnly(2022, 12, 30) }, - new StatisticEntity { IdStatistic = 4, Weight = 58, AverageHeartRate = 135, MaximumHeartRate = 195, AverageCaloriesBurned = 650, Date = new DateOnly(2023, 02, 20) }, - new StatisticEntity { IdStatistic = 5, Weight = 90, AverageHeartRate = 110, MaximumHeartRate = 170, AverageCaloriesBurned = 450, Date = new DateOnly(2024, 01, 10) } + new StatisticEntity { IdStatistic = 1, Weight = 75, AverageHeartRate = 120, MaximumHeartRate = 180, AverageCaloriesBurned = 500, Date = new DateOnly(2021, 12, 12), AthleteId = 1 }, + new StatisticEntity { IdStatistic = 2, Weight = 60, AverageHeartRate = 130, MaximumHeartRate = 190, AverageCaloriesBurned = 600, Date = new DateOnly(2021, 01, 11), AthleteId = 2 }, + new StatisticEntity { IdStatistic = 3, Weight = 68, AverageHeartRate = 125, MaximumHeartRate = 185, AverageCaloriesBurned = 550, Date = new DateOnly(2022, 12, 30), AthleteId = 1 }, + new StatisticEntity { IdStatistic = 4, Weight = 58, AverageHeartRate = 135, MaximumHeartRate = 195, AverageCaloriesBurned = 650, Date = new DateOnly(2023, 02, 20), AthleteId = 3 }, + new StatisticEntity { IdStatistic = 5, Weight = 90, AverageHeartRate = 110, MaximumHeartRate = 170, AverageCaloriesBurned = 450, Date = new DateOnly(2024, 01, 10), AthleteId = 4 } ); } } diff --git a/src/StubbedContextLib/TrainingStubbedContext.cs b/src/StubbedContextLib/TrainingStubbedContext.cs index 6bc7cfe..389ed6e 100644 --- a/src/StubbedContextLib/TrainingStubbedContext.cs +++ b/src/StubbedContextLib/TrainingStubbedContext.cs @@ -37,11 +37,11 @@ namespace StubbedContextLib base.OnModelCreating(modelBuilder); modelBuilder.Entity().HasData( - new TrainingEntity { IdTraining = 1, Date = new DateOnly(2024, 01, 19), Description = "Running", Latitude = 48.8566f, Longitude = 2.3522f, FeedBack = "Good" }, - new TrainingEntity { IdTraining = 2, Date = new DateOnly(2024, 02, 20), Description = "Cycling", Latitude = 48.8566f, Longitude = 2.3522f }, - new TrainingEntity { IdTraining = 3, Date = new DateOnly(2024, 02, 21), Latitude = 48.8566f, Longitude = 2.3522f, FeedBack = "Good" }, - new TrainingEntity { IdTraining = 4, Date = new DateOnly(2024, 02, 22), Description = "Running", Latitude = 48.8566f, Longitude = 2.3522f, FeedBack = "Good" }, - new TrainingEntity { IdTraining = 5, Date = new DateOnly(2024, 02, 23), Description = "Cycling", Latitude = 48.8566f, Longitude = 2.3522f } + new TrainingEntity { IdTraining = 1, Date = new DateOnly(2024, 01, 19), Description = "Running", Latitude = 48.8566f, Longitude = 2.3522f, FeedBack = "Good", AthleteId = 1 }, + new TrainingEntity { IdTraining = 2, Date = new DateOnly(2024, 02, 20), Description = "Cycling", Latitude = 48.8566f, Longitude = 2.3522f, AthleteId = 5 }, + new TrainingEntity { IdTraining = 3, Date = new DateOnly(2024, 02, 21), Latitude = 48.8566f, Longitude = 2.3522f, FeedBack = "Good", AthleteId = 4 }, + new TrainingEntity { IdTraining = 4, Date = new DateOnly(2024, 02, 22), Description = "Running", Latitude = 48.8566f, Longitude = 2.3522f, FeedBack = "Good", AthleteId = 3 }, + new TrainingEntity { IdTraining = 5, Date = new DateOnly(2024, 02, 23), Description = "Cycling", Latitude = 48.8566f, Longitude = 2.3522f, AthleteId = 1 } ); } } diff --git a/src/Tests/ConsoleTestEntities/Program.cs b/src/Tests/ConsoleTestEntities/Program.cs index 153f506..ccbe0d2 100644 --- a/src/Tests/ConsoleTestEntities/Program.cs +++ b/src/Tests/ConsoleTestEntities/Program.cs @@ -1,6 +1,5 @@ using DbContextLib; using StubbedContextLib; -using Microsoft.EntityFrameworkCore; using Entities; diff --git a/src/Tests/ConsoleTestRelationships/ConsoleTestRelationships.csproj b/src/Tests/ConsoleTestRelationships/ConsoleTestRelationships.csproj index 206b89a..02f9db5 100644 --- a/src/Tests/ConsoleTestRelationships/ConsoleTestRelationships.csproj +++ b/src/Tests/ConsoleTestRelationships/ConsoleTestRelationships.csproj @@ -1,5 +1,17 @@  + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + Exe net8.0 diff --git a/src/Tests/ConsoleTestRelationships/Program.cs b/src/Tests/ConsoleTestRelationships/Program.cs index 83fa4f4..b43a033 100644 --- a/src/Tests/ConsoleTestRelationships/Program.cs +++ b/src/Tests/ConsoleTestRelationships/Program.cs @@ -1,2 +1,223 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); + +using DbContextLib; +using Microsoft.EntityFrameworkCore; +using StubbedContextLib; + +class Program +{ + static void Main(string[] args) + { + + try { + using (LibraryContext db = new TrainingStubbedContext()) + { + ActivityTests(db); + + DataSourceTests(db); + + AthleteTests(db); + } + } + catch (Exception ex) + { + Console.WriteLine($"Une erreur s'est produite : {ex.Message}"); + } + } + static void ActivityTests(LibraryContext db) + { + Console.WriteLine("Accès à toutes les activités avec leurs fréquences cardiaques :"); + + Console.WriteLine("Activités :"); + Console.WriteLine("---------------------------------"); + + foreach (var activity in db.ActivitiesSet.Include(a => a.HeartRates)) + { + Console.WriteLine($"\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}"); + + Console.WriteLine("\tFréquences cardiaques :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var heartRate in activity.HeartRates) + { + Console.WriteLine($"\t\t{heartRate.IdHeartRate} - {heartRate.Altitude}, {heartRate.Time}, {heartRate.Temperature}, {heartRate.Bpm}, {heartRate.Longitude}, {heartRate.Latitude}"); + } + } + + Console.WriteLine("---------------------------------\n"); + + Console.WriteLine("Accès à l'activité d'id '2' :"); + Console.WriteLine("---------------------------------"); + + foreach (var activity in db.ActivitiesSet.Where(a => a.IdActivity == 2).Include(a => a.HeartRates)) + { + Console.WriteLine($"\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}"); + + Console.WriteLine("\tFréquences cardiaques :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var heartRate in activity.HeartRates) + { + Console.WriteLine($"\t\t{heartRate.IdHeartRate} - {heartRate.Altitude}, {heartRate.Time}, {heartRate.Temperature}, {heartRate.Bpm}, {heartRate.Longitude}, {heartRate.Latitude}"); + } + } + } + + static void DataSourceTests(LibraryContext db) + { + Console.WriteLine("Accès à toutes les sources de données avec leurs activités :"); + + Console.WriteLine("Sources de données :"); + Console.WriteLine("---------------------------------"); + + foreach (var dataSource in db.DataSourcesSet.Include(ds => ds.Activities)) + { + Console.WriteLine($"\t{dataSource.IdSource} - {dataSource.Model}"); + + Console.WriteLine("\tActivités :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var activity in dataSource.Activities) + { + Console.WriteLine($"\t\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}"); + } + + Console.WriteLine("\tAthletes :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var athlete in dataSource.Athletes) + { + Console.WriteLine($"\t\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}"); + } + } + + Console.WriteLine("---------------------------------\n"); + + Console.WriteLine("Accès à la source de données d'id '2' :"); + Console.WriteLine("---------------------------------"); + + foreach (var dataSource in db.DataSourcesSet.Where(ds => ds.IdSource == 2).Include(ds => ds.Activities)) + { + Console.WriteLine($"\t{dataSource.IdSource} - {dataSource.Model}"); + + Console.WriteLine("\tActivités :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var activity in dataSource.Activities) + { + Console.WriteLine($"\t\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}"); + } + + Console.WriteLine("\tAthletes :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var athlete in dataSource.Athletes) + { + Console.WriteLine($"\t\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}"); + } + } + + Console.WriteLine("---------------------------------\n"); + } + + static void AthleteTests(LibraryContext db) + { + Console.WriteLine("Accès à tous les athlètes avec leurs statistiques :"); + + Console.WriteLine("Athlètes :"); + Console.WriteLine("---------------------------------"); + + // ! Pas oublier de faire tous les includes necessaire ! + // ? Mais comment ? + foreach (var athlete in db.AthletesSet.Include(a => a.Statistics)) + { + Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}"); + + Console.WriteLine("\tStatistiques :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var statistic in athlete.Statistics) + { + Console.WriteLine($"\t\t{statistic.IdStatistic} - {statistic.Date}, {statistic.AverageCaloriesBurned}, {statistic.AverageHeartRate}, {statistic.MaximumHeartRate}"); + } + + Console.WriteLine("\tActivités :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var activity in athlete.Activities) + { + Console.WriteLine($"\t\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}"); + } + + Console.WriteLine("\tEntraînements :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var training in athlete.Trainings) + { + Console.WriteLine($"\t\t{training.IdTraining} - {training.Date}, {training.Latitude}, {training.Longitude}, {training.Description}, {training.FeedBack}"); + } + + Console.WriteLine("\tNotifications :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var notification in athlete.Notifications) + { + Console.WriteLine($"\t\t{notification.IdNotif} - {notification.Date}, {notification.Statut}, {notification.Message}"); + } + + Console.WriteLine("\tSources de données :"); + Console.WriteLine("\t---------------------------------"); + + Console.WriteLine("\t\t" + (athlete.DataSource?.Model ?? "Aucune source de données")); + } + + Console.WriteLine("---------------------------------\n"); + + Console.WriteLine("Accès à l'athlète d'id '2' :"); + Console.WriteLine("---------------------------------"); + + foreach (var athlete in db.AthletesSet.Where(a => a.IdAthlete == 2).Include(a => a.Statistics)) + { + Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}"); + + Console.WriteLine("\tStatistiques :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var statistic in athlete.Statistics) + { + Console.WriteLine($"\t\t{statistic.IdStatistic} - {statistic.Date}, {statistic.AverageCaloriesBurned}, {statistic.AverageHeartRate}, {statistic.MaximumHeartRate}"); + } + + Console.WriteLine("\tActivités :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var activity in athlete.Activities) + { + Console.WriteLine($"\t\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}"); + } + + Console.WriteLine("\tEntraînements :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var training in athlete.Trainings) + { + Console.WriteLine($"\t\t{training.IdTraining} - {training.Date}, {training.Latitude}, {training.Longitude}, {training.Description}, {training.FeedBack}"); + } + + Console.WriteLine("\tNotifications :"); + Console.WriteLine("\t---------------------------------"); + + foreach (var notification in athlete.Notifications) + { + Console.WriteLine($"\t\t{notification.IdNotif} - {notification.Date}, {notification.Statut}, {notification.Message}"); + } + + Console.WriteLine("\tSources de données :"); + Console.WriteLine("\t---------------------------------"); + + Console.WriteLine("\t\t" + (athlete.DataSource?.Model ?? "Aucune source de données")); + } + + Console.WriteLine("---------------------------------\n"); + } + +} \ No newline at end of file diff --git a/src/Tests/ConsoleTestRelationships/uca.HeartTrack.db b/src/Tests/ConsoleTestRelationships/uca.HeartTrack.db new file mode 100644 index 0000000..d2d197f Binary files /dev/null and b/src/Tests/ConsoleTestRelationships/uca.HeartTrack.db differ