Skip to content

Commit

Permalink
REFACT :: Routine Detail에 isCompleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Daybreak312 committed Aug 20, 2024
1 parent c3a920c commit 8ff28ba
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.info.maeumgagym.core.routine.port.`in`

import com.info.maeumgagym.core.routine.dto.response.RoutineResponse
import com.info.maeumgagym.core.routine.dto.response.CompletableRoutineResponse

interface ReadRoutineUseCase {
fun readFromId(routineId: Long): RoutineResponse
fun readFromId(routineId: Long): CompletableRoutineResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@ import com.info.maeumgagym.common.annotation.responsibility.ReadOnlyUseCase
import com.info.maeumgagym.common.exception.BusinessLogicException
import com.info.maeumgagym.common.exception.SecurityException
import com.info.maeumgagym.core.auth.port.out.ReadCurrentUserPort
import com.info.maeumgagym.core.routine.dto.response.RoutineResponse
import com.info.maeumgagym.core.routine.dto.response.CompletableRoutineResponse
import com.info.maeumgagym.core.routine.port.`in`.ReadRoutineUseCase
import com.info.maeumgagym.core.routine.port.out.ExistsRoutineHistoryPort
import com.info.maeumgagym.core.routine.port.out.ReadRoutinePort

@ReadOnlyUseCase
internal class ReadRoutineService(
private val readRoutinePort: ReadRoutinePort,
private val existsRoutineHistoryPort: ExistsRoutineHistoryPort,
private val readCurrentUserPort: ReadCurrentUserPort
) : ReadRoutineUseCase {
override fun readFromId(routineId: Long): RoutineResponse {
override fun readFromId(routineId: Long): CompletableRoutineResponse {
val routine = readRoutinePort.readById(routineId)
?: throw BusinessLogicException.ROUTINE_NOT_FOUND

if (routine.userId != readCurrentUserPort.readCurrentUser().id) {
throw SecurityException.PERMISSION_DENIED
}

return routine.toResponse()
return routine.toResponse(
isCompleted = existsRoutineHistoryPort.existByOriginIdToday(routine.id!!)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.info.maeumgagym.presentation.controller.routine
import com.info.maeumgagym.common.annotation.responsibility.WebAdapter
import com.info.maeumgagym.common.annotation.security.RequireAuthentication
import com.info.maeumgagym.core.routine.dto.response.CompletableRoutineListResponse
import com.info.maeumgagym.core.routine.dto.response.CompletableRoutineResponse
import com.info.maeumgagym.core.routine.dto.response.RoutineHistoryListResponse
import com.info.maeumgagym.core.routine.dto.response.RoutineResponse
import com.info.maeumgagym.core.routine.port.`in`.*
import com.info.maeumgagym.presentation.common.locationheader.LocationHeaderManager
import com.info.maeumgagym.presentation.controller.routine.dto.CreateRoutineWebRequest
Expand Down Expand Up @@ -100,7 +100,7 @@ private class RoutineController(
@Valid
@Positive(message = "0보다 커야 합니다.")
id: Long
): RoutineResponse = readRoutineUseCase.readFromId(id)
): CompletableRoutineResponse = readRoutineUseCase.readFromId(id)

@Operation(summary = "루틴 완료 API")
@ResponseStatus(HttpStatus.NO_CONTENT)
Expand Down

0 comments on commit 8ff28ba

Please sign in to comment.