-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from freekode/tr-copy-workout
Copy workouts from TrainerRoad
- Loading branch information
Showing
92 changed files
with
1,356 additions
and
841 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
boot/src/main/kotlin/org/freekode/tp2intervals/app/plan/CopyLibraryRequest.kt
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
16 changes: 8 additions & 8 deletions
16
boot/src/main/kotlin/org/freekode/tp2intervals/app/plan/LibraryService.kt
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 |
---|---|---|
@@ -1,33 +1,33 @@ | ||
package org.freekode.tp2intervals.app.plan | ||
|
||
import org.freekode.tp2intervals.domain.Platform | ||
import org.freekode.tp2intervals.domain.plan.Plan | ||
import org.freekode.tp2intervals.domain.plan.PlanRepository | ||
import org.freekode.tp2intervals.domain.librarycontainer.LibraryContainer | ||
import org.freekode.tp2intervals.domain.librarycontainer.LibraryContainerRepository | ||
import org.freekode.tp2intervals.domain.workout.WorkoutRepository | ||
import org.freekode.tp2intervals.infrastructure.utils.Date | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class LibraryService( | ||
workoutRepositories: List<WorkoutRepository>, | ||
planRepositories: List<PlanRepository>, | ||
planRepositories: List<LibraryContainerRepository>, | ||
) { | ||
private val workoutRepositoryMap = workoutRepositories.associateBy { it.platform() } | ||
private val planRepositoryMap = planRepositories.associateBy { it.platform() } | ||
|
||
fun getLibraries(platform: Platform): List<Plan> { | ||
fun getLibraryContainers(platform: Platform): List<LibraryContainer> { | ||
val repository = planRepositoryMap[platform]!! | ||
return repository.getLibraries() | ||
return repository.getLibraryContainer() | ||
} | ||
|
||
fun copyLibrary(request: CopyLibraryRequest): CopyPlanResponse { | ||
val targetPlanRepository = planRepositoryMap[request.targetPlatform]!! | ||
val sourceWorkoutRepository = workoutRepositoryMap[request.sourcePlatform]!! | ||
val targetWorkoutRepository = workoutRepositoryMap[request.targetPlatform]!! | ||
|
||
val workouts = sourceWorkoutRepository.getWorkoutsFromLibrary(request.plan) | ||
val newPlan = targetPlanRepository.createPlan(request.newName, Date.thisMonday(), true) | ||
workouts.forEach { targetWorkoutRepository.saveWorkoutToLibrary(it, newPlan) } | ||
val workouts = sourceWorkoutRepository.getWorkoutsFromLibrary(request.libraryContainer) | ||
val newPlan = targetPlanRepository.createLibraryContainer(request.newName, Date.thisMonday(), true) | ||
workouts.forEach { targetWorkoutRepository.saveWorkoutToLibrary(newPlan, it) } | ||
return CopyPlanResponse(newPlan.name, workouts.size) | ||
} | ||
} |
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
13 changes: 13 additions & 0 deletions
13
.../src/main/kotlin/org/freekode/tp2intervals/app/workout/CopyFromLibraryToLibraryRequest.kt
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,13 @@ | ||
package org.freekode.tp2intervals.app.workout | ||
|
||
import org.freekode.tp2intervals.domain.Platform | ||
import org.freekode.tp2intervals.domain.librarycontainer.LibraryContainer | ||
import org.freekode.tp2intervals.domain.workout.WorkoutDetails | ||
import org.freekode.tp2intervals.rest.workout.WorkoutDetailsDTO | ||
|
||
class CopyFromLibraryToLibraryRequest( | ||
val workoutDetails: WorkoutDetailsDTO, | ||
val targetLibraryContainer: LibraryContainer, | ||
val sourcePlatform: Platform, | ||
val targetPlatform: Platform, | ||
) |
10 changes: 0 additions & 10 deletions
10
boot/src/main/kotlin/org/freekode/tp2intervals/app/workout/CopyPlannedWorkoutsResponse.kt
This file was deleted.
Oops, something went wrong.
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
47 changes: 29 additions & 18 deletions
47
boot/src/main/kotlin/org/freekode/tp2intervals/app/workout/WorkoutService.kt
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 |
---|---|---|
@@ -1,60 +1,71 @@ | ||
package org.freekode.tp2intervals.app.workout | ||
|
||
import java.time.LocalDate | ||
import org.freekode.tp2intervals.domain.Platform | ||
import org.freekode.tp2intervals.domain.plan.PlanRepository | ||
import org.freekode.tp2intervals.domain.workout.Workout | ||
import org.freekode.tp2intervals.domain.TrainingType | ||
import org.freekode.tp2intervals.domain.librarycontainer.LibraryContainerRepository | ||
import org.freekode.tp2intervals.domain.workout.WorkoutDetails | ||
import org.freekode.tp2intervals.domain.workout.WorkoutRepository | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class WorkoutService( | ||
workoutRepositories: List<WorkoutRepository>, | ||
planRepositories: List<PlanRepository>, | ||
planRepositories: List<LibraryContainerRepository>, | ||
) { | ||
private val workoutRepositoryMap = workoutRepositories.associateBy { it.platform() } | ||
private val planRepositoryMap = planRepositories.associateBy { it.platform() } | ||
|
||
fun copyPlannedWorkouts(request: CopyPlannedWorkoutsRequest): CopyPlannedWorkoutsResponse { | ||
fun copyWorkoutsFromCalendarToCalendar(request: CopyFromCalendarToCalendarRequest): CopyWorkoutsResponse { | ||
val sourceWorkoutRepository = workoutRepositoryMap[request.sourcePlatform]!! | ||
val targetWorkoutRepository = workoutRepositoryMap[request.targetPlatform]!! | ||
|
||
val allWorkoutsToPlan = sourceWorkoutRepository.getPlannedWorkouts(request.startDate, request.endDate) | ||
val allWorkoutsToPlan = sourceWorkoutRepository.getWorkoutsFromCalendar(request.startDate, request.endDate) | ||
var filteredWorkoutsToPlan = allWorkoutsToPlan | ||
.filter { request.types.contains(it.type) } | ||
.filter { request.types.contains(it.details.type) } | ||
if (request.skipSynced) { | ||
val plannedWorkouts = targetWorkoutRepository.getPlannedWorkouts(request.startDate, request.endDate) | ||
.filter { request.types.contains(it.type) } | ||
val plannedWorkouts = targetWorkoutRepository.getWorkoutsFromCalendar(request.startDate, request.endDate) | ||
.filter { request.types.contains(it.details.type) } | ||
|
||
filteredWorkoutsToPlan = filteredWorkoutsToPlan | ||
.filter { !plannedWorkouts.contains(it) } | ||
} | ||
|
||
val response = CopyPlannedWorkoutsResponse( | ||
val response = CopyWorkoutsResponse( | ||
filteredWorkoutsToPlan.size, | ||
allWorkoutsToPlan.size - filteredWorkoutsToPlan.size, | ||
request.startDate, | ||
request.endDate | ||
) | ||
filteredWorkoutsToPlan.forEach { targetWorkoutRepository.planWorkout(it) } | ||
filteredWorkoutsToPlan.forEach { targetWorkoutRepository.saveWorkoutToCalendar(it) } | ||
return response | ||
} | ||
|
||
fun copyPlannedWorkoutsToLibrary(request: CopyPlannedToLibraryWorkoutsRequest): CopyPlannedToLibraryResponse { | ||
fun copyWorkoutsFromCalendarToLibrary(request: CopyFromCalendarToLibraryRequest): CopyWorkoutsResponse { | ||
val sourceWorkoutRepository = workoutRepositoryMap[request.sourcePlatform]!! | ||
val targetWorkoutRepository = workoutRepositoryMap[request.targetPlatform]!! | ||
val targetPlanRepository = planRepositoryMap[request.targetPlatform]!! | ||
|
||
val allWorkouts = sourceWorkoutRepository.getPlannedWorkouts(request.startDate, request.endDate) | ||
val filteredWorkouts = allWorkouts.filter { request.types.contains(it.type) } | ||
val allWorkouts = sourceWorkoutRepository.getWorkoutsFromCalendar(request.startDate, request.endDate) | ||
val filteredWorkouts = allWorkouts.filter { request.types.contains(it.details.type) } | ||
|
||
val plan = targetPlanRepository.createPlan(request.name, request.startDate, request.isPlan) | ||
filteredWorkouts.forEach { targetWorkoutRepository.saveWorkoutToLibrary(it, plan) } | ||
return CopyPlannedToLibraryResponse( | ||
val plan = targetPlanRepository.createLibraryContainer(request.name, request.startDate, request.isPlan) | ||
filteredWorkouts.forEach { targetWorkoutRepository.saveWorkoutToLibrary(plan, it) } | ||
return CopyWorkoutsResponse( | ||
filteredWorkouts.size, allWorkouts.size - filteredWorkouts.size, request.startDate, request.endDate | ||
) | ||
} | ||
|
||
fun findWorkoutsByName(platform: Platform, name: String): List<Workout> { | ||
TODO("not implemented") | ||
fun copyWorkoutFromLibraryToLibrary(request: CopyFromLibraryToLibraryRequest): CopyWorkoutsResponse { | ||
val sourceWorkoutRepository = workoutRepositoryMap[request.sourcePlatform]!! | ||
val targetWorkoutRepository = workoutRepositoryMap[request.targetPlatform]!! | ||
|
||
val workout = sourceWorkoutRepository.getWorkoutFromLibrary(request.workoutDetails.externalData) | ||
targetWorkoutRepository.saveWorkoutToLibrary(request.targetLibraryContainer, workout) | ||
return CopyWorkoutsResponse(1, 0, LocalDate.now(), LocalDate.now()) | ||
} | ||
|
||
fun findWorkoutsByName(platform: Platform, name: String): List<WorkoutDetails> { | ||
return workoutRepositoryMap[platform]!!.findWorkoutsFromLibraryByName(name) | ||
} | ||
} |
9 changes: 5 additions & 4 deletions
9
...freekode/tp2intervals/domain/plan/Plan.kt → ...main/librarycontainer/LibraryContainer.kt
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 |
---|---|---|
@@ -1,19 +1,20 @@ | ||
package org.freekode.tp2intervals.domain.plan | ||
package org.freekode.tp2intervals.domain.librarycontainer | ||
|
||
import java.io.Serializable | ||
import java.time.LocalDate | ||
import org.freekode.tp2intervals.domain.ExternalData | ||
import org.freekode.tp2intervals.infrastructure.utils.Date | ||
|
||
data class Plan( | ||
data class LibraryContainer( | ||
val name: String, | ||
val startDate: LocalDate, | ||
val isPlan: Boolean, | ||
val workoutsAmount: Int, | ||
val externalData: ExternalData, | ||
) : Serializable { | ||
companion object { | ||
fun planFromMonday(name: String, externalData: ExternalData): Plan { | ||
return Plan(name, Date.thisMonday(), true, externalData) | ||
fun planFromMonday(name: String, workoutsAmount: Int, externalData: ExternalData): LibraryContainer { | ||
return LibraryContainer(name, Date.thisMonday(), true, workoutsAmount, externalData) | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...in/kotlin/org/freekode/tp2intervals/domain/librarycontainer/LibraryContainerRepository.kt
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,12 @@ | ||
package org.freekode.tp2intervals.domain.librarycontainer | ||
|
||
import org.freekode.tp2intervals.domain.Platform | ||
import java.time.LocalDate | ||
|
||
interface LibraryContainerRepository { | ||
fun platform(): Platform | ||
|
||
fun createLibraryContainer(name: String, startDate: LocalDate, isPlan: Boolean): LibraryContainer | ||
|
||
fun getLibraryContainer(): List<LibraryContainer> | ||
} |
12 changes: 0 additions & 12 deletions
12
boot/src/main/kotlin/org/freekode/tp2intervals/domain/plan/PlanRepository.kt
This file was deleted.
Oops, something went wrong.
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
39 changes: 39 additions & 0 deletions
39
boot/src/main/kotlin/org/freekode/tp2intervals/domain/workout/WorkoutDetails.kt
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,39 @@ | ||
package org.freekode.tp2intervals.domain.workout | ||
|
||
import java.io.Serializable | ||
import java.time.Duration | ||
import java.time.LocalDate | ||
import org.freekode.tp2intervals.domain.ExternalData | ||
import org.freekode.tp2intervals.domain.TrainingType | ||
|
||
data class WorkoutDetails( | ||
val type: TrainingType, | ||
val name: String, | ||
val description: String?, | ||
val duration: Duration?, | ||
val load: Int?, | ||
val externalData: ExternalData, | ||
) : Serializable { | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as WorkoutDetails | ||
|
||
if (type != other.type) return false | ||
if (name != other.name) return false | ||
if (load != other.load) return false | ||
if (externalData != other.externalData) return false | ||
|
||
return true | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = type.hashCode() | ||
result = 31 * result + name.hashCode() | ||
result = 31 * result + (load ?: 0) | ||
result = 31 * result + externalData.hashCode() | ||
return result | ||
} | ||
} |
15 changes: 10 additions & 5 deletions
15
boot/src/main/kotlin/org/freekode/tp2intervals/domain/workout/WorkoutRepository.kt
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 |
---|---|---|
@@ -1,17 +1,22 @@ | ||
package org.freekode.tp2intervals.domain.workout | ||
|
||
import java.time.LocalDate | ||
import org.freekode.tp2intervals.domain.ExternalData | ||
import org.freekode.tp2intervals.domain.Platform | ||
import org.freekode.tp2intervals.domain.plan.Plan | ||
import org.freekode.tp2intervals.domain.librarycontainer.LibraryContainer | ||
|
||
interface WorkoutRepository { | ||
fun platform(): Platform | ||
|
||
fun getPlannedWorkouts(startDate: LocalDate, endDate: LocalDate): List<Workout> | ||
fun getWorkoutsFromCalendar(startDate: LocalDate, endDate: LocalDate): List<Workout> | ||
|
||
fun planWorkout(workout: Workout) | ||
fun getWorkoutsFromLibrary(libraryContainer: LibraryContainer): List<Workout> | ||
|
||
fun getWorkoutsFromLibrary(plan: Plan): List<Workout> | ||
fun getWorkoutFromLibrary(externalData: ExternalData): Workout | ||
|
||
fun saveWorkoutToLibrary(workout: Workout, plan: Plan) | ||
fun findWorkoutsFromLibraryByName(name: String): List<WorkoutDetails> | ||
|
||
fun saveWorkoutToCalendar(workout: Workout) | ||
|
||
fun saveWorkoutToLibrary(libraryContainer: LibraryContainer, workout: Workout) | ||
} |
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.