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
continuous-integration/drone/push Build is passing
Details
parent
9176966c2d
commit
16b7c3051e
@ -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);
|
||||||
|
}
|
@ -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; }
|
||||||
|
}
|
@ -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;
|
@ -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 };
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace Entities;
|
||||||
|
|
||||||
|
public class LargeImageEntity
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
public string Base64 { get; set; }
|
||||||
|
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
Loading…
Reference in new issue