-
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 #4 from HappyScrolls/feature/#1_user_additional_infos
Feature/#1 user additional infos
- Loading branch information
Showing
14 changed files
with
210 additions
and
14 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...service/application/CoupleQueryService.kt → .../application/couple/CoupleQueryService.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
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/yedongsoon/account_service/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.account_service.application.exception | ||
|
||
import org.springframework.http.HttpStatus | ||
|
||
abstract class AbstractException( | ||
val status: HttpStatus, | ||
override val message: String | ||
) : RuntimeException(message) |
29 changes: 29 additions & 0 deletions
29
...ain/kotlin/com/yedongsoon/account_service/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.account_service.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}") | ||
) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/yedongsoon/account_service/application/exception/MemberException.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.account_service.application.exception | ||
|
||
import org.springframework.http.HttpStatus | ||
|
||
class MemberAdditionalInfoExistsException(message: String) : AbstractException(HttpStatus.BAD_REQUEST, message) | ||
class MemberNotFoundException(message: String) : AbstractException(HttpStatus.NOT_FOUND, message) | ||
|
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/yedongsoon/account_service/application/member/MemberCommandService.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,24 @@ | ||
package com.yedongsoon.account_service.application.member | ||
|
||
import com.yedongsoon.account_service.application.exception.MemberAdditionalInfoExistsException | ||
import com.yedongsoon.account_service.application.exception.MemberNotFoundException | ||
import com.yedongsoon.account_service.domain.member.MemberRepository | ||
import com.yedongsoon.account_service.domain.member.model.MemberAdditionalInfoCommand | ||
import jakarta.transaction.Transactional | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Service | ||
|
||
|
||
@Service | ||
class MemberCommandService( | ||
private val memberRepository: MemberRepository, | ||
) { | ||
@Transactional | ||
suspend fun createAdditional(command: MemberAdditionalInfoCommand) { | ||
memberRepository.findByIdOrNull(command.memberNo)?.also { | ||
if(it.birthDate!=null&& it.mobileNo!=null) throw MemberAdditionalInfoExistsException("추가 정보를 이미 입력한 유저입니다.") | ||
it.createAdditionalInfo(command) | ||
memberRepository.save(it) //트랜잭션 수정후 제거 | ||
}?:throw throw MemberNotFoundException("유저를 찾을 수 없습니다") | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
.../kotlin/com/yedongsoon/account_service/domain/member/model/MemberAdditionalInfoCommand.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,12 @@ | ||
package com.yedongsoon.account_service.domain.member.model | ||
|
||
import java.time.LocalDate | ||
|
||
data class MemberAdditionalInfoCommand( | ||
val memberNo:Int, | ||
val name: String?, | ||
val mobileNo:String, | ||
val birthDate: LocalDate, | ||
val profilePhoto: String?, | ||
//추후 개인정보 동의 여부 추가 | ||
) |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/com/yedongsoon/account_service/presentation/WebConfig.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,25 @@ | ||
package com.yedongsoon.account_service.presentation | ||
|
||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.web.cors.CorsConfiguration | ||
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource | ||
import org.springframework.web.cors.reactive.CorsWebFilter | ||
|
||
@Configuration | ||
class WebFluxConfig { | ||
|
||
@Bean | ||
fun corsFilter(): CorsWebFilter { | ||
val corsConfig = CorsConfiguration() | ||
corsConfig.allowedOrigins = listOf("*") // 모든 도메인 허용 | ||
corsConfig.allowedMethods = listOf("*") // 모든 HTTP 메서드 허용 | ||
corsConfig.allowedHeaders = listOf("*") // 모든 헤더 허용 | ||
corsConfig.allowCredentials = false // 자격 증명 비허용 | ||
|
||
val source = UrlBasedCorsConfigurationSource() | ||
source.registerCorsConfiguration("/**", corsConfig) // 모든 경로에 대해 CORS 설정 적용 | ||
|
||
return CorsWebFilter(source) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/com/yedongsoon/account_service/presentation/handler/CoupleHandler.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
24 changes: 24 additions & 0 deletions
24
src/main/kotlin/com/yedongsoon/account_service/presentation/handler/MemberHandler.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,24 @@ | ||
package com.yedongsoon.account_service.presentation.handler | ||
|
||
import com.yedongsoon.account_service.application.member.MemberCommandService | ||
import com.yedongsoon.account_service.presentation.extension.extractMemberCodeHeader | ||
import com.yedongsoon.account_service.presentation.handler.model.CoupleResponse | ||
import com.yedongsoon.account_service.presentation.handler.model.MemberAdditionalInfoRequest | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.springframework.stereotype.Service | ||
import org.springframework.web.reactive.function.server.* | ||
|
||
@Service | ||
class MemberHandler( | ||
private val memberCommandService: MemberCommandService, | ||
) { | ||
suspend fun createAdditional(request: ServerRequest): ServerResponse = withContext(Dispatchers.IO) { | ||
val memberHeader = request.extractMemberCodeHeader() | ||
val command = request.awaitBodyOrNull<MemberAdditionalInfoRequest>()?.toCommand(memberHeader.no) | ||
?: throw IllegalArgumentException() | ||
|
||
memberCommandService.createAdditional(command) | ||
ServerResponse.ok().buildAndAwait() | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../com/yedongsoon/account_service/presentation/handler/model/MemberAdditionalInfoRequest.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,21 @@ | ||
package com.yedongsoon.account_service.presentation.handler.model | ||
|
||
import com.yedongsoon.account_service.domain.member.model.MemberAdditionalInfoCommand | ||
import java.time.LocalDate | ||
|
||
|
||
data class MemberAdditionalInfoRequest( | ||
val name: String?, | ||
val mobileNo:String, | ||
val birthDate: LocalDate, | ||
val profilePhoto: String?, | ||
//추후 개인정보 동의 여부 추가 | ||
){ | ||
fun toCommand(no:Int)= MemberAdditionalInfoCommand( | ||
memberNo =no, | ||
name=name, | ||
mobileNo=mobileNo, | ||
birthDate=birthDate, | ||
profilePhoto=profilePhoto, | ||
) | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/yedongsoon/account_service/presentation/router/MemberRouter.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,21 @@ | ||
package com.yedongsoon.account_service.presentation.router | ||
|
||
import com.yedongsoon.account_service.presentation.handler.MemberHandler | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.http.MediaType | ||
import org.springframework.web.reactive.function.server.RouterFunction | ||
import org.springframework.web.reactive.function.server.ServerResponse | ||
import org.springframework.web.reactive.function.server.coRouter | ||
|
||
@Configuration | ||
class MemberRouter(private val memberHandler: MemberHandler) { | ||
@Bean | ||
fun memberRoute(): RouterFunction<ServerResponse> { | ||
return coRouter { | ||
(accept(MediaType.APPLICATION_JSON) and "/account-service/member").nest { | ||
POST("/additional-info", memberHandler::createAdditional) | ||
} | ||
} | ||
} | ||
} |
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,11 @@ | ||
### 추가 정보 기입 | ||
POST {{url}}/account-service/member/additional-info | ||
Content-Type: application/json | ||
Member-Code: eyJubyI6MSwibmFtZSI6Im5hbWUiLCJhY2NvdW50IjoiYWNjb3VudCJ9 | ||
|
||
{ | ||
"name" : null, | ||
"mobileNo": "123123123", | ||
"birthDate":"2024-01-01", | ||
"profilePhoto": null | ||
} |