Repository navigation
[REFACTOR/#227] 운동 타임라인 경로, 사진 마커를 기기 데이터로 표시 #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
73f4af0
[FEAT/#227] 저장을 마친 운동 경로를 메모리에 남기는 저장소 메서드 추가
seungjunGong 9545d69
[MOD/#227] 운동 저장에 성공하면 타임라인에 쓸 경로를 남기기
seungjunGong 42ae495
[FEAT/#227] 타임라인 경로, 사진 마커를 기기 데이터로 표시
seungjunGong 37ad4ef
[REFACTOR/#227] 타임라인 경로 조회 UseCase 추가
seungjunGong 3472703
[REFACTOR/#227] 타임라인 경로를 UseCase로 조회
seungjunGong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
core/domain/src/main/java/com/routee/android/core/domain/timeline/GetTimelineTrackUseCase.kt
This file contains hidden or 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,36 @@ | ||
| package com.routee.android.core.domain.timeline | ||
|
|
||
| import com.routee.android.core.data.recap.model.ActivityTrack | ||
| import com.routee.android.core.data.recap.model.TimelineMarker | ||
| import com.routee.android.core.data.recap.model.TrackPoint as ActivityTrackPoint | ||
| import com.routee.android.core.data.recap.repository.RecapRepository | ||
| import com.routee.android.core.data.workout.model.TrackPoint as WorkoutTrackPoint | ||
| import com.routee.android.core.data.workout.model.WorkoutPhoto | ||
| import com.routee.android.core.data.workout.repository.WorkoutPhotoRepository | ||
| import com.routee.android.core.data.workout.repository.WorkoutTrackingRepository | ||
| import javax.inject.Inject | ||
|
|
||
| /** 타임라인 지도 경로와 사진 마커, 기기에 남긴 경로가 있으면 서버를 부르지 않음 */ | ||
| class GetTimelineTrackUseCase @Inject constructor( | ||
| private val trackingRepository: WorkoutTrackingRepository, | ||
| private val photoRepository: WorkoutPhotoRepository, | ||
| private val recapRepository: RecapRepository, | ||
| ) { | ||
| suspend operator fun invoke(activityId: Long): Result<ActivityTrack> { | ||
| val deviceRoute = trackingRepository.getSavedTrackPoints(activityId) | ||
| ?: return recapRepository.getActivityTrack(activityId) | ||
| val markers = photoRepository.photos.value.toTimelineMarkers(activityId) | ||
| return Result.success(ActivityTrack(deviceRoute.map { it.toActivityTrackPoint() }, markers)) | ||
| } | ||
| } | ||
|
|
||
| private fun WorkoutTrackPoint.toActivityTrackPoint() = ActivityTrackPoint(latitude, longitude, elevation, pointIndex) | ||
|
|
||
| // 서버에 올린 사진만 | ||
| private fun List<WorkoutPhoto>.toTimelineMarkers(activityId: Long): List<TimelineMarker> = | ||
| filter { it.activityId == activityId } | ||
| .mapNotNull { photo -> | ||
| val timelineId = photo.timelineId ?: return@mapNotNull null | ||
| val imageUrl = photo.imageUrl() ?: return@mapNotNull null | ||
| TimelineMarker(timelineId, imageUrl, photo.point.latitude, photo.point.longitude, photo.point.pointIndex) | ||
| } |
This file contains hidden or 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 hidden or 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
88 changes: 88 additions & 0 deletions
88
...main/src/test/java/com/routee/android/core/domain/timeline/GetTimelineTrackUseCaseTest.kt
This file contains hidden or 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,88 @@ | ||
| package com.routee.android.core.domain.timeline | ||
|
|
||
| import com.routee.android.core.data.recap.model.ActivityRecap | ||
| import com.routee.android.core.data.recap.model.ActivityTrack | ||
| import com.routee.android.core.data.recap.model.RecapEditorData | ||
| import com.routee.android.core.data.recap.model.RecapResource | ||
| import com.routee.android.core.data.recap.model.TimelineMarker | ||
| import com.routee.android.core.data.recap.repository.RecapRepository | ||
| import com.routee.android.core.domain.workout.FakePhotoTrackingRepository | ||
| import com.routee.android.core.domain.workout.FakeWorkoutPhotoRepository | ||
| import com.routee.android.core.domain.workout.photoTrackPoint | ||
| import com.routee.android.core.domain.workout.workoutPhoto | ||
| import java.io.File | ||
| import java.time.YearMonth | ||
| import kotlinx.coroutines.test.runTest | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Test | ||
|
|
||
| class GetTimelineTrackUseCaseTest { | ||
| private val tracking = FakePhotoTrackingRepository(points = 0) | ||
| private val photos = FakeWorkoutPhotoRepository() | ||
| private val recap = FakeRecapRepository() | ||
| private val getTimelineTrack = GetTimelineTrackUseCase(tracking, photos, recap) | ||
|
|
||
| /** | ||
| * GIVEN: 저장을 마친 기록의 경로가 기기에 남아 있을 때 | ||
| * WHEN: 경로를 조회하면 | ||
| * THEN: 서버를 부르지 않고 기기 경로와 이 기록의 올린 사진만 마커로 돌려준다 | ||
| */ | ||
| @Test | ||
| fun `기기에 남긴 경로가 있으면 서버를 부르지 않는다`() = runTest { | ||
| tracking.savedRoute = ACTIVITY_ID to listOf(photoTrackPoint(0), photoTrackPoint(1)) | ||
| photos.setPhotos( | ||
| listOf( | ||
| workoutPhoto(1).copy(timelineId = 11), | ||
| workoutPhoto(2), | ||
| workoutPhoto(3, activityId = 8).copy(timelineId = 13), | ||
| ), | ||
| ) | ||
|
|
||
| val result = getTimelineTrack(ACTIVITY_ID).getOrThrow() | ||
|
|
||
| assertEquals(listOf(0, 1), result.trackPoints.map { it.pointIndex }) | ||
| assertEquals( | ||
| listOf(TimelineMarker(11, File("photo-1.jpg").toURI().toString(), 37.0, 127.0, 1)), | ||
| result.timelineMarkers, | ||
| ) | ||
| assertEquals(0, recap.trackRequestCount) | ||
| } | ||
|
|
||
| /** | ||
| * GIVEN: 앱이 다시 켜져 기기에 경로가 없을 때 | ||
| * WHEN: 경로를 조회하면 | ||
| * THEN: 서버에서 조회한다 | ||
| */ | ||
| @Test | ||
| fun `기기에 경로가 없으면 서버에서 조회한다`() = runTest { | ||
| val result = getTimelineTrack(ACTIVITY_ID).getOrThrow() | ||
|
|
||
| assertEquals(SERVER_TRACK, result) | ||
| assertEquals(1, recap.trackRequestCount) | ||
| } | ||
|
|
||
| private class FakeRecapRepository : RecapRepository { | ||
| var trackRequestCount = 0 | ||
|
|
||
| override suspend fun getMonthlyRecaps(month: YearMonth): Result<List<ActivityRecap>> = error("Unused") | ||
|
|
||
| override suspend fun updateRecapTitle( | ||
| activityId: Long, | ||
| title: String, | ||
| ): Result<Unit> = error("Unused") | ||
|
|
||
| override suspend fun getRecapResource(activityId: Long): Result<RecapResource> = error("Unused") | ||
|
|
||
| override suspend fun getActivityTrack(activityId: Long): Result<ActivityTrack> { | ||
| trackRequestCount++ | ||
| return Result.success(SERVER_TRACK) | ||
| } | ||
|
|
||
| override suspend fun getRecapEditorData(activityId: Long): Result<RecapEditorData> = error("Unused") | ||
| } | ||
|
|
||
| private companion object { | ||
| const val ACTIVITY_ID = 7L | ||
| val SERVER_TRACK = ActivityTrack(emptyList(), emptyList()) | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.