OK seems to be good but the DB is fucked up i cannot access to property by incluing them => it's null and throw error no Collum "nameOfProperty"
continuous-integration/drone/push Build is passing Details

Test_CI
David D'ALMEIDA 1 year ago
parent 9176966c2d
commit 16b7c3051e

@ -6,18 +6,18 @@ namespace APIMappers;
public static class ActivityMapper
{
private static GenericMapper<Activity, ActivityDto> _mapper = new GenericMapper<Activity, ActivityDto>();
private static GenericMapper<Activity, ActivityDto> _mapper = new();
public static ActivityDto ToDto(this Activity activity)
public static Activity ToModel(this ActivityDto activityDto)
{
return activity.ToU(_mapper, activityDto => new ActivityDto
Func<ActivityDto, Activity> create = activity => new Activity
{
Id = activity.Id,
Type = activity.Type,
Date = activity.Date,
StartTime = activity.StartTime,
EndTime = activity.EndTime,
EffortFelt = activity.Effort,
Effort = activity.EffortFelt,
Variability = activity.Variability,
Variance = activity.Variance,
StandardDeviation = activity.StandardDeviation,
@ -26,28 +26,55 @@ public static class ActivityMapper
Minimum = activity.Minimum,
AverageTemperature = activity.AverageTemperature,
HasAutoPause = activity.HasAutoPause
});
};
Action<ActivityDto, Activity> link = (activity, model) =>
{
model.HeartRates.AddRange(activity.HeartRates.ToModels(activityDto).ToArray());
if (activity.DataSource != null) model.DataSource = activity.DataSource.ToModel();
model.Athlete = activity.Athlete.ToModel();
};
return activityDto.ToT(_mapper, create, link);
}
public static Activity ToModel(this ActivityDto activityDto)
public static ActivityDto ToDto(this Activity model)
{
Func<Activity, ActivityDto> create = activity => new ActivityDto
{
return activityDto.ToT(_mapper, activity => new Activity
Id = activity.Id,
Type = activity.Type,
Date = activity.Date,
StartTime = activity.StartTime,
EndTime = activity.EndTime,
EffortFelt = activity.Effort,
Variability = activity.Variability,
Variance = activity.Variance,
StandardDeviation = activity.StandardDeviation,
Average = activity.Average,
Maximum = activity.Maximum,
Minimum = activity.Minimum,
AverageTemperature = activity.AverageTemperature,
HasAutoPause = activity.HasAutoPause
};
Action<Activity, ActivityDto> link = (activity, dto) =>
{
Id = activityDto.Id,
Type = activityDto.Type,
Date = activityDto.Date,
StartTime = activityDto.StartTime,
EndTime = activityDto.EndTime,
Effort = activityDto.EffortFelt,
Variability = activityDto.Variability,
Variance = activityDto.Variance,
StandardDeviation = activityDto.StandardDeviation,
Average = activityDto.Average,
Maximum = activityDto.Maximum,
Minimum = activityDto.Minimum,
AverageTemperature = activityDto.AverageTemperature,
HasAutoPause = activityDto.HasAutoPause
});
dto.HeartRates = activity.HeartRates.ToDtos(model).ToArray();
dto.DataSource = activity.DataSource.ToDto();
dto.Athlete = activity.Athlete.ToDto();
};
return model.ToU(_mapper, create, link);
}
public static IEnumerable<Activity> ToModels(this IEnumerable<ActivityDto> dtos)
=> dtos.Select(dto => dto.ToModel());
public static IEnumerable<ActivityDto> ToDtos(this IEnumerable<Activity> models)
=> models.Select(model => model.ToDto());
}

@ -0,0 +1,51 @@
using Dto;
using Model;
using Shared;
namespace APIMappers;
public static class DataSourceMapper
{
private static GenericMapper<DataSource, DataSourceDto> _mapper = new ();
public static DataSource ToModel(this DataSourceDto dto)
{
Func<DataSourceDto, DataSource> create = dataSourceDto =>
new DataSource( dataSourceDto.Id, dataSourceDto.Type, dataSourceDto.Model, dataSourceDto.Precision, dataSourceDto.Athletes.ToModels().ToList(), dataSourceDto.Activities.ToModels().ToList());
/*
Action<DataSourceDto, DataSource> link = (dataSourceDto, model) =>
{
model.Activities.AddRange(dataSourceDto.Activities.ToModels());
model.Athletes.AddRange(dataSourceDto.Athletes.ToModels());
};*/
return dto.ToT(_mapper, create);
}
public static DataSourceDto ToDto(this DataSource model)
{
Func<DataSource, DataSourceDto> create = dataSource =>
new DataSourceDto
{
Id = dataSource.Id,
Type = dataSource.Type,
Model = dataSource.Model,
Precision = dataSource.Precision,
};
Action<DataSource, DataSourceDto> link = (dataSource, dto) =>
{
dto.Activities = dataSource.Activities.ToDtos().ToArray();
dto.Athletes = dataSource.Athletes.ToDtos().ToArray();
};
return model.ToU(_mapper, create, link);
}
public static IEnumerable<DataSource> ToModels(this IEnumerable<DataSourceDto> dtos)
=> dtos.Select(d => d.ToModel());
public static IEnumerable<DataSourceDto> ToDtos(this IEnumerable<DataSource> models)
=> models.Select(m => m.ToDto());
}

@ -0,0 +1,45 @@
using Dto;
using Model;
using Shared;
namespace APIMappers;
public static class HeartRateMapper
{
private static GenericMapper<HeartRate, HeartRateDto> _mapper = new();
public static HeartRate ToModel(this HeartRateDto dto, ActivityDto activityDto)
{
Func<HeartRateDto, HeartRate> create = heartRateDto =>
new HeartRate(heartRateDto.HeartRate, TimeOnly.FromDateTime(heartRateDto.Timestamp), activityDto.ToModel(), heartRateDto.Latitude, heartRateDto.Longitude, heartRateDto.Altitude, heartRateDto.Cadence, heartRateDto.Distance, heartRateDto.Speed, heartRateDto.Power, heartRateDto.Temperature);
return dto.ToT(_mapper, create);
}
public static HeartRateDto ToDto(this HeartRate model, Activity activity)
{
Func<HeartRate, HeartRateDto> create = heartRate =>
new HeartRateDto
{
Timestamp = new DateTime(activity.Date.Year, activity.Date.Month, activity.Date.Day, heartRate.Timestamp.Hour, heartRate.Timestamp.Minute, heartRate.Timestamp.Second),
Latitude = heartRate.Latitude,
Longitude = heartRate.Longitude,
Altitude = heartRate.Altitude,
HeartRate = heartRate.Bpm,
Cadence = heartRate.Cadence,
Distance = heartRate.Distance,
Speed = heartRate.Speed,
Power = heartRate.Power,
Temperature = heartRate.Temperature
};
return model.ToU(_mapper, create);
}
public static IEnumerable<HeartRate> ToModels(this IEnumerable<HeartRateDto> dtos, ActivityDto activityDto)
=> dtos.Select(d => d.ToModel(activityDto));
public static IEnumerable<HeartRateDto> ToDtos(this IEnumerable<HeartRate> models, Activity activity)
=> models.Select(m => m.ToDto(activity));
}

