-
Notifications
You must be signed in to change notification settings - Fork 0
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 #214 from MaeumGaGym/Routine-한-요일에-다수-등록-가능하도록-수정
PR :: 루틴의 요일이 겹쳐도 되도록 변경
- Loading branch information
Showing
19 changed files
with
98 additions
and
167 deletions.
There are no files selected for viewing
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
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
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
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
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/com/info/maeumgagym/core/routine/port/in/CompleteRoutineUseCase.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,5 @@ | ||
package com.info.maeumgagym.core.routine.port.`in` | ||
|
||
interface CompleteRoutineUseCase { | ||
fun completeFromId(id: Long) | ||
} |
5 changes: 0 additions & 5 deletions
5
src/main/kotlin/com/info/maeumgagym/core/routine/port/in/CompleteTodayRoutineUseCase.kt
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
src/main/kotlin/com/info/maeumgagym/core/routine/port/in/ReadTodayRoutineUseCase.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,8 +1,8 @@ | ||
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.RoutineListResponse | ||
|
||
interface ReadTodayRoutineUseCase { | ||
|
||
fun readTodayRoutine(): RoutineResponse? | ||
fun readTodayRoutine(): RoutineListResponse | ||
} |
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
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/com/info/maeumgagym/core/routine/service/CompleteRoutineService.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,42 @@ | ||
package com.info.maeumgagym.core.routine.service | ||
|
||
import com.info.maeumgagym.common.annotation.responsibility.UseCase | ||
import com.info.maeumgagym.common.exception.BusinessLogicException | ||
import com.info.maeumgagym.core.auth.port.out.ReadCurrentUserPort | ||
import com.info.maeumgagym.core.routine.model.ExerciseInfoHistoryModel.Companion.toHistory | ||
import com.info.maeumgagym.core.routine.model.RoutineHistory | ||
import com.info.maeumgagym.core.routine.port.`in`.CompleteRoutineUseCase | ||
import com.info.maeumgagym.core.routine.port.out.ReadRoutinePort | ||
import com.info.maeumgagym.core.routine.port.out.SaveRoutineHistoryPort | ||
import java.time.LocalDate | ||
|
||
@UseCase | ||
class CompleteRoutineService( | ||
private val readCurrentUserPort: ReadCurrentUserPort, | ||
private val readRoutinePort: ReadRoutinePort, | ||
private val saveRoutineHistoryPort: SaveRoutineHistoryPort | ||
) : CompleteRoutineUseCase { | ||
|
||
override fun completeFromId(id: Long) { | ||
val user = readCurrentUserPort.readCurrentUser() | ||
|
||
val routine = readRoutinePort.readById(id) | ||
?: throw BusinessLogicException.ROUTINE_NOT_FOUND | ||
|
||
val now = LocalDate.now() | ||
|
||
if (!routine.dayOfWeeks!!.contains(now.dayOfWeek)) { | ||
throw BusinessLogicException(400, "It's Not Today's Routine") | ||
} | ||
|
||
saveRoutineHistoryPort.save( | ||
RoutineHistory( | ||
id = null, | ||
date = now, | ||
exerciseInfoHistoryList = routine.exerciseInfoModelList.map { it.toHistory() }, | ||
userId = user.id!!, | ||
routineName = routine.routineName | ||
) | ||
) | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
src/main/kotlin/com/info/maeumgagym/core/routine/service/CompleteTodayRoutineService.kt
This file was deleted.
Oops, something went wrong.
13 changes: 1 addition & 12 deletions
13
src/main/kotlin/com/info/maeumgagym/core/routine/service/CreateRoutineService.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
35 changes: 21 additions & 14 deletions
35
src/main/kotlin/com/info/maeumgagym/core/routine/service/ReadTodayRoutineService.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,31 +1,38 @@ | ||
package com.info.maeumgagym.core.routine.service | ||
|
||
import com.info.maeumgagym.common.annotation.responsibility.ReadOnlyUseCase | ||
import com.info.maeumgagym.common.exception.MaeumGaGymException | ||
import com.info.maeumgagym.core.auth.port.out.ReadCurrentUserPort | ||
import com.info.maeumgagym.common.exception.BusinessLogicException | ||
import com.info.maeumgagym.core.routine.dto.response.RoutineResponse | ||
import com.info.maeumgagym.core.routine.dto.response.RoutineListResponse | ||
import com.info.maeumgagym.core.routine.port.`in`.ReadTodayRoutineUseCase | ||
import com.info.maeumgagym.core.routine.port.out.ExistsRoutineHistoryPort | ||
import com.info.maeumgagym.core.routine.port.out.ReadRoutinePort | ||
import com.info.maeumgagym.core.user.dto.response.UserResponse | ||
import java.time.LocalDate | ||
|
||
@ReadOnlyUseCase | ||
class ReadTodayRoutineService( | ||
private val readRoutinePort: ReadRoutinePort, | ||
private val readCurrentUserPort: ReadCurrentUserPort, | ||
private val existsRoutineHistoryPort: ExistsRoutineHistoryPort | ||
private val readCurrentUserPort: ReadCurrentUserPort | ||
) : ReadTodayRoutineUseCase { | ||
|
||
override fun readTodayRoutine(): RoutineResponse? { | ||
val userId = readCurrentUserPort.readCurrentUser().id!! | ||
override fun readTodayRoutine(): RoutineListResponse { | ||
val user = readCurrentUserPort.readCurrentUser() | ||
|
||
val now = LocalDate.now() | ||
val routines = readRoutinePort.readByUserIdAndDayOfWeekAndIsArchivedFalse( | ||
user.id!!, | ||
LocalDate.now().dayOfWeek | ||
) | ||
|
||
return readRoutinePort.readByUserIdAndDayOfWeekAndIsArchivedFalse( | ||
userId, | ||
now.dayOfWeek | ||
)?.run { | ||
toResponse(existsRoutineHistoryPort.exsitsByUserIdAndDate(userId, now)) | ||
} ?: throw BusinessLogicException(204, "There's No Content Left") | ||
if (routines.isEmpty()) { | ||
throw MaeumGaGymException.NO_CONTENT | ||
} | ||
|
||
return RoutineListResponse( | ||
UserResponse( | ||
nickname = user.nickname, | ||
profileImage = user.profileImage | ||
), | ||
routines.map { it.toResponse() } | ||
) | ||
} | ||
} |
Oops, something went wrong.