Skip to content

Commit 5b2dcce

Browse files
committed
Refactor: 루틴 삭제 api 버전업 및 네이밍 수정
1 parent db0f031 commit 5b2dcce

8 files changed

Lines changed: 68 additions & 45 deletions

File tree

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.threegap.bitnagil.data.routine.datasource
22

3-
import com.threegap.bitnagil.data.routine.model.request.RoutineByDayDeletionRequestDto
43
import com.threegap.bitnagil.data.routine.model.request.RoutineCompletionRequestDto
54
import com.threegap.bitnagil.data.routine.model.response.RoutineDto
65
import com.threegap.bitnagil.data.routine.model.response.RoutinesResponseDto
76

87
interface RoutineRemoteDataSource {
98
suspend fun fetchWeeklyRoutines(startDate: String, endDate: String): Result<RoutinesResponseDto>
109
suspend fun syncRoutineCompletion(routineCompletionRequestDto: RoutineCompletionRequestDto): Result<Unit>
11-
suspend fun deleteRoutine(routineId: String): Result<Unit>
12-
suspend fun deleteRoutineByDay(routineByDayDeletionRequestDto: RoutineByDayDeletionRequestDto): Result<Unit>
1310
suspend fun getRoutine(routineId: String): Result<RoutineDto>
11+
suspend fun deleteRoutine(routineId: String): Result<Unit>
12+
suspend fun deleteRoutineForDay(routineId: String): Result<Unit>
1413
}

data/src/main/java/com/threegap/bitnagil/data/routine/datasourceImpl/RoutineRemoteDataSourceImpl.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.threegap.bitnagil.data.routine.datasourceImpl
33
import com.threegap.bitnagil.data.common.safeApiCall
44
import com.threegap.bitnagil.data.common.safeUnitApiCall
55
import com.threegap.bitnagil.data.routine.datasource.RoutineRemoteDataSource
6-
import com.threegap.bitnagil.data.routine.model.request.RoutineByDayDeletionRequestDto
76
import com.threegap.bitnagil.data.routine.model.request.RoutineCompletionRequestDto
87
import com.threegap.bitnagil.data.routine.model.response.RoutineDto
98
import com.threegap.bitnagil.data.routine.model.response.RoutinesResponseDto
@@ -23,18 +22,18 @@ class RoutineRemoteDataSourceImpl @Inject constructor(
2322
routineService.routineCompletion(routineCompletionRequestDto)
2423
}
2524

25+
override suspend fun getRoutine(routineId: String): Result<RoutineDto> =
26+
safeApiCall {
27+
routineService.getRoutine(routineId)
28+
}
29+
2630
override suspend fun deleteRoutine(routineId: String): Result<Unit> =
2731
safeUnitApiCall {
2832
routineService.deleteRoutine(routineId)
2933
}
3034

31-
override suspend fun deleteRoutineByDay(routineByDayDeletionRequestDto: RoutineByDayDeletionRequestDto): Result<Unit> =
35+
override suspend fun deleteRoutineForDay(routineId: String): Result<Unit> =
3236
safeUnitApiCall {
33-
routineService.deleteRoutineByDay(routineByDayDeletionRequestDto)
34-
}
35-
36-
override suspend fun getRoutine(routineId: String): Result<RoutineDto> =
37-
safeApiCall {
38-
routineService.getRoutine(routineId)
37+
routineService.deleteRoutineForDay(routineId)
3938
}
4039
}

