Skip to content

Commit

Permalink
Merge pull request #347 from Runnect/feature/refactor-presentation-re…
Browse files Browse the repository at this point in the history
…sponse

[Refactor] Presentation Layer에서 Response 사용 중인 부분 수정
  • Loading branch information
dongx0915 authored Apr 30, 2024
2 parents 2f2fa5d + f16c18a commit 1283dc7
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@ import kotlinx.serialization.Serializable

@Serializable
data class ResponsePostMyDrawCourse(
@SerialName("data")
val data: Data
) {
@Serializable
data class Data(
@SerialName("id")
val id: Int,
@SerialName("createdAt")
val createdAt: String
)
}
@SerialName("id")
val id: Int,
@SerialName("createdAt")
val createdAt: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import com.runnect.runnect.data.dto.request.RequestPostPublicCourse
import com.runnect.runnect.data.dto.request.RequestPostRunningHistory
import com.runnect.runnect.data.dto.request.RequestPutMyDrawCourse
import com.runnect.runnect.data.dto.response.ResponseGetMyDrawDetail
import com.runnect.runnect.data.dto.response.ResponsePostDiscoverUpload
import com.runnect.runnect.data.dto.response.ResponsePostMyDrawCourse
import com.runnect.runnect.data.dto.response.ResponsePostMyHistory
import com.runnect.runnect.data.dto.response.ResponsePutMyDrawCourse
import com.runnect.runnect.data.network.mapToFlowResult
import com.runnect.runnect.data.source.remote.RemoteCourseDataSource
import com.runnect.runnect.domain.entity.CourseDetail
Expand All @@ -25,8 +21,9 @@ import okhttp3.MultipartBody
import okhttp3.RequestBody
import javax.inject.Inject

