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/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")) } 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 + ) + } + } +} 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 ) )