data/src/main/java/com/threegap/bitnagil/data/routine/repositoryImpl/RoutineRepositoryImpl.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import com.threegap.bitnagil.data.routine.datasource.RoutineRemoteDataSource
44
import com.threegap.bitnagil.data.routine.model.request.toDto
55
import com.threegap.bitnagil.data.routine.model.response.toDomain
66
import com.threegap.bitnagil.domain.routine.model.Routine
7-
import com.threegap.bitnagil.domain.routine.model.RoutineByDayDeletion
87
import com.threegap.bitnagil.domain.routine.model.RoutineCompletionInfos
98
import com.threegap.bitnagil.domain.routine.model.Routines
109
import com.threegap.bitnagil.domain.routine.repository.RoutineRepository
@@ -20,12 +19,12 @@ class RoutineRepositoryImpl @Inject constructor(
2019
override suspend fun syncRoutineCompletion(routineCompletionInfos: RoutineCompletionInfos): Result<Unit> =
2120
routineRemoteDataSource.syncRoutineCompletion(routineCompletionInfos.toDto())
2221

23-
override suspend fun deleteRoutine(routineId: String): Result<Unit> =
24-
routineRemoteDataSource.deleteRoutine(routineId)
25-
2622
override suspend fun getRoutine(routineId: String): Result<Routine> =
2723
routineRemoteDataSource.getRoutine(routineId).map { it.toDomain() }
2824

29-
override suspend fun deleteRoutineByDay(routineByDayDeletion: RoutineByDayDeletion): Result<Unit> =
30-
routineRemoteDataSource.deleteRoutineByDay(routineByDayDeletion.toDto())
25+
override suspend fun deleteRoutine(routineId: String): Result<Unit> =
26+
routineRemoteDataSource.deleteRoutine(routineId)
27+
28+
override suspend fun deleteRoutineForDay(routineId: String): Result<Unit> =
29+
routineRemoteDataSource.deleteRoutineForDay(routineId)
3130
}
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.threegap.bitnagil.data.routine.service
22

3-
import com.threegap.bitnagil.data.routine.model.request.RoutineByDayDeletionRequestDto
43
import com.threegap.bitnagil.data.routine.model.request.RoutineCompletionRequestDto
54
import com.threegap.bitnagil.data.routine.model.response.RoutineDto
65
import com.threegap.bitnagil.data.routine.model.response.RoutinesResponseDto
76
import com.threegap.bitnagil.network.model.BaseResponse
87
import retrofit2.http.Body
98
import retrofit2.http.DELETE
109
import retrofit2.http.GET
11-
import retrofit2.http.HTTP
1210
import retrofit2.http.PUT
1311
import retrofit2.http.Path
1412
import retrofit2.http.Query
@@ -20,7 +18,12 @@ interface RoutineService {
2018
@Query("endDate") endDate: String,
2119
): BaseResponse<RoutinesResponseDto>
2220

23-
@PUT("/api/v2/routines")
21+
@GET("/api/v1/routines/{routineId}")
22+
suspend fun getRoutine(
23+
@Path("routineId") routineId: String,
24+
): BaseResponse<RoutineDto>
25+
26+
@PUT("/api/v2/routines/completions")
2427
suspend fun routineCompletion(
2528
@Body request: RoutineCompletionRequestDto,
2629
): BaseResponse<Unit>
@@ -30,13 +33,8 @@ interface RoutineService {
3033
@Path("routineId") routineId: String,
3134
): BaseResponse<Unit>
3235