@ -0,0 +1,12 @@
using Dto;
using Model;
namespace APIMappers;
public static class LargeImageMapper
{
public static LargeImageDto ToDto(this LargeImage largeImage)
=> new() { Base64 = largeImage.Base64 };
public static LargeImage ToModel(this LargeImageDto largeImageDto) => new(largeImageDto.Base64);
}

@ -48,4 +48,10 @@ public static class UserMappeur
});
}
public static IEnumerable<User> ToModels(this IEnumerable<UserDto> dtos)
=> dtos.Select(dto => dto.ToModel());
public static IEnumerable<UserDto> ToDtos(this IEnumerable<User> models)
=> models.Select(model => model.ToDto());
}

@ -9,7 +9,6 @@
using Entities;
using Microsoft.EntityFrameworkCore;
namespace DbContextLib
{
/// <summary>
@ -52,6 +51,12 @@ namespace DbContextLib
/// </summary>
public DbSet<TrainingEntity> TrainingsSet { get; set; }
/// <summary>
/// Gets or sets the set of large images.
/// </summary>
public DbSet<LargeImageEntity> LargeImages { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="HeartTrackContext"/> class.
/// </summary>
@ -219,13 +224,13 @@ namespace DbContextLib
.HasMany(d => d.Activities)
.WithOne(a => a.DataSource)
.HasForeignKey(a => a.DataSourceId)
.IsRequired();
.IsRequired(false);
modelBuilder.Entity<DataSourceEntity>()
.HasMany(ds => ds.Activities)
.HasMany(ds => ds.Athletes)
.WithOne(at => at.DataSource)
.HasForeignKey(at => at.DataSourceId)
.IsRequired(false);
.IsRequired();
// modelBuilder.Entity<AthleteEntity>()
// .HasMany(fer => fer.Followers)

@ -16,12 +16,10 @@ public class ActivityDto
public int Minimum { get; set; }
public float AverageTemperature { get; set; }
public bool HasAutoPause { get; set; }
public DataSourceDto? DataSource { get; set; }
public int AthleteId { get; set; }
public UserDto? Athlete { get; set; }
public int DataSourceId { get; set; }
public int? TrainingId { get; set; }
public IEnumerable<HeartRateDto> HeartRates { get; set; } // = new List<HeartRateDto>();
// public int? TrainingId { get; set; }
public IEnumerable<HeartRateDto> HeartRates { get; set; }
}

@ -17,7 +17,9 @@ public class UserDto
public float Weight { get; set; }
public string? Password { get; set; }
public DateTime DateOfBirth { get; set; }
public string ProfilePicture { get; set; } = "https://davidalmeida.site/assets/me_avatar.f77af006.png";
public LargeImageDto Image { get; set; }
public string ProfilePicture { get; set; } = "default.jpg";
public bool IsCoach { get; set; }
}

@ -0,0 +1,16 @@
namespace Dto;
public class DataSourceDto
{
public int Id { get; set; }
public string? Type { get; set; }
public string Model { get; set; }
public float Precision { get; set; }
public IEnumerable<UserDto>? Athletes { get; set; }
public IEnumerable<ActivityDto>? Activities { get; set; }
}

