Skip to content

Commit c8c34a9

Browse files
committed
feat: add subtype handling to workout conversion and mapping for improved workout details
1 parent db4d895 commit c8c34a9

5 files changed

Lines changed: 8 additions & 0 deletions

File tree

boot/src/main/kotlin/org/freekode/tp2intervals/infrastructure/platform/intervalsicu/workout/FromIntervalsWorkoutConverter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class FromIntervalsWorkoutConverter(
2020
return Workout(
2121
WorkoutDetails(
2222
eventDTO.mapType(),
23+
eventDTO.mapSubType(),
2324
eventDTO.name,
2425
eventDTO.description,
2526
eventDTO.mapDuration(),

boot/src/main/kotlin/org/freekode/tp2intervals/infrastructure/platform/trainerroad/workout/TrainerRoadWorkoutMapper.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class TrainerRoadWorkoutMapper {
2626
fun toWorkoutDetails(detailsDTO: TrainerRoadWorkoutDetailsDTO, removeHtmlTags: Boolean): WorkoutDetails {
2727

2828
return WorkoutDetails(
29+
TrainingType.BIKE,
2930
if (detailsDTO.isOutside) TrainingType.BIKE else TrainingType.VIRTUAL_BIKE,
3031
detailsDTO.workoutName,
3132
getDescription(detailsDTO.workoutDescription, removeHtmlTags),

boot/src/main/kotlin/org/freekode/tp2intervals/infrastructure/platform/trainingpeaks/workout/TPBaseWorkoutResponseDTO.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ abstract class TPBaseWorkoutResponseDTO(
1515
val structure: TPWorkoutStructureDTO?
1616
) {
1717
fun getWorkoutType(): TrainingType? = workoutTypeValueId?.let { TPTrainingTypeMapper.getByValue(it) }
18+
fun getWorkoutSubType(): TrainingType? = workoutSubTypeValueId?.let { TPTrainingTypeMapper.getSubtypeByValue(it) }
1819
}

boot/src/main/kotlin/org/freekode/tp2intervals/infrastructure/platform/trainingpeaks/workout/TPToWorkoutConverter.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class TPToWorkoutConverter {
4343
return Workout(
4444
WorkoutDetails(
4545
tpWorkout.getWorkoutType()!!,
46+
tpWorkout.getWorkoutSubType()!!,
4647
if (tpWorkout.title.isNullOrBlank()) "Workout" else tpWorkout.title,
4748
description,
4849
tpWorkout.totalTimePlanned?.let { Duration.ofMinutes((it * 60).toLong()) },

boot/src/main/kotlin/org/freekode/tp2intervals/infrastructure/platform/trainingpeaks/workout/TPTrainingTypeMapper.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class TPTrainingTypeMapper {
3636
workoutSubTypeMap[trainingType] ?: workoutSubTypeMap[TrainingType.UNKNOWN]!!
3737

3838
fun getByValue(value: Int): TrainingType =
39+
workoutTypeMap.filterValues { it == value }.keys.firstOrNull()
40+
?: TrainingType.UNKNOWN
41+
42+
fun getSubtypeByValue(value: Int): TrainingType =
3943
workoutSubTypeMap.filterValues { it == value }.keys.firstOrNull()
4044
?: TrainingType.UNKNOWN
4145

0 commit comments

Comments
 (0)