-
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.
- Loading branch information
Showing
8 changed files
with
75 additions
and
17 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
10 changes: 7 additions & 3 deletions
10
src/main/kotlin/com/yedongsoon/example_project/application/example/ExampleQueryService.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,20 +1,24 @@ | ||
package com.yedongsoon.example_project.application.example | ||
|
||
import com.yedongsoon.example_project.application.couple.CoupleService | ||
import com.yedongsoon.example_project.application.exception.ExampleNotFoundException | ||
import com.yedongsoon.example_project.domain.example.Example | ||
import com.yedongsoon.example_project.domain.example.ExampleRepository | ||
import org.springframework.data.crossstore.ChangeSetPersister.NotFoundException | ||
import com.yedongsoon.example_project.infrastructure.couple.CoupleAdapter | ||
import org.slf4j.LoggerFactory | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ExampleQueryService( | ||
private val exampleRepository: ExampleRepository, | ||
private val coupleService: CoupleService, | ||
) { | ||
private val logger = LoggerFactory.getLogger(CoupleAdapter::class.java) | ||
suspend fun getExampleInfo(exampleInfoNo: Int, memberHeader: String): Example { | ||
val coupleDetail = coupleService.getCoupleDetail(memberHeader) | ||
println(coupleDetail) | ||
return exampleRepository.findByNo(exampleInfoNo) ?: throw NotFoundException() | ||
logger.info(coupleDetail.name) | ||
|
||
return exampleRepository.findByNo(exampleInfoNo) ?: throw ExampleNotFoundException("없음") | ||
|
||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/yedongsoon/example_project/application/exception/AbstractException.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,8 @@ | ||
package com.yedongsoon.example_project.application.exception | ||
|
||
import org.springframework.http.HttpStatus | ||
|
||
abstract class AbstractException( | ||
val status: HttpStatus, | ||
override val message: String | ||
) : RuntimeException(message) |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/yedongsoon/example_project/application/exception/ExampleException.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,7 @@ | ||
package com.yedongsoon.example_project.application.exception | ||
|
||
import org.springframework.http.HttpStatus | ||
|
||
class ExampleNotFoundException(message: String) : AbstractException(HttpStatus.NOT_FOUND, message) | ||
|
||
class ExampleBadRequestException(message: String) : AbstractException(HttpStatus.BAD_REQUEST, message) |
29 changes: 29 additions & 0 deletions
29
...ain/kotlin/com/yedongsoon/example_project/application/exception/GlobalExceptionHandler.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,29 @@ | ||
package com.yedongsoon.example_project.application.exception | ||
|
||
import org.springframework.http.HttpStatus | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.ControllerAdvice | ||
import org.springframework.web.bind.annotation.ExceptionHandler | ||
import reactor.core.publisher.Mono | ||
|
||
@ControllerAdvice | ||
class GlobalExceptionHandler { | ||
|
||
@ExceptionHandler(AbstractException::class) | ||
fun handleCustomException(ex: AbstractException): Mono<ResponseEntity<String>> { | ||
return Mono.just( | ||
ResponseEntity | ||
.status(ex.status) | ||
.body(ex.message) | ||
) | ||
} | ||
|
||
@ExceptionHandler(Exception::class) | ||
fun handleGeneralException(ex: Exception): Mono<ResponseEntity<String>> { | ||
return Mono.just( | ||
ResponseEntity | ||
.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.body("An unexpected error occurred: ${ex.message}") | ||
) | ||
} | ||
} |
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