@ -1,3 +1,5 @@
namespace Dto;
public class HeartRateDto
{
public DateTime Timestamp { get; set; }

@ -0,0 +1,6 @@
namespace Dto;
public class LargeImageDto
{
public string Base64 { get; set; }
}

@ -0,0 +1 @@
namespace Dto;

@ -0,0 +1 @@
namespace Dto;

@ -0,0 +1 @@
namespace Dto;

@ -6,61 +6,70 @@ namespace EFMappers;
public static class ActivityMapper
{
private static GenericMapper<Activity, ActivityEntity> _mapper = new GenericMapper<Activity, ActivityEntity>();
// ! RESET
// ? Quand on fait appel au reset ?
// * Apres des saves changing ou rollback.
private static GenericMapper<Activity, ActivityEntity> _mapper = new ();
public static void Reset()
{
_mapper.Reset();
}
public static Activity? ToModel(this ActivityEntity entity)
public static Activity ToModel(this ActivityEntity entity)
{
Func<ActivityEntity, Activity> create = activityEntity => new Activity
{
// return entity.ToModel();
return entity.ToT(_mapper, activity => new Activity (
entity.IdActivity,
entity.Type,
new DateTime(entity.Date.Year, entity.Date.Month, entity.Date.Day),
new DateTime().Add(entity.StartTime.ToTimeSpan()),
new DateTime().Add(entity.EndTime.ToTimeSpan()),
entity.EffortFelt,
entity.Variability,
entity.Variance,
entity.StandardDeviation,
entity.Average,
entity.Maximum,
entity.Minimum,
entity.AverageTemperature,
entity.HasAutoPause));
// ! regarder a ce que le model est bien les relation comme l'EF
// ), (activity, entity) => activity.Id = entity.IdActivity);
Id = activityEntity.IdActivity,
Type = activityEntity.Type,
Date = activityEntity.Date.ToDateTime(TimeOnly.MinValue),
StartTime = activityEntity.Date.ToDateTime(activityEntity.StartTime),
EndTime = activityEntity.Date.ToDateTime(activityEntity.EndTime),
Effort = activityEntity.EffortFelt,
Variability = activityEntity.Variability,
Variance = activityEntity.Variance,
StandardDeviation = activityEntity.StandardDeviation,
Average = activityEntity.Average,
Maximum = activityEntity.Maximum,
Minimum = activityEntity.Minimum,
AverageTemperature = activityEntity.AverageTemperature,
HasAutoPause = activityEntity.HasAutoPause
};
Console.WriteLine("ActivityMapper.ToModel");
// here
Action<ActivityEntity, Activity> link = (activityEntity, model) =>
{
model.HeartRates.AddRange(activityEntity.HeartRates?.ToModels());
model.DataSource = activityEntity.DataSource.ToModel();
model.Athlete = activityEntity.Athlete.ToModel();
};
return entity.ToT(_mapper, create, link);
}
// dictionnaire;
public static ActivityEntity? ToEntity(this Activity model)
public static ActivityEntity ToEntity(this Activity model)
{
// return model.ToEntity();
return model.ToU(_mapper, activityEntity => new ActivityEntity
Func<Activity, ActivityEntity> create = activity => new ActivityEntity
{
IdActivity = model.Id,
Type = model.Type,
Date = DateOnly.FromDateTime(model.Date),
StartTime = TimeOnly.FromDateTime(model.StartTime),
EndTime = TimeOnly.FromDateTime(model.EndTime),
EffortFelt = model.Effort,
Variability = model.Variability,
Variance = model.Variance,
StandardDeviation = model.StandardDeviation,
Average = model.Average,
Maximum = model.Maximum,
Minimum = model.Minimum,
AverageTemperature = model.AverageTemperature,
HasAutoPause = model.HasAutoPause
}
// ! regarder a ce que le model est bien les relation comme l'EF
);
IdActivity = activity.Id,
Type = activity.Type,
Date = DateOnly.FromDateTime(activity.Date),
StartTime = TimeOnly.FromDateTime(activity.StartTime),
EndTime = TimeOnly.FromDateTime(activity.EndTime),
EffortFelt = activity.Effort,
Variability = activity.Variability,
Variance = activity.Variance,
StandardDeviation = activity.StandardDeviation,
Average = activity.Average,
Maximum = activity.Maximum,
Minimum = activity.Minimum,
AverageTemperature = activity.AverageTemperature,
HasAutoPause = activity.HasAutoPause
};
Action<Activity, ActivityEntity> link = (activity, entity) =>
{
entity.HeartRates = activity.HeartRates.ToEntities().ToList();
entity.DataSource = activity.DataSource.ToEntity();
entity.Athlete = activity.Athlete.ToEntity();
};
return model.ToU(_mapper, create, link);
}
public static IEnumerable<Activity> ToModels(this IEnumerable<ActivityEntity> entities)

@ -1,117 +1,86 @@
using System.Buffers;
using Dto;
using Entities;
using Model;
using Shared;
namespace ApiMappeur;
namespace EFMappers;
public static class UserMappeur
{
private static readonly ArrayPool<UserDto> UserDtoPool = ArrayPool<UserDto>.Create();
private static readonly Dictionary<User, UserDto> userToDtoMap = new Dictionary<User, UserDto>();
private static readonly Dictionary<UserDto, User> dtoToUserMap = new Dictionary<UserDto, User>();
public static UserDto ToDto(this User user)
private static GenericMapper<User, AthleteEntity> _mapper = new ();
public static User ToModel(this AthleteEntity entity)
{
Func<AthleteEntity, User> create = athleteEntity => new User
{
Id = athleteEntity.IdAthlete,
FirstName = athleteEntity.FirstName,
LastName = athleteEntity.LastName,
Email = athleteEntity.Email,
MotDePasse = athleteEntity.Password,
DateOfBirth = athleteEntity.DateOfBirth.ToDateTime(TimeOnly.MinValue),
Sexe = athleteEntity.Sexe,
Username = athleteEntity.Username,
Weight = athleteEntity.Weight,
Lenght = (float)athleteEntity.Length,
ProfilePicture = athleteEntity.ProfilPicture,
// Role = athleteEntity.IsCoach ? new Coach() : new Athlete(),
};
Action<AthleteEntity, User> link = (athleteEntity, model) =>
{
model.Role = athleteEntity.IsCoach ? new Coach() : new Athlete();
model.DataSources.Add(athleteEntity.DataSource.ToModel());
model.Activities.AddRange(athleteEntity.Activities.ToModels());
model.Image = athleteEntity.Image.ToModel();
};
return entity.ToT(_mapper, create, link);
}
public static AthleteEntity ToEntity(this User model)
{
return new UserDto
Func<User, AthleteEntity> create = user => new AthleteEntity
{
Id = user.Id,
IdAthlete = user.Id,
Username = user.Username,
ProfilePicture = user.ProfilePicture,
LastName = user.LastName,
Sexe = user.Sexe,
FirstName = user.FirstName,
LastName = user.LastName,
Email = user.Email,
Password = user.MotDePasse,
Sexe = user.Sexe,
Lenght = user.Lenght,
DateOfBirth = DateOnly.FromDateTime(user.DateOfBirth),
IsCoach = user.Role is Coach,
Weight = user.Weight,
DateOfBirth = user.DateOfBirth,
IsCoach = user.Role is Coach
Length = user.Lenght,
ProfilPicture = user.ProfilePicture,
};
}
public static User ToModel(this UserDto userDto)
{
return new User
Action<User, AthleteEntity> link = (user, entity) =>
{
Username = userDto.Username,
ProfilePicture = userDto.ProfilePicture,
LastName = userDto.LastName,
FirstName = userDto.FirstName,
Email = userDto.Email,
MotDePasse = userDto.Password,
Sexe = userDto.Sexe,
Lenght = userDto.Lenght,
Weight = userDto.Weight,
DateOfBirth = userDto.DateOfBirth,
Role = userDto.IsCoach ? new Coach() : new Athlete()
entity.DataSource = user.DataSources.ToEntities().First();
entity.Activities = user.Activities.ToEntities().ToList();
entity.IsCoach = user.Role is Coach;
entity.Image = user.Image.ToEntity();
/*if (user.Role is Coach)
entity.TrainingsCoach = user.Traning.ToEntities().ToList();
else
entity.TrainingsAthlete = user.Traning.ToEntities().ToList();
*/
// entity.NotificationsReceived = user.Notifications.ToEntities().ToList();
};
}
}
/*
using Dto;
using Model;
using System.Buffers;
// entity.DataSource = user.DataSources.ToEntities().ToList();
namespace ApiMappeur
{
// anotine
public static class UserMappeur
{
private static readonly ArrayPool<UserDto> UserDtoPool = ArrayPool<UserDto>.Create();
// [TODO] [DAVE] : Add the link to the friendship
public static UserDto ToDto(this User user)
{
UserDto userDto = UserDtoPool.Rent();
userDto.Id = user.Id;
userDto.Username = user.Username;
userDto.ProfilePicture = user.ProfilePicture;
userDto.LastName = user.LastName;
userDto.FirstName = user.FirstName;
userDto.Email = user.Email;
userDto.Password = user.MotDePasse;
userDto.Sexe = user.Sexe;
userDto.Lenght = user.Lenght;
userDto.Weight = user.Weight;
userDto.DateOfBirth = user.DateOfBirth;
userDto.IsCoach = user.Role is Coach;
return userDto;
}
};
public static User ToModel(this UserDto userDto)
{
if (userDto.IsCoach)
{
return new User(
userDto.Username,
userDto.ProfilePicture,
userDto.LastName,
userDto.FirstName,
userDto.Email,
userDto.Password,
userDto.Sexe,
userDto.Lenght,
userDto.Weight,
userDto.DateOfBirth,
new Coach()
);
}
return new User(
userDto.Username,
userDto.ProfilePicture,
userDto.LastName,
userDto.FirstName,
userDto.Email,
userDto.Password,
userDto.Sexe,
userDto.Lenght,
userDto.Weight,
userDto.DateOfBirth,
new Athlete());
return model.ToU(_mapper, create, link);
}
public static void ReturnToPool(this UserDto userDto)
{
UserDtoPool.Return(userDto);
}
}
public static IEnumerable<User> ToModels(this IEnumerable<AthleteEntity> entities)
=> entities.Select(e => e.ToModel());
public static IEnumerable<AthleteEntity> ToEntities(this IEnumerable<User> models)
=> models.Select(m => m.ToEntity());
}
*/

@ -0,0 +1,51 @@
using Entities;
using Model;
using Shared;
namespace EFMappers;
public static class DataSourceMapper
{
private static GenericMapper<DataSource, DataSourceEntity> _mapper = new ();
public static DataSource ToModel(this DataSourceEntity entity)
{
Func<DataSourceEntity, DataSource> create = dataSourceEntity =>
new DataSource( dataSourceEntity.IdSource, dataSourceEntity.Type, dataSourceEntity.Model, dataSourceEntity.Precision, dataSourceEntity.Athletes.ToModels().ToList(), dataSourceEntity.Activities.ToModels().ToList());
/*
Action<DataSourceEntity, DataSource> link = (dataSourceEntity, model) =>
{
model.Activities.AddRange(dataSourceEntity.Activities.ToModels());
model.Athletes.AddRange(dataSourceEntity.Athletes.ToModels());
};*/
return entity.ToT(_mapper, create);
}
public static DataSourceEntity ToEntity(this DataSource model)
{
Func<DataSource, DataSourceEntity> create = dataSource =>
new DataSourceEntity
{
IdSource = dataSource.Id,
Type = dataSource.Type,
Model = dataSource.Model,
Precision = dataSource.Precision
};
Action<DataSource, DataSourceEntity> link = (dataSource, entity) =>
{
entity.Activities = dataSource.Activities.ToEntities().ToList();
entity.Athletes = dataSource.Athletes.ToEntities().ToList();
};
return model.ToU(_mapper, create, link);
}
public static IEnumerable<DataSource> ToModels(this IEnumerable<DataSourceEntity> entities)
=> entities.Select(e => e.ToModel());
public static IEnumerable<DataSourceEntity> ToEntities(this IEnumerable<DataSource> models)
=> models.Select(m => m.ToEntity());
}

@ -0,0 +1,56 @@
using Entities;
using Model;
using Shared;
namespace EFMappers;
public static class HeartRateMapper
{
private static GenericMapper<HeartRate, HeartRateEntity> _mapper = new ();
public static HeartRate ToModel(this HeartRateEntity entity)
{
Func<HeartRateEntity,HeartRate> create = heartRateEntity =>
new HeartRate(heartRateEntity.IdHeartRate, heartRateEntity.Bpm, heartRateEntity.Time, heartRateEntity.Activity.ToModel(),heartRateEntity.Latitude, heartRateEntity.Longitude, heartRateEntity.Altitude, heartRateEntity.Cadence, heartRateEntity.Distance, heartRateEntity.Speed, heartRateEntity.Power, heartRateEntity.Temperature);
Action<HeartRateEntity, HeartRate> link = (heartRateEntity, model) =>
{
model.Activity = heartRateEntity.Activity.ToModel();
};
return entity.ToT(_mapper, create, link);
}
public static HeartRateEntity ToEntity(this HeartRate model)
{
Func<HeartRate, HeartRateEntity> create = heartRate =>
new HeartRateEntity
{
IdHeartRate = heartRate.Id,
Bpm = heartRate.Bpm,
Time = heartRate.Timestamp,
Latitude = heartRate.Latitude,
Longitude = heartRate.Longitude,
Altitude = heartRate.Altitude,
Cadence = heartRate.Cadence??0,
Distance = heartRate.Distance,
Speed = heartRate.Speed,
Power = heartRate.Power,
Temperature = heartRate.Temperature
};
Action<HeartRate, HeartRateEntity> link = (heartRate, entity) =>
{
entity.Activity = heartRate.Activity.ToEntity();
};
return model.ToU(_mapper, create, link);
}
public static IEnumerable<HeartRate> ToModels(this IEnumerable<HeartRateEntity> entities)
=> entities.Select(h => h.ToModel());
public static IEnumerable<HeartRateEntity> ToEntities(this IEnumerable<HeartRate> models)
=> models.Select(h => h.ToEntity());
}

@ -0,0 +1,12 @@
using Entities;
using Model;
namespace EFMappers;
public static class LargeImageMapper
{
public static LargeImage ToModel(this LargeImageEntity largeImage) => new(largeImage.Base64);
public static LargeImageEntity ToEntity(this LargeImage largeImage) => new() { Base64 = largeImage.Base64 };
}

@ -97,11 +97,11 @@ namespace Entities
/// </summary>
public bool HasAutoPause { get; set; }
public ICollection<HeartRateEntity> HeartRates { get; set; } = new List<HeartRateEntity>();
public ICollection<HeartRateEntity>? HeartRates { get; set; } = new List<HeartRateEntity>();
public int DataSourceId { get; set; }
public int? DataSourceId { get; set; }
public DataSourceEntity DataSource { get; set; } = null!;
public DataSourceEntity? DataSource { get; set; } = null!;
public int AthleteId { get; set; }

@ -17,8 +17,6 @@ namespace Entities
[Table("Athlete")]
public class AthleteEntity
{
public AthleteEntity() : base() { }
/// <summary>
/// Gets or sets the unique identifier of the athlete.
/// </summary>
@ -89,9 +87,13 @@ namespace Entities
/// </summary>
public bool IsCoach { get; set; }
public byte[]? ProfilPicture { get; set; }
// [TODO] [DAVE] Pourquoi c'est un byte[] ? et pas un string ? it's me so should change it to string
public string? ProfilPicture { get; set; }
public LargeImageEntity? Image { get; set; }
[ForeignKey("Image")]
public Guid? ImageId { get; set; }
public ICollection<ActivityEntity> Activities { get; set; } = new List<ActivityEntity>();
@ -104,7 +106,7 @@ namespace Entities
public ICollection<NotificationEntity> NotificationsSent { get; set; } = new List<NotificationEntity>();
public int? DataSourceId { get; set; }
// [TODO] [DAVE] Pourquoi c'est un one to one ? et pas un one to many ?
public DataSourceEntity? DataSource { get; set; }
public ICollection<FriendshipEntity> Followers { get; set; } = [];

@ -27,7 +27,7 @@ namespace Entities
/// <summary>
/// Gets or sets the altitude.
/// </summary>
public double Altitude { get; set; }
public double? Altitude { get; set; }
/// <summary>
/// Gets or sets the time of the heart rate measurement.
@ -39,7 +39,7 @@ namespace Entities
/// <summary>
/// Gets or sets the temperature.
/// </summary>
public float Temperature { get; set; }
public double? Temperature { get; set; }
/// <summary>
/// Gets or sets the heart rate in beats per minute (bpm).
@ -49,12 +49,32 @@ namespace Entities
/// <summary>
/// Gets or sets the longitude.
/// </summary>
public float Longitude { get; set; }
public double? Longitude { get; set; }
/// <summary>
/// Gets or sets the latitude.
/// </summary>
public float Latitude { get; set; }
public double? Latitude { get; set; }
/// <summary>
/// Gets or sets the cadence.
/// </summary>
public int Cadence { get; set; }
/// <summary>
/// Gets or sets the distance.
/// </summary>
public double? Distance { get; set; }
/// <summary>
/// Gets or sets the speed.
/// </summary>
public double? Speed { get; set; }
/// <summary>
/// Gets or sets the power.
/// </summary>
public int? Power { get; set; }
public int ActivityId { get; set; }

@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;
namespace Entities;
public class LargeImageEntity
{
[Key]
public Guid Id { get; set; }
public string Base64 { get; set; }
}

@ -10,6 +10,7 @@ public class Activity
public DateTime EndTime { get; set; }
private int _effort;
[Range(0, 5)]
public int Effort
{
@ -32,12 +33,32 @@ public class Activity
public float AverageTemperature { get; set; }
public bool HasAutoPause { get; set; }
public HashSet<User> Users { get; private set; } = new HashSet<User>();
public Activity(int idActivity ,string? type, DateTime date, DateTime startTime, DateTime endTime,
int effort, float variability, float variance, float standardDeviation,
float average, int maximum, int minimum, float averageTemperature, bool hasAutoPause)
public User Athlete { get; set; }
public DataSource? DataSource { get; set; }
public List<HeartRate> HeartRates { get; set; } = new List<HeartRate>();
public Activity(int id, string type, DateTime date, DateTime startTime, DateTime endTime, int effort, float variability, float variance, float standardDeviation, float average, int maximum, int minimum, float averageTemperature, bool hasAutoPause, User user, DataSource dataSource, List<HeartRate> heartRates)
{
Id = idActivity;
Id = id;
Type = type;
Date = date;
StartTime = startTime;
EndTime = endTime;
Effort = effort;
Variability = variability;
Variance = variance;
StandardDeviation = standardDeviation;
Average = average;
Maximum = maximum;
Minimum = minimum;
AverageTemperature = averageTemperature;
HasAutoPause = hasAutoPause;
Athlete = user;
DataSource = dataSource;
HeartRates = heartRates;
}
public Activity(int id, string type, DateTime date, DateTime startTime, DateTime endTime, int effort, float variability, float variance, float standardDeviation, float average, int maximum, int minimum, float averageTemperature, bool hasAutoPause, User user){
Id = id;
Type = type;
Date = date;
StartTime = startTime;
@ -51,6 +72,7 @@ public class Activity
Minimum = minimum;
AverageTemperature = averageTemperature;
HasAutoPause = hasAutoPause;
Athlete = user;
}
public Activity(){}

@ -0,0 +1,29 @@
namespace Model;
public class DataSource
{
public int Id { get; set; }
public string Type { get; set; }
public string Model { get; set; }
public float Precision { get; set; }
public ICollection<Activity> Activities { get; set; } = new List<Activity>();
public ICollection<User> Athletes { get; set; }
public DataSource(int id, string type, string model, float precision, ICollection<User> athletes, ICollection<Activity>? activities)
{
Id = id;
Type = type;
Model = model;
Precision = precision;
Athletes = athletes;
Activities = activities;
}
public DataSource(string type, string model, float precision, ICollection<User> athletes, ICollection<Activity>? activities)
: this(0, type, model, precision, athletes, activities)
{}
public override string ToString()
{
return $"DataSource #{Id}: {Type} {Model} with a precision of {Precision}";
}
}

@ -0,0 +1,44 @@
namespace Model;
public class HeartRate
{
public int Id { get; set; }
public int Bpm { get; set; }
public TimeOnly Timestamp { get; set; }
public Activity Activity { get; set; }
public double? Latitude { get; set; }
public double? Longitude { get; set; }
public double? Altitude { get; set; }
public int? Cadence { get; set; }
public double? Distance { get; set; }
public double? Speed { get; set; }
public int? Power { get; set; }
public double? Temperature { get; set; }
public HeartRate(int id, int bpm, TimeOnly timestamp, Activity activity, double? latitude, double? longitude, double? altitude, int? cadence, double? distance, double? speed, int? power, double? temperature)
{
Id = id;
Bpm = bpm;
Timestamp = timestamp;
Activity = activity;
Latitude = latitude;
Longitude = longitude;
Altitude = altitude;
Cadence = cadence;
Distance = distance;
Speed = speed;
Power = power;
Temperature = temperature;
}
public HeartRate(int bpm, TimeOnly timestamp, Activity activity, double? latitude, double? longitude, double? altitude, int? cadence, double? distance, double? speed, int? power, double? temperature)
: this(0, bpm, timestamp, activity, latitude, longitude, altitude, cadence, distance, speed, power, temperature)
{}
public override string ToString()
{
return $"HeartRate #{Id}: {Bpm} bpm at {Timestamp:HH:mm:ss} with a temperature of {Temperature}°C" +
$" and an altitude of {Altitude}m at {Longitude}°E and {Latitude}°N";
}
}

@ -0,0 +1,25 @@
namespace Model;
public class LargeImage : IEquatable<LargeImage>
{
public string Base64 { get; set; }
public LargeImage(string base64)
{
Base64 = base64;
}
public bool Equals(LargeImage? other)
=> other != null && other.Base64.Equals(Base64);
public override bool Equals(object? obj)
{
if(ReferenceEquals(obj, null)) return false;
if(ReferenceEquals(obj!, this)) return true;
if(GetType() != obj!.GetType()) return false;
return Equals(obj! as LargeImage);
}
public override int GetHashCode()
=> Base64.Substring(0, 10).GetHashCode();
}

@ -4,7 +4,7 @@ public class User
{
public int Id { get; set; }
public string Username { get; set; }
public string ProfilePicture { get; set; }
public string ProfilePicture { get; set; } = "";
public string LastName { get; set; }
public string FirstName { get; set; }
public string Email { get; set; }
@ -15,9 +15,12 @@ public class User
public DateTime DateOfBirth { get; set; }
public Role Role { get; set; }
protected List<Notification> Notifications { get; set; } = new List<Notification>();
public LargeImage Image { get; set; } = new LargeImage("");
public List<Notification> Notifications { get; set; } = new List<Notification>();
public List<Activity> Activities { get; set; } = new List<Activity>();
public List<User> Users { get; set; } = new List<User>();
public List<DataSource> DataSources { get; set; } = new List<DataSource>();
public User( string username, string profilePicture, string nom, string prenom, string email, string motDePasse, string sexe, float taille, float poids, DateTime dateNaissance, Role role)
{
@ -35,9 +38,4 @@ public class User
}
public User(){}
}

@ -28,7 +28,8 @@ public partial class DbDataManager : IDataManager
_logger.LogInformation($"GetActivities with index {index} and count {count}", index, count);
_logger.LogInformation($"GetActivities with criteria {criteria} and descending {descending}", criteria, descending);
var activities = _dataManager.DbContext.ActivitiesSet.GetItemsWithFilterAndOrdering(b => true, index, count, criteria, descending).ToModels();
var activities = _dataManager.DbContext.ActivitiesSet
.Include(a => a.DataSource).GetItemsWithFilterAndOrdering(b => true, index, count, criteria, descending).ToModels();
_logger.LogInformation($"Retrieved {activities.Count()} activities");
return await Task.FromResult(activities);
@ -89,10 +90,15 @@ public partial class DbDataManager : IDataManager
entity.HasAutoPause = activity.HasAutoPause;
});
if (updatedActivity != null)
{
_logger.LogInformation($"Updated activity with ID {id}");
return await Task.FromResult(updatedActivity.ToModel());
}
else
{
_logger.LogError($"Failed to update activity with ID {id}");
return await Task.FromResult(updatedActivity!.ToModel());
return await Task.FromResult<Activity?>(null);
}
}
catch (Exception ex)
{

@ -16,8 +16,6 @@ public partial class DbDataManager: IDataManager
public DbDataManager(HeartTrackContext dbContext)
{
DbContext = dbContext;
Console.WriteLine("Contexttttttttt");
Console.WriteLine($"Database created Context: {DbContext.Database.EnsureCreated()}");
ActivityRepo = new ActivityRepository(this);
UserRepo = new UserRepository(this);
ActivityMapper.Reset();
@ -26,14 +24,11 @@ public partial class DbDataManager: IDataManager
public DbDataManager(string dbPlatformPath)
: this(new HeartTrackContext(dbPlatformPath))
{
Console.WriteLine($"Database created String: {DbContext.Database.EnsureCreated()}"); }
{}
public DbDataManager()
{
DbContext = new HeartTrackContext();
Console.WriteLine($"Database created None: {DbContext.Database.EnsureCreated()}");
ActivityRepo = new ActivityRepository(this);
UserRepo= new UserRepository(this);
}

@ -14,7 +14,13 @@ public static class Extensions
return await Task.FromResult<T?>(null);
}
var entry = context.Set<T>().Add(item);
try {
await context.SaveChangesAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message, ex.InnerException, ex.StackTrace);
}
return await Task.FromResult<T?>(entry.Entity);
}
@ -41,9 +47,10 @@ public static class Extensions
// Enregistrer les modifications dans la base de données
await context.SaveChangesAsync();
return existingT;
}
return Task.FromResult<U?>(null).Result;
return existingT;
}

