From 04183e899fe854d9aaca6b35ede553024250b19b Mon Sep 17 00:00:00 2001 From: soohyeon Date: Tue, 3 Sep 2024 16:10:41 +0900 Subject: [PATCH 1/3] add :: review --- .../org/meogo/domain/review/domain/Review.kt | 29 +++++++++++++++++++ .../review/presentation/ReviewController.kt | 21 ++++++++++++++ .../review/repository/ReviewRepository.kt | 8 +++++ 3 files changed, 58 insertions(+) create mode 100644 src/main/kotlin/org/meogo/domain/review/domain/Review.kt create mode 100644 src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt create mode 100644 src/main/kotlin/org/meogo/domain/review/repository/ReviewRepository.kt diff --git a/src/main/kotlin/org/meogo/domain/review/domain/Review.kt b/src/main/kotlin/org/meogo/domain/review/domain/Review.kt new file mode 100644 index 0000000..b39a4e2 --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/review/domain/Review.kt @@ -0,0 +1,29 @@ +package org.meogo.domain.review.domain + +import java.time.LocalDateTime +import java.util.UUID +import javax.persistence.Entity +import javax.persistence.GeneratedValue +import javax.persistence.GenerationType +import javax.persistence.Id + +@Entity +class Review( + + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + val id: Long = 0, + + val date: LocalDateTime, + + val userId: UUID, + + val schoolId: Int, + + val star: Long, + + val content: String, + + val picture: String? + +) diff --git a/src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt b/src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt new file mode 100644 index 0000000..0b53db2 --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt @@ -0,0 +1,21 @@ +package org.meogo.domain.review.presentation + +import lombok.RequiredArgsConstructor +import org.meogo.domain.review.presentation.dto.ReviewRequest +import org.meogo.domain.review.service.CreateReviewService +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequiredArgsConstructor +@RequestMapping("/review") +class ReviewController( + private val createReviewService: CreateReviewService +) { + + @PostMapping() + fun create(@RequestBody request: ReviewRequest) = + createReviewService.execute(request) +} diff --git a/src/main/kotlin/org/meogo/domain/review/repository/ReviewRepository.kt b/src/main/kotlin/org/meogo/domain/review/repository/ReviewRepository.kt new file mode 100644 index 0000000..60dae40 --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/review/repository/ReviewRepository.kt @@ -0,0 +1,8 @@ +package org.meogo.domain.review.repository + +import org.meogo.domain.review.domain.Review +import org.springframework.data.repository.Repository + +interface ReviewRepository : Repository { + fun save(review: Review): Review +} From 3239e2697faa4c10169c701e40e3534f60d28964 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Tue, 3 Sep 2024 16:10:56 +0900 Subject: [PATCH 2/3] refactor --- src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt | 5 ++--- .../org/meogo/domain/user/repository/UserRepository.kt | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) 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 55340e2..0f61e87 100644 --- a/src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt +++ b/src/main/kotlin/org/meogo/domain/user/facade/UserFacade.kt @@ -12,11 +12,10 @@ class UserFacade( ) { fun currentUser(): User? { - val authentication = SecurityContextHolder.getContext().authentication - val accountId = authentication?.name + val accountId = SecurityContextHolder.getContext().authentication.name return accountId?.let { getUserByAccountId(it) } } - fun getUserByAccountId(accountId: String): User = + fun getUserByAccountId(accountId: String) = userRepository.findByAccountId(accountId) ?: throw UserNotFoundException } diff --git a/src/main/kotlin/org/meogo/domain/user/repository/UserRepository.kt b/src/main/kotlin/org/meogo/domain/user/repository/UserRepository.kt index 77972e1..0dda506 100644 --- a/src/main/kotlin/org/meogo/domain/user/repository/UserRepository.kt +++ b/src/main/kotlin/org/meogo/domain/user/repository/UserRepository.kt @@ -1,10 +1,10 @@ package org.meogo.domain.user.repository import org.meogo.domain.user.domain.User -import org.springframework.data.repository.Repository +import org.springframework.data.jpa.repository.JpaRepository import java.util.UUID -interface UserRepository : Repository { +interface UserRepository : JpaRepository { fun save(entity: User): User fun findByAccountId(accountId: String): User? From fe2b5b705a557d2e693b430dc1938173d4632e31 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Tue, 3 Sep 2024 16:43:06 +0900 Subject: [PATCH 3/3] modify :: controller --- .../domain/review/presentation/ReviewController.kt | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt b/src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt index 0b53db2..3266b95 100644 --- a/src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt +++ b/src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt @@ -1,21 +1,10 @@ package org.meogo.domain.review.presentation import lombok.RequiredArgsConstructor -import org.meogo.domain.review.presentation.dto.ReviewRequest -import org.meogo.domain.review.service.CreateReviewService -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController @RestController @RequiredArgsConstructor @RequestMapping("/review") -class ReviewController( - private val createReviewService: CreateReviewService -) { - - @PostMapping() - fun create(@RequestBody request: ReviewRequest) = - createReviewService.execute(request) -} +class ReviewController()