From cc2a285de85473ca08284de009126324d2c27054 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Fri, 6 Sep 2024 23:09:10 +0900 Subject: [PATCH 1/3] modify :: userFacade --- src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt b/src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt index 3d6af5b..7b0c6fa 100644 --- a/src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt +++ b/src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt @@ -14,7 +14,7 @@ class UserFacade( fun currentUser(): User? { val accountId = SecurityContextHolder.getContext().authentication.name - return accountId?.let { getUserByAccountId(it) } + return accountId?.let { getUserByAccountId(it) }!! } fun getUserByAccountId(accountId: String): User = From a6aa5094c3de89ce77fa75a16000b5eda7b82b22 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Fri, 6 Sep 2024 23:11:55 +0900 Subject: [PATCH 2/3] add :: myPage api --- .../review/repository/ReviewRepository.kt | 3 +++ .../user/presentation/UserController.kt | 10 +++++++- .../dto/response/MyPageResponse.kt | 7 ++++++ .../domain/user/service/MyPageService.kt | 23 +++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/org/meogo/domain/user/presentation/dto/response/MyPageResponse.kt create mode 100644 src/main/kotlin/org/meogo/domain/user/service/MyPageService.kt diff --git a/src/main/kotlin/org/meogo/domain/review/repository/ReviewRepository.kt b/src/main/kotlin/org/meogo/domain/review/repository/ReviewRepository.kt index a906e3e..ddc0e87 100644 --- a/src/main/kotlin/org/meogo/domain/review/repository/ReviewRepository.kt +++ b/src/main/kotlin/org/meogo/domain/review/repository/ReviewRepository.kt @@ -2,6 +2,7 @@ package org.meogo.domain.review.repository import org.meogo.domain.review.domain.Review import org.springframework.data.repository.Repository +import java.util.UUID interface ReviewRepository : Repository { fun save(review: Review): Review @@ -10,5 +11,7 @@ interface ReviewRepository : Repository { fun findById(id: Long): Review? + fun findByUserId(userId: UUID): List? + fun deleteById(id: Long) } diff --git a/src/main/kotlin/org/meogo/domain/user/presentation/UserController.kt b/src/main/kotlin/org/meogo/domain/user/presentation/UserController.kt index 844dd36..5632476 100644 --- a/src/main/kotlin/org/meogo/domain/user/presentation/UserController.kt +++ b/src/main/kotlin/org/meogo/domain/user/presentation/UserController.kt @@ -4,10 +4,13 @@ import lombok.RequiredArgsConstructor import org.meogo.domain.user.presentation.dto.request.UserCheckRequest import org.meogo.domain.user.presentation.dto.request.UserSignInRequest import org.meogo.domain.user.presentation.dto.request.UserSignUpRequest +import org.meogo.domain.user.presentation.dto.response.MyPageResponse import org.meogo.domain.user.service.CheckAccountIdService +import org.meogo.domain.user.service.MyPageService import org.meogo.domain.user.service.UserSignInService import org.meogo.domain.user.service.UserSignUpService import org.meogo.global.jwt.dto.TokenResponse +import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping @@ -20,7 +23,8 @@ import javax.validation.Valid class UserController( private val userSignUpService: UserSignUpService, private val userSignInService: UserSignInService, - private val userCheckAccountIdService: CheckAccountIdService + private val userCheckAccountIdService: CheckAccountIdService, + private val myPageService: MyPageService ) { @PostMapping("/signup") fun signUp( @@ -36,4 +40,8 @@ class UserController( @PostMapping("/check") fun checkAccountId(@RequestBody request: UserCheckRequest): Boolean = userCheckAccountIdService.execute(request) + + @GetMapping("/myPage") + fun myPage(): MyPageResponse = + myPageService.execute() } diff --git a/src/main/kotlin/org/meogo/domain/user/presentation/dto/response/MyPageResponse.kt b/src/main/kotlin/org/meogo/domain/user/presentation/dto/response/MyPageResponse.kt new file mode 100644 index 0000000..e7b233c --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/user/presentation/dto/response/MyPageResponse.kt @@ -0,0 +1,7 @@ +package org.meogo.domain.user.presentation.dto.response + +data class MyPageResponse( + val name: String, + val accountId: String, + val profile: String +) diff --git a/src/main/kotlin/org/meogo/domain/user/service/MyPageService.kt b/src/main/kotlin/org/meogo/domain/user/service/MyPageService.kt new file mode 100644 index 0000000..43df572 --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/user/service/MyPageService.kt @@ -0,0 +1,23 @@ +package org.meogo.domain.user.service + +import org.meogo.domain.user.exception.UserNotFoundException +import org.meogo.domain.user.facade.UserFacade +import org.meogo.domain.user.presentation.dto.response.MyPageResponse +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional + +@Service +class MyPageService( + private val userFacade: UserFacade +) { + @Transactional + fun execute(): MyPageResponse { + val user = userFacade.currentUser() ?: throw UserNotFoundException + + return MyPageResponse( + user.name, + user.accountId, + user.profile!! + ) + } +} From 904434d68eb748fb51b82ad3735cc602e7b553d3 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Fri, 6 Sep 2024 23:19:21 +0900 Subject: [PATCH 3/3] modify :: nullable --- src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt b/src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt index 7b0c6fa..3d6af5b 100644 --- a/src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt +++ b/src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt @@ -14,7 +14,7 @@ class UserFacade( fun currentUser(): User? { val accountId = SecurityContextHolder.getContext().authentication.name - return accountId?.let { getUserByAccountId(it) }!! + return accountId?.let { getUserByAccountId(it) } } fun getUserByAccountId(accountId: String): User =