@ -2,27 +2,36 @@ namespace Shared;
public static class Extensions
{
public static U ToU<T, U>(this T t, GenericMapper<T, U> mapper, Func<T, U> func) where U :class where T :class
public static U ToU<T, U>(this T t, GenericMapper<T, U> mapper, Func<T, U> func,Action<T, U>? action = null) where U :class where T :class
{
var u = mapper.GetU(t);
if (u != null) {
return u;
var res = mapper.GetU(t);
if (res != null) {
return res;
}
u = func(t);
U u = func(t);
mapper.Add(t, u);
// action(t, u);
if(action != null) action(t, u);
return u;
}
// , Action<T, U> action
public static T ToT<T,U>(this U u, GenericMapper<T, U> mapper, Func<U, T> func) where U :class where T :class
public static T ToT<T,U>(this U u, GenericMapper<T, U> mapper, Func<U, T> func,Action<U, T>? action = null) where U :class where T :class
{
var t = mapper.GetT(u);
if (t != null) {
return t;
}
t = func(u);
var result = mapper.GetT(u);
if(result != null) return result;
T t = func(u);
mapper.Add(t, u);
// action(t, u);
if(action != null) action(u, t);
return t;
}
public static void AddRange<T>(this ICollection<T> set, IEnumerable<T> ts)
{
foreach(var t in ts)
{
set.Add(t);
}
}
}

@ -25,12 +25,12 @@ public class ActivityService: IActivityRepository
Minimum = 0,
AverageTemperature = 20.0f,
HasAutoPause = false,
Users = {new User
Athlete = new User
{
Id = 3, Username = "Athlete3", ProfilePicture = "https://plus.unsplash.com/premium_photo-1705091981693-6006f8a20479?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D", FirstName = "First3", LastName = "Last3",
Sexe = "M", Lenght = 190, Weight = 80, DateOfBirth = new DateTime(1994, 3, 3), Email = "ath@ex.fr",
Role = new Athlete()
}}
}
},
}
);
@ -66,13 +66,13 @@ public class ActivityService: IActivityRepository
public async Task<IEnumerable<Activity>?> GetActivitiesByUser(int userId, int index, int count, ActivityOrderCriteria criteria, bool descending = false)
{
var activities = _activities.GetItemsWithFilterAndOrdering(c => c.Users.Any(u => u.Id == userId), index, count,
var activities = _activities.GetItemsWithFilterAndOrdering(a => a.Athlete.Id == userId, index, count,
criteria != ActivityOrderCriteria.None ? criteria : null, descending);
return await Task.FromResult(activities);
}
public Task<int> GetNbActivitiesByUser(int userId)
{
return Task.FromResult(_activities.Count(a => a.Users.Any(u => u.Id == userId)));
return Task.FromResult(_activities.Count(a => a.Athlete.Id == userId));
}
}

