Skip to content

Commit

Permalink
설정 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
chs98412 committed Sep 1, 2024
1 parent 8203597 commit a760df4
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 17 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ dependencies {
testImplementation("org.springframework.restdocs:spring-restdocs-webtestclient:3.0.0")
testImplementation("com.ninja-squad:springmockk:4.0.2")
testImplementation("com.epages:restdocs-api-spec-openapi3-generator:0.17.1")
implementation("io.netty:netty-resolver-dns-native-macos:4.1.97.Final:osx-aarch_64")

}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
Expand Down
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("없음")

}
}
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)
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)
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}")
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.yedongsoon.example_project.infrastructure.couple
import com.yedongsoon.example_project.application.couple.CoupleService
import com.yedongsoon.example_project.application.couple.model.CoupleDetailResponse
import kotlinx.coroutines.reactor.awaitSingle
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.http.HttpHeaders
import org.springframework.stereotype.Service
Expand All @@ -15,15 +16,21 @@ class CoupleAdapter(private val webClient: WebClient

@Value("\${couple.service.url}")
lateinit var coupleServiceUrl: String
private val logger = LoggerFactory.getLogger(CoupleAdapter::class.java)

override suspend fun getCoupleDetail(memberHeader: String): CoupleDetailResponse {
return webClient.get()
.uri("$coupleServiceUrl/couple/lover")
.header(HttpHeaders.CONTENT_TYPE, "application/json")
.header("Member-Code", memberHeader)
.retrieve()
.bodyToMono<CoupleDetailResponse>()
.awaitSingle()
return try {
webClient.get()
.uri("$coupleServiceUrl/couple/detail")
.header(HttpHeaders.CONTENT_TYPE, "application/json")
.header("Member-Code", memberHeader)
.retrieve()
.bodyToMono<CoupleDetailResponse>()
.awaitSingle()
} catch (e: Exception) {
logger.error("Error while fetching couple details for Member-Code: $memberHeader", e)
throw e
}
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.yedongsoon.example_project.presentation.extension

import com.yedongsoon.example_project.application.exception.ExampleBadRequestException
import com.yedongsoon.example_project.domain.extension.decodeBase64ToDto
import org.springframework.web.reactive.function.server.ServerRequest
import org.springframework.web.reactive.function.server.queryParamOrNull
import java.time.LocalDate
import java.time.format.DateTimeFormatter

fun ServerRequest.extractMemberCodeHeader(): MemberHeader {
return headers().header("Member-Code").firstOrNull()
Expand All @@ -22,8 +25,7 @@ fun ServerRequest.intQueryParam(parameter: String): Int {
return queryParamOrNull(parameter)?.toIntOrNull()
?: throw IllegalArgumentException("Invalid or missing 'itemNo' query parameter")
}
<<<<<<< Updated upstream
=======


fun ServerRequest.localDateQueryParam(parameter: String): LocalDate {
return queryParamOrNull(parameter)?.let {
Expand All @@ -32,6 +34,5 @@ fun ServerRequest.localDateQueryParam(parameter: String): LocalDate {
}

fun ServerRequest.extractRawMemberCodeHeader(): String {
return headers().header("Member-Code").firstOrNull() ?: throw IllegalArgumentException()
}
>>>>>>> Stashed changes
return headers().header("Member-Code").firstOrNull() ?: throw ExampleBadRequestException("헤더 없음")
}
4 changes: 2 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spring:
cache-prep-stmts: true
jpa:
hibernate:
ddl-auto: none
ddl-auto: create
show-sql: true
properties:
hibernate:
Expand All @@ -32,4 +32,4 @@ server:

couple:
service:
url: http://158.247.198.100:32002
url: https://f3badfd3-b053-4d58-a6cd-5105bbed9015.mock.pstmn.io

0 comments on commit a760df4

Please sign in to comment.