class CourseRepositoryImpl @Inject constructor(private val remoteCourseDataSource: RemoteCourseDataSource) :
CourseRepository {
class CourseRepositoryImpl @Inject constructor(
private val remoteCourseDataSource: RemoteCourseDataSource
) : CourseRepository {

override suspend fun getMarathonCourse(): Flow<Result<List<MarathonCourse>>> {
return remoteCourseDataSource.getMarathonCourse().mapToFlowResult {
Expand Down Expand Up @@ -66,8 +63,8 @@ class CourseRepositoryImpl @Inject constructor(private val remoteCourseDataSourc
return remoteCourseDataSource.getMyDrawDetail(courseId = courseId).mapToFlowResult { it }
}

override suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse): Flow<Result<ResponsePutMyDrawCourse>> {
return remoteCourseDataSource.deleteMyDrawCourse(deleteCourseList = deleteCourseList).mapToFlowResult { it }
override suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse): Flow<Result<Unit>> {
return remoteCourseDataSource.deleteMyDrawCourse(deleteCourseList = deleteCourseList).mapToFlowResult {}
}

override suspend fun postCourseScrap(
Expand All @@ -78,8 +75,8 @@ class CourseRepositoryImpl @Inject constructor(private val remoteCourseDataSourc
}
}

override suspend fun postUploadMyCourse(requestPostPublicCourse: RequestPostPublicCourse): Flow<Result<ResponsePostDiscoverUpload>> {
return remoteCourseDataSource.postUploadMyCourse(requestPostPublicCourse = requestPostPublicCourse).mapToFlowResult { it }
override suspend fun postUploadMyCourse(requestPostPublicCourse: RequestPostPublicCourse): Flow<Result<Unit>> {
return remoteCourseDataSource.postUploadMyCourse(requestPostPublicCourse = requestPostPublicCourse).mapToFlowResult {}
}

override suspend fun patchPublicCourse(
Expand All @@ -93,14 +90,16 @@ class CourseRepositoryImpl @Inject constructor(private val remoteCourseDataSourc
it.toEditableCourseDetail()
}

override suspend fun postRecord(request: RequestPostRunningHistory): Flow<Result<ResponsePostMyHistory>> {
return remoteCourseDataSource.postRecord(request = request).mapToFlowResult { it }
override suspend fun postRecord(request: RequestPostRunningHistory): Flow<Result<Unit>> {
return remoteCourseDataSource.postRecord(request = request).mapToFlowResult {}
}

override suspend fun uploadCourse(
image: MultipartBody.Part,
data: RequestBody
): Flow<Result<ResponsePostMyDrawCourse>> {
return remoteCourseDataSource.uploadCourse(image = image, data = data).mapToFlowResult { it }
): Flow<Result<Int>> {
return remoteCourseDataSource.uploadCourse(image = image, data = data).mapToFlowResult {
it.id
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.runnect.runnect.data.repository

import com.runnect.runnect.data.dto.request.RequestPutMyDrawCourse
import com.runnect.runnect.data.dto.response.ResponsePutMyDrawCourse
import com.runnect.runnect.data.dto.response.toMyDrawCourse
import com.runnect.runnect.data.network.mapToFlowResult
import com.runnect.runnect.data.source.remote.RemoteStorageDataSource
Expand All @@ -18,8 +17,8 @@ class StorageRepositoryImpl @Inject constructor(
override suspend fun getMyDrawCourse(): Flow<Result<List<MyDrawCourse>>> =
remoteStorageDataSource.getMyDrawCourse().mapToFlowResult { it.toMyDrawCourse() }

override suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse): Flow<Result<ResponsePutMyDrawCourse>> {
return remoteStorageDataSource.deleteMyDrawCourse(deleteCourseList = deleteCourseList).mapToFlowResult { it }
override suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse): Flow<Result<Unit>> {
return remoteStorageDataSource.deleteMyDrawCourse(deleteCourseList = deleteCourseList).mapToFlowResult {}
}

override suspend fun getMyScrapCourse(): Flow<Result<List<MyScrapCourse>>> =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
package com.runnect.runnect.data.repository

import com.runnect.runnect.data.dto.HistoryInfoDTO
import com.runnect.runnect.domain.entity.UserProfile
import com.runnect.runnect.data.dto.request.RequestDeleteHistory
import com.runnect.runnect.data.dto.request.RequestDeleteUploadCourse
import com.runnect.runnect.data.dto.request.RequestPatchHistoryTitle
import com.runnect.runnect.data.dto.request.RequestPatchNickName
import com.runnect.runnect.data.dto.response.ResponseDeleteHistory
import com.runnect.runnect.data.dto.response.ResponseDeleteUploadCourse
import com.runnect.runnect.data.dto.response.ResponseDeleteUser
import com.runnect.runnect.data.dto.response.ResponsePatchHistoryTitle
import com.runnect.runnect.data.dto.response.ResponsePatchUserNickName
import com.runnect.runnect.data.network.mapToFlowResult
import com.runnect.runnect.data.source.remote.RemoteUserDataSource
import com.runnect.runnect.domain.entity.User
import com.runnect.runnect.domain.entity.UserProfile
import com.runnect.runnect.domain.entity.UserUploadCourse
import com.runnect.runnect.domain.repository.UserRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class UserRepositoryImpl @Inject constructor(private val remoteUserDataSource: RemoteUserDataSource) :
UserRepository {
class UserRepositoryImpl @Inject constructor(
private val remoteUserDataSource: RemoteUserDataSource
) : UserRepository {

override suspend fun getUserInfo(): Flow<Result<User>> = remoteUserDataSource.getUserInfo()
.mapToFlowResult { it.toUser() }
Expand All @@ -33,29 +29,31 @@ class UserRepositoryImpl @Inject constructor(private val remoteUserDataSource: R

override suspend fun putDeleteUploadCourse(
requestDeleteUploadCourse: RequestDeleteUploadCourse
): Flow<Result<ResponseDeleteUploadCourse>> {
return remoteUserDataSource.putDeleteUploadCourse(requestDeleteUploadCourse).mapToFlowResult { it }
): Flow<Result<Unit>> {
return remoteUserDataSource.putDeleteUploadCourse(requestDeleteUploadCourse).mapToFlowResult {}
}

override suspend fun putDeleteHistory(
requestDeleteHistory: RequestDeleteHistory
): Flow<Result<ResponseDeleteHistory>> {
return remoteUserDataSource.putDeleteHistory(requestDeleteHistory).mapToFlowResult { it }
): Flow<Result<Unit>> {
return remoteUserDataSource.putDeleteHistory(requestDeleteHistory).mapToFlowResult {}
}

override suspend fun patchHistoryTitle(
historyId: Int, requestPatchHistoryTitle: RequestPatchHistoryTitle
): Flow<Result<ResponsePatchHistoryTitle>> =
remoteUserDataSource.patchHistoryTitle(historyId, requestPatchHistoryTitle).mapToFlowResult { it }
): Flow<Result<String>> =
remoteUserDataSource.patchHistoryTitle(historyId, requestPatchHistoryTitle).mapToFlowResult {
it.record.title
}

override suspend fun deleteUser(): Flow<Result<ResponseDeleteUser>> {
return remoteUserDataSource.deleteUser().mapToFlowResult { it }
override suspend fun deleteUser(): Flow<Result<Unit>> {
return remoteUserDataSource.deleteUser().mapToFlowResult {}
}

override suspend fun updateNickName(
requestPatchNickName: RequestPatchNickName
): Flow<Result<ResponsePatchUserNickName>> =
remoteUserDataSource.updateNickName(requestPatchNickName).mapToFlowResult { it }
): Flow<Result<Unit>> =
remoteUserDataSource.updateNickName(requestPatchNickName).mapToFlowResult {}

override suspend fun getRecord(): Flow<Result<List<HistoryInfoDTO>>> {
return remoteUserDataSource.getRecord().mapToFlowResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import com.runnect.runnect.data.dto.request.RequestPostPublicCourse
import com.runnect.runnect.data.dto.request.RequestPostRunningHistory
import com.runnect.runnect.data.dto.request.RequestPutMyDrawCourse
import com.runnect.runnect.data.dto.response.ResponseGetMyDrawDetail
import com.runnect.runnect.data.dto.response.ResponsePostDiscoverUpload
import com.runnect.runnect.data.dto.response.ResponsePostMyDrawCourse
import com.runnect.runnect.data.dto.response.ResponsePostMyHistory
import com.runnect.runnect.data.dto.response.ResponsePutMyDrawCourse
import com.runnect.runnect.domain.entity.CourseDetail
import com.runnect.runnect.domain.entity.DiscoverMultiViewItem.MarathonCourse
import com.runnect.runnect.domain.entity.DiscoverSearchCourse
Expand Down Expand Up @@ -37,20 +33,20 @@ interface CourseRepository {

suspend fun getMyDrawDetail(courseId: Int): Flow<Result<ResponseGetMyDrawDetail>>

suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse): Flow<Result<ResponsePutMyDrawCourse>>
suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse): Flow<Result<Unit>>

suspend fun postCourseScrap(requestPostCourseScrap: RequestPostCourseScrap): Flow<Result<PostScrap>>

suspend fun postUploadMyCourse(requestPostPublicCourse: RequestPostPublicCourse): Flow<Result<ResponsePostDiscoverUpload>>
suspend fun postUploadMyCourse(requestPostPublicCourse: RequestPostPublicCourse): Flow<Result<Unit>>

suspend fun patchPublicCourse(
publicCourseId: Int,
requestPatchPublicCourse: RequestPatchPublicCourse
): Flow<Result<EditableCourseDetail>>

suspend fun postRecord(request: RequestPostRunningHistory): Flow<Result<ResponsePostMyHistory>>
suspend fun postRecord(request: RequestPostRunningHistory): Flow<Result<Unit>>

suspend fun uploadCourse(
image: MultipartBody.Part, data: RequestBody
): Flow<Result<ResponsePostMyDrawCourse>>
): Flow<Result<Int>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import kotlinx.coroutines.flow.Flow
interface StorageRepository {
suspend fun getMyDrawCourse(): Flow<Result<List<MyDrawCourse>>>
suspend fun getMyScrapCourse(): Flow<Result<List<MyScrapCourse>>>
suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse) : Flow<Result<ResponsePutMyDrawCourse>>
suspend fun deleteMyDrawCourse(deleteCourseList: RequestPutMyDrawCourse) : Flow<Result<Unit>>
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
package com.runnect.runnect.domain.repository

import com.runnect.runnect.data.dto.HistoryInfoDTO
import com.runnect.runnect.domain.entity.UserProfile
import com.runnect.runnect.data.dto.request.RequestDeleteHistory
import com.runnect.runnect.data.dto.request.RequestDeleteUploadCourse
import com.runnect.runnect.data.dto.request.RequestPatchHistoryTitle
import com.runnect.runnect.data.dto.request.RequestPatchNickName
import com.runnect.runnect.data.dto.response.ResponseDeleteHistory
import com.runnect.runnect.data.dto.response.ResponseDeleteUploadCourse
import com.runnect.runnect.data.dto.response.ResponseDeleteUser
import com.runnect.runnect.data.dto.response.ResponsePatchHistoryTitle
import com.runnect.runnect.data.dto.response.ResponsePatchUserNickName
import com.runnect.runnect.domain.entity.User
import com.runnect.runnect.domain.entity.UserProfile
import com.runnect.runnect.domain.entity.UserUploadCourse
import kotlinx.coroutines.flow.Flow

Expand All @@ -22,11 +17,11 @@ interface UserRepository {

suspend fun putDeleteUploadCourse(
requestDeleteUploadCourse: RequestDeleteUploadCourse
): Flow<Result<ResponseDeleteUploadCourse>>
): Flow<Result<Unit>>

suspend fun putDeleteHistory(requestDeleteHistory: RequestDeleteHistory): Flow<Result<ResponseDeleteHistory>>
suspend fun putDeleteHistory(requestDeleteHistory: RequestDeleteHistory): Flow<Result<Unit>>

suspend fun deleteUser(): Flow<Result<ResponseDeleteUser>>
suspend fun deleteUser(): Flow<Result<Unit>>

suspend fun getRecord(): Flow<Result<List<HistoryInfoDTO>>>

Expand All @@ -35,11 +30,11 @@ interface UserRepository {
suspend fun patchHistoryTitle(
historyId: Int,
requestPatchHistoryTitle: RequestPatchHistoryTitle
): Flow<Result<ResponsePatchHistoryTitle>>
): Flow<Result<String>>

suspend fun updateNickName(
requestPatchNickName: RequestPatchNickName
): Flow<Result<ResponsePatchUserNickName>>
): Flow<Result<Unit>>

suspend fun getUserProfile(userId: Int): Flow<Result<UserProfile>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class CourseDetailViewModel @Inject constructor(
val coursePatchState: LiveData<UiStateV2<EditableCourseDetail?>>
get() = _coursePatchState

private val _courseDeleteState = MutableLiveData<UiStateV2<ResponseDeleteUploadCourse?>>()
val courseDeleteState: LiveData<UiStateV2<ResponseDeleteUploadCourse?>>
private val _courseDeleteState = MutableLiveData<UiStateV2<Unit>>()
val courseDeleteState: LiveData<UiStateV2<Unit>>
get() = _courseDeleteState

private val _courseScrapState = MutableLiveData<UiStateV2<PostScrap>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class DrawActivity : BindingActivity<ActivityDrawBinding>(R.layout.activity_draw

binding.tvGuide.isVisible = false
viewModel.searchResult.value = searchResult
viewModel.departureName.value = searchResult.name
viewModel.departureName = searchResult.name

setDepartureLatLng(
latLng = LatLng(
Expand Down Expand Up @@ -515,11 +515,11 @@ class DrawActivity : BindingActivity<ActivityDrawBinding>(R.layout.activity_draw
if (isCustomLocationMode) departureLatLng = customDepartureLatLng

val courseData = CourseData(
courseId = viewModel.uploadResult.value?.data?.id,
courseId = viewModel.uploadCourseId,
publicCourseId = null, //직접 생성하는 코스는 publicCourseId가 없지만 코스 발견 -> 러닝 등의 루트로 넘어올 시 기록 업로드에서 requestBody에 필요함
touchList = touchList,
startLatLng = departureLatLng,
departure = viewModel.departureName.value,
departure = viewModel.departureName,
distance = viewModel.distanceSum.value,
image = captureUri.toString(),
dataFrom = "fromDrawCourse"
Expand Down Expand Up @@ -791,18 +791,18 @@ class DrawActivity : BindingActivity<ActivityDrawBinding>(R.layout.activity_draw
val uploadLatLngList: List<UploadLatLng> = distanceList.map { latLng ->
UploadLatLng(latLng.latitude, latLng.longitude)
}
viewModel.path.value = uploadLatLngList
viewModel.path = uploadLatLngList

when {
isSearchLocationMode -> {
viewModel.departureAddress.value = searchResult.fullAddress
viewModel.departureName.value = searchResult.name
viewModel.departureAddress = searchResult.fullAddress
viewModel.departureName = searchResult.name
}

isCurrentLocationMode || isCustomLocationMode -> {
viewModel.departureAddress.value =
viewModel.reverseGeocodingResult.value?.fullAddress
viewModel.departureName.value =
viewModel.departureAddress =
viewModel.reverseGeocodingResult.value?.fullAddress ?: ""
viewModel.departureName =
viewModel.reverseGeocodingResult.value?.buildingName ?: "내가 설정한 출발지"
}
}
Expand Down
Loading

0 comments on commit 1283dc7

Please sign in to comment.