@ -35,14 +35,18 @@ namespace StubbedContextLib
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
var picture = System.Text.Encoding.UTF8.GetBytes(
"\"UklGRtwDAABXRUJQVlA4INADAAAwEACdASoqACoAAMASJZgCdMoSCz655ndU4XXAP2yXIge5neM/Qd6WCfO8evoj2S0A/p7+f0An85cBxlLDgPC8jO/0nsl/13/O8vvzj7Af8s/p3/H4FU6td4MCwq23z1H2uzoKIXaqJniPI/bRMf8qzv0Zp+HE1RCBw5WQ1j/JovdM1FS52+QcaAAA/v/+NxU4DpPk3+xQPW7tcmURSo9vC4qc+XMxNVBzEM5E8actDz98gmwTXgD62e9EmG/ervdd2ovFFSuxYppWl/wtaX3rkn0xrt8qOql/5I2jfLOnCU0kALLcW4F/wTjU10qsxZXW9fxauC6OPVRF28sc94V9ocmoSWy+sf6jW3vYkVOh+gE/RE0L6b2d3oFyHmkRJnfYwG8o3p6fv9pivNF5aopIBzFnjzwb/VqSq3/b+MWKFmjr8T1qe4/fITo2vBWEqDyogV3ZVGnDVi2DbiEFVSUr2eXTNZQ9V/D9QC/+vCR5TGyX9QOVBgtAYtm/ZTIwzPEYB9NrV1NeO1/sAz78u0tW59r0I+SO5Jgm3B9i1toRurzHv9EZJ9yZL8nafb/T1FaoPDkuJfM+iPs0j8xnS7TaU/gEK0wCxeDYRYtJx9j4hUQq7pAu/T2yWy0vjcUHki952ZNbXnXxB8m8pV5x9E1sfLj5MZEgpU2XV8RHrVvWniCjsf6vgxmR7+KtwIbMjahitUGtHet1WdL+8MmdL29iQJC37pDXirir1NibxKKhFYRuJ3xW9O0r9+Vnh8diqbBuXqDbYR/MSoHvscOCm2t95dN5WBdRUoD7YCG/ZHWc7Ypv/x/al4fkB2lZlYhVWHxjaoeF9jEPI0gAN5XsvUI6hbzEzWMsNW/1orkNOnlskalgmpI4B2rm4Gc7LNui+MuMBrpnBvLkbYX9exe9g8tu7wLt7ScOjDcL99oOyR89Mh9L8rd4+43+JQyR6tsIfcPJo6T6FxHf11d/MGayJi+SWct/uhvvua0oOh+zXNIaUzgoBmu1XULjkpuA0Ghzctf30jbY1AOM49qbMZRYS9A+0S1HrHPnwRvpQY/Sj4xKPn0gdpv/+iTbKJb8zkPC4/9af0Jvesa+GDG0/iw3TswenMhqlh7BM9MW5txpeblsByx4WnJ/oHv6cc0dmM7tsV36lYkCTUXEf/0eKlnfivnN0g1g+j/Lk9et/uoa6TFCW0HgwFOIVFumEYdT675PfuTrYO5o8ZrWEIHtv2Ctlrv9J3TrslD/iKEwtipGHtn0Vak8B9wLL+kz+CIQ/VG4KJpXjx88CeCC4XaGitEdjAAA\"");
var picture2 =
"https://davidalmeida.site/assets/me_avatar.f77af006.png";
LargeImageEntity picture = new LargeImageEntity { Id = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}"), Base64 = "UklGRtwDAABXRUJQVlA4INADAAAwEACdASoqACoAAMASJZgCdMoSCz655ndU4XXAP2yXIge5neM/Qd6WCfO8evoj2S0A/p7+f0An85cBxlLDgPC8jO/0nsl/13/O8vvzj7Af8s/p3/H4FU6td4MCwq23z1H2uzoKIXaqJniPI/bRMf8qzv0Zp+HE1RCBw5WQ1j/JovdM1FS52+QcaAAA/v/+NxU4DpPk3+xQPW7tcmURSo9vC4qc+XMxNVBzEM5E8actDz98gmwTXgD62e9EmG/ervdd2ovFFSuxYppWl/wtaX3rkn0xrt8qOql/5I2jfLOnCU0kALLcW4F/wTjU10qsxZXW9fxauC6OPVRF28sc94V9ocmoSWy+sf6jW3vYkVOh+gE/RE0L6b2d3oFyHmkRJnfYwG8o3p6fv9pivNF5aopIBzFnjzwb/VqSq3/b+MWKFmjr8T1qe4/fITo2vBWEqDyogV3ZVGnDVi2DbiEFVSUr2eXTNZQ9V/D9QC/+vCR5TGyX9QOVBgtAYtm/ZTIwzPEYB9NrV1NeO1/sAz78u0tW59r0I+SO5Jgm3B9i1toRurzHv9EZJ9yZL8nafb/T1FaoPDkuJfM+iPs0j8xnS7TaU/gEK0wCxeDYRYtJx9j4hUQq7pAu/T2yWy0vjcUHki952ZNbXnXxB8m8pV5x9E1sfLj5MZEgpU2XV8RHrVvWniCjsf6vgxmR7+KtwIbMjahitUGtHet1WdL+8MmdL29iQJC37pDXirir1NibxKKhFYRuJ3xW9O0r9+Vnh8diqbBuXqDbYR/MSoHvscOCm2t95dN5WBdRUoD7YCG/ZHWc7Ypv/x/al4fkB2lZlYhVWHxjaoeF9jEPI0gAN5XsvUI6hbzEzWMsNW/1orkNOnlskalgmpI4B2rm4Gc7LNui+MuMBrpnBvLkbYX9exe9g8tu7wLt7ScOjDcL99oOyR89Mh9L8rd4+43+JQyR6tsIfcPJo6T6FxHf11d/MGayJi+SWct/uhvvua0oOh+zXNIaUzgoBmu1XULjkpuA0Ghzctf30jbY1AOM49qbMZRYS9A+0S1HrHPnwRvpQY/Sj4xKPn0gdpv/+iTbKJb8zkPC4/9af0Jvesa+GDG0/iw3TswenMhqlh7BM9MW5txpeblsByx4WnJ/oHv6cc0dmM7tsV36lYkCTUXEf/0eKlnfivnN0g1g+j/Lk9et/uoa6TFCW0HgwFOIVFumEYdT675PfuTrYO5o8ZrWEIHtv2Ctlrv9J3TrslD/iKEwtipGHtn0Vak8B9wLL+kz+CIQ/VG4KJpXjx88CeCC4XaGitEdjAAA" };
modelBuilder.Entity<LargeImageEntity>().HasData(picture);
modelBuilder.Entity<AthleteEntity>().HasData(
new AthleteEntity { IdAthlete = 1, Username = "Doe",ProfilPicture = picture, 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",ProfilPicture = picture, 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",ProfilPicture = picture, 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",ProfilPicture = picture, 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", ProfilPicture = picture,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 }
new AthleteEntity { IdAthlete = 1, Username = "Doe",ProfilPicture = picture2, ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") ,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 , DataSourceId = 1},
new AthleteEntity { IdAthlete = 2, Username = "Smith",ProfilPicture = picture2,ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") ,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",ProfilPicture = picture2,ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}") ,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, DataSourceId = 1},
new AthleteEntity { IdAthlete = 4, Username = "Brown",ProfilPicture = picture2, ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}"),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, DataSourceId = 2 },
new AthleteEntity { IdAthlete = 5, Username = "Lee", ProfilPicture = picture2, ImageId = Guid.Parse("{8d121cdc-6787-4738-8edd-9e026ac16b65}"),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 }
);
}
}

