🐛 Test new mappers
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
da5b41e404
commit
90b00ed328
@ -0,0 +1,61 @@
|
|||||||
|
using Entities;
|
||||||
|
using Model;
|
||||||
|
using Shared;
|
||||||
|
|
||||||
|
namespace EFMappers;
|
||||||
|
|
||||||
|
public static class HeartRateMapper
|
||||||
|
{
|
||||||
|
private static GenericMapper<HeartRate, HeartRateEntity> _mapper = new GenericMapper<HeartRate, HeartRateEntity>();
|
||||||
|
// ! RESET
|
||||||
|
// ? Quand on fait appel au reset ?
|
||||||
|
// * Apres des saves changing ou rollback.
|
||||||
|
public static void Reset()
|
||||||
|
{
|
||||||
|
_mapper.Reset();
|
||||||
|
}
|
||||||
|
public static HeartRate ToModel(this HeartRateEntity entity)
|
||||||
|
{
|
||||||
|
// return entity.ToModel();
|
||||||
|
return entity.ToT(_mapper, heartRate => new HeartRate (
|
||||||
|
entity.IdHeartRate,
|
||||||
|
entity.Altitude,
|
||||||
|
entity.Time,
|
||||||
|
entity.Temperature,
|
||||||
|
entity.Bpm,
|
||||||
|
entity.Longitude,
|
||||||
|
entity.Latitude,
|
||||||
|
entity.ActivityId
|
||||||
|
)
|
||||||
|
// ! regarder a ce que le model est bien les relation comme l'EF
|
||||||
|
, (heartRate, entity) => heartRate.ActivityId = entity.ActivityId);
|
||||||
|
|
||||||
|
}
|
||||||
|
// dictionnaire;
|
||||||
|
|
||||||
|
|
||||||
|
public static HeartRateEntity? ToEntity(this HeartRate model)
|
||||||
|
{
|
||||||
|
// return model.ToEntity();
|
||||||
|
return model.ToU(_mapper, heartRateEntity => new HeartRateEntity
|
||||||
|
{
|
||||||
|
IdHeartRate = model.Id,
|
||||||
|
Altitude = model.Altitude,
|
||||||
|
Time = model.Time,
|
||||||
|
Temperature = model.Temperature,
|
||||||
|
Bpm = model.Bpm,
|
||||||
|
Longitude = model.Longitude,
|
||||||
|
Latitude = model.Latitude,
|
||||||
|
ActivityId = model.ActivityId
|
||||||
|
}
|
||||||
|
, (heartRate, entity) => entity.ActivityId = heartRate.ActivityId
|
||||||
|
// ! regarder a ce que le model est bien les relation comme l'EF
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IEnumerable<HeartRate?> ToModels(this IEnumerable<HeartRateEntity> entities)
|
||||||
|
=> entities.Select(hr => hr.ToModel());
|
||||||
|
|
||||||
|
public static IEnumerable<HeartRateEntity?> ToEntities(this IEnumerable<HeartRate> models)
|
||||||
|
=> models.Select(hr => hr.ToEntity());
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
using 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<Athlete> Athletes { get; set; } = new List<Athlete>();
|
||||||
|
public DataSource(int id, string type, string model, float precision, ICollection<Activity> activities, ICollection<Athlete> athletes)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
Type = type;
|
||||||
|
Model = model;
|
||||||
|
Precision = precision;
|
||||||
|
Activities = activities;
|
||||||
|
Athletes = athletes;
|
||||||
|
}
|
||||||
|
public DataSource(){}
|
||||||
|
|
||||||
|
public DataSource(int id, string type, string model, float precision)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
Type = type;
|
||||||
|
Model = model;
|
||||||
|
Precision = precision;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"DataSource #{Id}: {Type} {Model} with a precision of {Precision}";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
namespace Model;
|
||||||
|
|
||||||
|
public class HeartRate {
|
||||||
|
public int Id { get; set; }
|
||||||
|
public double Altitude { get; set; }
|
||||||
|
public TimeOnly Time { get; set; }
|
||||||
|
public float Temperature { get; set; }
|
||||||
|
public int Bpm { get; set; }
|
||||||
|
public float Longitude { get; set; }
|
||||||
|
public float Latitude { get; set; }
|
||||||
|
public int ActivityId { get; set; }
|
||||||
|
public HeartRate(int id, double altitude, TimeOnly time, float temperature, int bpm, float longitude, float latitude, int activityId)
|
||||||
|
{
|
||||||
|
Id = id;
|
||||||
|
Altitude = altitude;
|
||||||
|
Time = time;
|
||||||
|
Temperature = temperature;
|
||||||
|
Bpm = bpm;
|
||||||
|
Longitude = longitude;
|
||||||
|
Latitude = latitude;
|
||||||
|
ActivityId = activityId;
|
||||||
|
}
|
||||||
|
public HeartRate(){}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"HeartRate #{Id}: {Bpm} bpm at {Time:HH:mm:ss} with a temperature of {Temperature}°C" +
|
||||||
|
$" and an altitude of {Altitude}m at {Longitude}°E and {Latitude}°N";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue