From 42c14abf8b874d1cb4283438a0cdaca650c2eaf7 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Tue, 10 Sep 2024 23:04:01 +0900 Subject: [PATCH 1/3] add :: querySchoolPost api --- .../org/meogo/domain/post/domain/Post.kt | 3 ++ .../domain/post/domain/PostRepository.kt | 2 ++ .../domain/post/present/PostController.kt | 8 ++++- .../post/service/QuerySchoolPostService.kt | 29 +++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/org/meogo/domain/post/service/QuerySchoolPostService.kt diff --git a/src/main/kotlin/org/meogo/domain/post/domain/Post.kt b/src/main/kotlin/org/meogo/domain/post/domain/Post.kt index 2d6fc71..3e0d18b 100644 --- a/src/main/kotlin/org/meogo/domain/post/domain/Post.kt +++ b/src/main/kotlin/org/meogo/domain/post/domain/Post.kt @@ -1,6 +1,7 @@ package org.meogo.domain.post.domain import java.time.LocalDateTime +import java.time.format.DateTimeFormatter import java.util.UUID import javax.persistence.Column import javax.persistence.Entity @@ -39,4 +40,6 @@ class Post( fun addGood() { this.good += 1 } + + fun format(date: LocalDateTime) = date.format(DateTimeFormatter.ofPattern("yy.MM.dd HH:mm"))!! } diff --git a/src/main/kotlin/org/meogo/domain/post/domain/PostRepository.kt b/src/main/kotlin/org/meogo/domain/post/domain/PostRepository.kt index 7b5770f..9a7bceb 100644 --- a/src/main/kotlin/org/meogo/domain/post/domain/PostRepository.kt +++ b/src/main/kotlin/org/meogo/domain/post/domain/PostRepository.kt @@ -7,4 +7,6 @@ interface PostRepository : Repository { fun save(post: Post) fun findAll(): List + + fun findBySchoolId(schoolId: Int): List } diff --git a/src/main/kotlin/org/meogo/domain/post/present/PostController.kt b/src/main/kotlin/org/meogo/domain/post/present/PostController.kt index 32855d9..4bb7836 100644 --- a/src/main/kotlin/org/meogo/domain/post/present/PostController.kt +++ b/src/main/kotlin/org/meogo/domain/post/present/PostController.kt @@ -4,11 +4,13 @@ import lombok.RequiredArgsConstructor import org.meogo.domain.post.present.dto.request.PostRequest import org.meogo.domain.post.service.CreatePostService import org.meogo.domain.post.service.QueryAllPostService +import org.meogo.domain.post.service.QuerySchoolPostService import org.springframework.http.HttpStatus 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 +import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.ResponseStatus import org.springframework.web.bind.annotation.RestController import javax.validation.Valid @@ -18,7 +20,8 @@ import javax.validation.Valid @RequestMapping("/post") class PostController( private val createPostService: CreatePostService, - private val queryAllPostService: QueryAllPostService + private val queryAllPostService: QueryAllPostService, + private val querySchoolPostService: QuerySchoolPostService ) { @PostMapping @@ -31,4 +34,7 @@ class PostController( @GetMapping("/query/all") fun queryAll() = queryAllPostService.execute() + + @GetMapping("/query/school") + fun querySchool(@RequestParam(name = "school_id") schoolId: Int) = querySchoolPostService.execute(schoolId) } diff --git a/src/main/kotlin/org/meogo/domain/post/service/QuerySchoolPostService.kt b/src/main/kotlin/org/meogo/domain/post/service/QuerySchoolPostService.kt new file mode 100644 index 0000000..6b527d6 --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/post/service/QuerySchoolPostService.kt @@ -0,0 +1,29 @@ +package org.meogo.domain.post.service + +import org.meogo.domain.post.domain.PostRepository +import org.meogo.domain.post.present.dto.response.PostResponse +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional + +@Service +class QuerySchoolPostService( + private val postRepository: PostRepository +) { + + @Transactional(readOnly = true) + fun execute(schoolId: Int): List { + val posts = postRepository.findBySchoolId(schoolId) + + return posts.map { post -> + PostResponse( + id = post.id, + name = "익명", + title = post.title, + content = post.content, + date = post.format(post.date), + keyWord = post.keyWord?.split(",")?.map { it.trim() }, + schoolId = post.schoolId + ) + } + } +} From e54124052ac3d63cfa13450e2f507339acb35cf0 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Tue, 10 Sep 2024 23:04:55 +0900 Subject: [PATCH 2/3] =?UTF-8?q?modify=20::=20=ED=82=A4=EC=9B=8C=EB=93=9C?= =?UTF-8?q?=EB=A6=AC=EB=B7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/org/meogo/domain/review/domain/Review.kt | 3 +++ .../domain/review/presentation/dto/request/ReviewRequest.kt | 1 + .../org/meogo/domain/review/service/CreateReviewService.kt | 3 +++ 3 files changed, 7 insertions(+) diff --git a/src/main/kotlin/org/meogo/domain/review/domain/Review.kt b/src/main/kotlin/org/meogo/domain/review/domain/Review.kt index c8ea4ae..5f38925 100644 --- a/src/main/kotlin/org/meogo/domain/review/domain/Review.kt +++ b/src/main/kotlin/org/meogo/domain/review/domain/Review.kt @@ -30,6 +30,9 @@ class Review( @Column(nullable = false) var content: String, + @Column(name = "key_word") + val keyWord: String?, + var picture: String? ) { diff --git a/src/main/kotlin/org/meogo/domain/review/presentation/dto/request/ReviewRequest.kt b/src/main/kotlin/org/meogo/domain/review/presentation/dto/request/ReviewRequest.kt index 8ac335b..9f915fc 100644 --- a/src/main/kotlin/org/meogo/domain/review/presentation/dto/request/ReviewRequest.kt +++ b/src/main/kotlin/org/meogo/domain/review/presentation/dto/request/ReviewRequest.kt @@ -7,5 +7,6 @@ data class ReviewRequest( val content: String, val schoolId: Int, val star: Float, + val keyWord: List?, val image: String? ) diff --git a/src/main/kotlin/org/meogo/domain/review/service/CreateReviewService.kt b/src/main/kotlin/org/meogo/domain/review/service/CreateReviewService.kt index 5f37e1f..62ab96f 100644 --- a/src/main/kotlin/org/meogo/domain/review/service/CreateReviewService.kt +++ b/src/main/kotlin/org/meogo/domain/review/service/CreateReviewService.kt @@ -19,6 +19,8 @@ class CreateReviewService( fun execute(request: ReviewRequest) { val user = userFacade.currentUser() ?: throw UserNotFoundException + val keyWord = request.keyWord?.joinToString(separator = ",") + reviewRepository.save( Review( date = LocalDateTime.now(), @@ -26,6 +28,7 @@ class CreateReviewService( schoolId = request.schoolId, star = request.star, content = request.content, + keyWord = keyWord, picture = request.image ) ) From 09619b3b1494983d47984917a6f1f5edb107161a Mon Sep 17 00:00:00 2001 From: soohyeon Date: Tue, 10 Sep 2024 23:05:09 +0900 Subject: [PATCH 3/3] delete :: format fun --- .../org/meogo/domain/post/service/QueryAllPostService.kt | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/main/kotlin/org/meogo/domain/post/service/QueryAllPostService.kt b/src/main/kotlin/org/meogo/domain/post/service/QueryAllPostService.kt index 85412c0..3869af5 100644 --- a/src/main/kotlin/org/meogo/domain/post/service/QueryAllPostService.kt +++ b/src/main/kotlin/org/meogo/domain/post/service/QueryAllPostService.kt @@ -4,8 +4,6 @@ import org.meogo.domain.post.domain.PostRepository import org.meogo.domain.post.present.dto.response.PostResponse import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional -import java.time.LocalDateTime -import java.time.format.DateTimeFormatter @Service class QueryAllPostService( @@ -22,13 +20,10 @@ class QueryAllPostService( name = "익명", title = post.title, content = post.content, - date = format(post.date), + date = post.format(post.date), keyWord = post.keyWord?.split(",")?.map { it.trim() }, schoolId = post.schoolId ) }.sortedBy { it.id } } - - private fun format(date: LocalDateTime) = - date.format(DateTimeFormatter.ofPattern("yy.MM.dd HH:mm")) }