@ -43,7 +43,28 @@ namespace Model2Entities
// // Test de la méthode AddActivity
Console.WriteLine("Testing AddActivity method...");
var newActivity = new Activity(10, "New Activity", new DateTime(2021, 10, 10), new DateTime(10, 10, 10, 10, 10, 10), new DateTime(10, 10, 10, 12, 12, 12), 5, 5, 5, 5, 5, 5, 5, 5, false);
var user = new User
{
Id = 1, Username = "DoeDoe",
ProfilePicture =
"https://images.unsplash.com/photo-1682687982134-2ac563b2228b?q=80&w=2070&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDF8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
FirstName = "John", LastName = "Doe",
Sexe = "M", Lenght = 180, Weight = 70, DateOfBirth = new DateTime(1990, 1, 1),
Email = "john.doe@example.com", Role = new Athlete()
};
var dataSource = new DataSource(1, "Polar", "Vantage V2", 0.5f, new List<User> {user}, new List<Activity>());
var newActivity = new Activity(10, "New Activity", new DateTime(2021, 10, 10),
new DateTime(10, 10, 10, 10, 10, 10), new DateTime(10, 10, 10, 12, 12, 12), 5, 5, 5, 5, 5, 5, 5, 5,
false, user)
{
DataSource = dataSource
};
var HeartRates = new List<HeartRate>
{
new HeartRate(1, 60, new TimeOnly(10, 10, 10), newActivity, 5, 5, 5, 5, 5, 5, 5, 5),
};
newActivity.HeartRates = HeartRates;
var addedActivity = await activityRepository.AddActivity(newActivity);
if (addedActivity != null)
{

@ -753,9 +753,7 @@ class Program
static void AddUpdateDeleteAthlete(HeartTrackContext db)
{
Console.WriteLine("Test d'ajout, de modification et de suppression des athletes :");
var picture = System.Text.Encoding.UTF8.GetBytes(
"\"UklGRtwDAABXRUJQVlA4INADAAAwEACdASoqACoAAMASJZgCdMoSCz655ndU4XXAP2yXIge5neM/Qd6WCfO8evoj2S0A/p7+f0An85cBxlLDgPC8jO/0nsl/13/O8vvzj7Af8s/p3/H4FU6td4MCwq23z1H2uzoKIXaqJniPI/bRMf8qzv0Zp+HE1RCBw5WQ1j/JovdM1FS52+QcaAAA/v/+NxU4DpPk3+xQPW7tcmURSo9vC4qc+XMxNVBzEM5E8actDz98gmwTXgD62e9EmG/ervdd2ovFFSuxYppWl/wtaX3rkn0xrt8qOql/5I2jfLOnCU0kALLcW4F/wTjU10qsxZXW9fxauC6OPVRF28sc94V9ocmoSWy+sf6jW3vYkVOh+gE/RE0L6b2d3oFyHmkRJnfYwG8o3p6fv9pivNF5aopIBzFnjzwb/VqSq3/b+MWKFmjr8T1qe4/fITo2vBWEqDyogV3ZVGnDVi2DbiEFVSUr2eXTNZQ9V/D9QC/+vCR5TGyX9QOVBgtAYtm/ZTIwzPEYB9NrV1NeO1/sAz78u0tW59r0I+SO5Jgm3B9i1toRurzHv9EZJ9yZL8nafb/T1FaoPDkuJfM+iPs0j8xnS7TaU/gEK0wCxeDYRYtJx9j4hUQq7pAu/T2yWy0vjcUHki952ZNbXnXxB8m8pV5x9E1sfLj5MZEgpU2XV8RHrVvWniCjsf6vgxmR7+KtwIbMjahitUGtHet1WdL+8MmdL29iQJC37pDXirir1NibxKKhFYRuJ3xW9O0r9+Vnh8diqbBuXqDbYR/MSoHvscOCm2t95dN5WBdRUoD7YCG/ZHWc7Ypv/x/al4fkB2lZlYhVWHxjaoeF9jEPI0gAN5XsvUI6hbzEzWMsNW/1orkNOnlskalgmpI4B2rm4Gc7LNui+MuMBrpnBvLkbYX9exe9g8tu7wLt7ScOjDcL99oOyR89Mh9L8rd4+43+JQyR6tsIfcPJo6T6FxHf11d/MGayJi+SWct/uhvvua0oOh+zXNIaUzgoBmu1XULjkpuA0Ghzctf30jbY1AOM49qbMZRYS9A+0S1HrHPnwRvpQY/Sj4xKPn0gdpv/+iTbKJb8zkPC4/9af0Jvesa+GDG0/iw3TswenMhqlh7BM9MW5txpeblsByx4WnJ/oHv6cc0dmM7tsV36lYkCTUXEf/0eKlnfivnN0g1g+j/Lk9et/uoa6TFCW0HgwFOIVFumEYdT675PfuTrYO5o8ZrWEIHtv2Ctlrv9J3TrslD/iKEwtipGHtn0Vak8B9wLL+kz+CIQ/VG4KJpXjx88CeCC4XaGitEdjAAA\"");
var picture = "https://davidalmeida.site/assets/me_avatar.f77af006.png";
// Ajout d'un nouveau livre
var newAthlete = new AthleteEntity { Username = "Doe", LastName = "Doe",ProfilPicture = picture,FirstName = "John", Email = "essaie.example.com", Password = "TheNewPassword", Sexe = "M", Length = 1.80, Weight = 90, DateOfBirth = new DateOnly(2024, 02, 22), IsCoach = false };
db.AthletesSet.Add(newAthlete);

@ -1,4 +1,4 @@
using ApiMappeur;
using APIMappers;
using Dto;
using HeartTrackAPI.Controllers;
using HeartTrackAPI.Request;

Loading…
Cancel
Save