-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
301 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using CyclingApp.Models; | ||
|
||
namespace CyclingApp.DTOs; | ||
|
||
/// <summary> | ||
/// Contains convert extensions for DTOs. | ||
/// </summary> | ||
internal static class ConvertExtensions | ||
{ | ||
/// <summary> | ||
/// Create a <see cref="GeoLocation"/> model from the DTO. | ||
/// </summary> | ||
/// <param name="dto">The DTO.</param> | ||
/// <returns>The created model.</returns> | ||
public static GeoLocation ToModel(this StoreGeoLocationDto dto) | ||
{ | ||
return new GeoLocation(dto.Timestamp, dto.Longitude, dto.Latitude, dto.Accuracy, dto.Altitude, | ||
dto.AltitudeAccuracy, dto.Heading, dto.Speed); | ||
} | ||
|
||
/// <summary> | ||
/// Create a <see cref="StoreGeoLocationDto"/> from the model. | ||
/// </summary> | ||
/// <param name="geoLocation">The model.</param> | ||
/// <returns>THe created DTO.</returns> | ||
public static StoreGeoLocationDto ToDto(this GeoLocation geoLocation) | ||
{ | ||
return new StoreGeoLocationDto | ||
{ | ||
Longitude = geoLocation.Longitude, | ||
Latitude = geoLocation.Latitude, | ||
Accuracy = geoLocation.Accuracy, | ||
Altitude = geoLocation.Altitude, | ||
AltitudeAccuracy = geoLocation.AltitudeAccuracy, | ||
Heading = geoLocation.Heading, | ||
Speed = geoLocation.Speed, | ||
Timestamp = geoLocation.Timestamp, | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// Create a <see cref="GeoLocation"/> model from the DTO. | ||
/// </summary> | ||
/// <param name="dto">The DTO.</param> | ||
/// <param name="id">The id of the activity to create.</param> | ||
/// <returns>The created model.</returns> | ||
public static Activity ToModel(this StoreActivityDto dto, Guid id) | ||
{ | ||
var waypoints = dto.Route.Select(x => x.ToModel()).ToList(); | ||
var route = new ReadOnlyRoute(waypoints); | ||
return new Activity(id, dto.CreationTime, dto.Duration, route); | ||
} | ||
|
||
/// <summary> | ||
/// Create a <see cref="StoreActivityDto"/> from the model. | ||
/// </summary> | ||
/// <param name="activity">The model.</param> | ||
/// <returns>THe created DTO.</returns> | ||
public static StoreActivityDto ToDto(this Activity activity) | ||
{ | ||
return new StoreActivityDto | ||
{ | ||
CreationTime = activity.CreationTime, | ||
Duration = activity.Duration, | ||
Route = activity.Route.Waypoints.Select(x => x.ToDto()).ToArray() | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using CyclingApp.Models; | ||
|
||
namespace CyclingApp.DTOs; | ||
|
||
/// <summary> | ||
/// DTO to store an <see cref="Activity"/>. | ||
/// </summary> | ||
internal class StoreActivityDto | ||
{ | ||
/// <inheritdoc cref="Activity.CreationTime"/> | ||
public DateTime CreationTime { get; set; } | ||
|
||
/// <inheritdoc cref="Activity.Duration"/> | ||
public TimeSpan Duration { get; set; } | ||
|
||
/// <inheritdoc cref="Activity.Route"/> | ||
public StoreGeoLocationDto[] Route { get; set; } = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using CyclingApp.Models; | ||
|
||
namespace CyclingApp.DTOs; | ||
|
||
/// <summary> | ||
/// DTO to store a <see cref="GeoLocation"/>. | ||
/// </summary> | ||
internal class StoreGeoLocationDto | ||
{ | ||
/// <inheritdoc cref="GeoLocation.Longitude"/> | ||
public double Longitude { get; set; } | ||
|
||
/// <inheritdoc cref="GeoLocation.Latitude"/> | ||
public double Latitude { get; set; } | ||
|
||
/// <inheritdoc cref="GeoLocation.Accuracy"/> | ||
public double Accuracy { get; set; } | ||
|
||
/// <inheritdoc cref="GeoLocation.Altitude"/> | ||
public double? Altitude { get; set; } | ||
|
||
/// <inheritdoc cref="GeoLocation.AltitudeAccuracy"/> | ||
public double? AltitudeAccuracy { get; set; } | ||
|
||
/// <inheritdoc cref="GeoLocation.Heading"/> | ||
public double? Heading { get; set; } | ||
|
||
/// <inheritdoc cref="GeoLocation.Speed"/> | ||
public double? Speed { get; set; } | ||
|
||
/// <inheritdoc cref="GeoLocation.Timestamp"/> | ||
public DateTime Timestamp { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.