33-
@GET("/api/v1/routines/{routineId}")
34-
suspend fun getRoutine(
36+
@DELETE("/api/v2/routines/day/{routineId}")
37+
suspend fun deleteRoutineForDay(
3538
@Path("routineId") routineId: String,
36-
): BaseResponse<RoutineDto>
37-
38-
@HTTP(method = "DELETE", path = "/api/v1/routines/day", hasBody = true)
39-
suspend fun deleteRoutineByDay(
40-
@Body request: RoutineByDayDeletionRequestDto,
4139
): BaseResponse<Unit>
4240
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package com.threegap.bitnagil.domain.routine.repository
22

33
import com.threegap.bitnagil.domain.routine.model.Routine
4-
import com.threegap.bitnagil.domain.routine.model.RoutineByDayDeletion
54
import com.threegap.bitnagil.domain.routine.model.RoutineCompletionInfos
65
import com.threegap.bitnagil.domain.routine.model.Routines
76

87
interface RoutineRepository {
98
suspend fun fetchWeeklyRoutines(startDate: String, endDate: String): Result<Routines>
109
suspend fun syncRoutineCompletion(routineCompletionInfos: RoutineCompletionInfos): Result<Unit>
11-
suspend fun deleteRoutine(routineId: String): Result<Unit>
1210
suspend fun getRoutine(routineId: String): Result<Routine>
13-
suspend fun deleteRoutineByDay(routineByDayDeletion: RoutineByDayDeletion): Result<Unit>
11+
suspend fun deleteRoutine(routineId: String): Result<Unit>
12+
suspend fun deleteRoutineForDay(routineId: String): Result<Unit>
1413
}

domain/src/main/java/com/threegap/bitnagil/domain/routine/usecase/DeleteRoutineByDayUseCase.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.threegap.bitnagil.domain.routine.usecase
2+
3+
import com.threegap.bitnagil.domain.routine.repository.RoutineRepository
4+
import javax.inject.Inject
5+
6+
class DeleteRoutineForDayUseCase @Inject constructor(
7+
private val routineRepository: RoutineRepository,
8+
) {
9+
suspend operator fun invoke(routineId: String): Result<Unit> =
10+
routineRepository.deleteRoutineForDay(routineId)
11+
}

presentation/src/main/java/com/threegap/bitnagil/presentation/routinelist/RoutineListViewModel.kt

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package com.threegap.bitnagil.presentation.routinelist
33
import android.util.Log
44
import androidx.lifecycle.SavedStateHandle
55
import androidx.lifecycle.viewModelScope
6+
import com.threegap.bitnagil.domain.routine.usecase.DeleteRoutineForDayUseCase
7+
import com.threegap.bitnagil.domain.routine.usecase.DeleteRoutineUseCase
68
import com.threegap.bitnagil.domain.routine.usecase.FetchWeeklyRoutinesUseCase
79
import com.threegap.bitnagil.presentation.common.mviviewmodel.MviViewModel
810
import com.threegap.bitnagil.presentation.home.util.getCurrentWeekDays
@@ -20,6 +22,8 @@ import javax.inject.Inject
2022
class RoutineListViewModel @Inject constructor(
2123
savedStateHandle: SavedStateHandle,
2224
private val fetchWeeklyRoutinesUseCase: FetchWeeklyRoutinesUseCase,
25+
private val deleteRoutineUseCase: DeleteRoutineUseCase,
26+
private val deleteRoutineForDayUseCase: DeleteRoutineForDayUseCase,
2327
) : MviViewModel<RoutineListState, RoutineListSideEffect, RoutineListIntent>(
2428
savedStateHandle = savedStateHandle,
2529
initState = RoutineListState(
@@ -67,7 +71,7 @@ class RoutineListViewModel @Inject constructor(
6771

6872
private fun fetchRoutines() {
6973
sendIntent(RoutineListIntent.UpdateLoading(true))
70-
val currentWeek = LocalDate.now().getCurrentWeekDays()
74+
val currentWeek = container.stateFlow.value.selectedDate.getCurrentWeekDays()
7175
val startDate = currentWeek.first().toString()
7276
val endDate = currentWeek.last().toString()
7377
viewModelScope.launch {
@@ -85,10 +89,36 @@ class RoutineListViewModel @Inject constructor(
8589
}
8690

8791
fun deleteRoutineCompletely() {
88-
viewModelScope.launch {}
92+
sendIntent(RoutineListIntent.UpdateLoading(true))
93+
val selectedRoutine = stateFlow.value.selectedRoutine!!
94+
viewModelScope.launch {
95+
deleteRoutineUseCase(selectedRoutine.routineId).fold(
96+
onSuccess = {
97+
sendIntent(RoutineListIntent.HideDeleteConfirmBottomSheet)
98+
sendIntent(RoutineListIntent.UpdateLoading(false))
99+
},
100+
onFailure = {
101+
Log.e("RoutineListViewModel", "루틴 삭제 실패: ${it.message}")
102+
sendIntent(RoutineListIntent.UpdateLoading(false))
103+
},
104+
)
105+
}
89106
}
90107

91108
fun deleteRoutineForToday() {
92-
viewModelScope.launch { }
109+
sendIntent(RoutineListIntent.UpdateLoading(true))
110+
val selectedRoutine = stateFlow.value.selectedRoutine!!
111+
viewModelScope.launch {
112+
deleteRoutineForDayUseCase(selectedRoutine.routineId).fold(
113+
onSuccess = {
114+
sendIntent(RoutineListIntent.HideDeleteConfirmBottomSheet)
115+
sendIntent(RoutineListIntent.UpdateLoading(false))
116+
},
117+
onFailure = {
118+
Log.e("RoutineListViewModel", "루틴 삭제 실패: ${it.message}")
119+
sendIntent(RoutineListIntent.UpdateLoading(false))
120+
},
121+
)
122+
}
93123
}
94124
}

0 commit comments

Comments
 (0)