Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

πŸ„ :: (Meogo-28) query school post #29

Merged
merged 3 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/kotlin/org/meogo/domain/post/domain/Post.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -39,4 +40,6 @@ class Post(
fun addGood() {
this.good += 1
}

fun format(date: LocalDateTime) = date.format(DateTimeFormatter.ofPattern("yy.MM.dd HH:mm"))!!
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ interface PostRepository : Repository<Post, Long> {
fun save(post: Post)

fun findAll(): List<Post>

fun findBySchoolId(schoolId: Int): List<Post>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"))
}
Original file line number Diff line number Diff line change
@@ -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<PostResponse> {
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
)
}
}
}
3 changes: 3 additions & 0 deletions src/main/kotlin/org/meogo/domain/review/domain/Review.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class Review(
@Column(nullable = false)
var content: String,

@Column(name = "key_word")
val keyWord: String?,

var picture: String?

) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ data class ReviewRequest(
val content: String,
val schoolId: Int,
val star: Float,
val keyWord: List<String>?,
val image: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ class CreateReviewService(
fun execute(request: ReviewRequest) {
val user = userFacade.currentUser() ?: throw UserNotFoundException

val keyWord = request.keyWord?.joinToString(separator = ",")

reviewRepository.save(
Review(
date = LocalDateTime.now(),
userId = user.id!!,
schoolId = request.schoolId,
star = request.star,
content = request.content,
keyWord = keyWord,
picture = request.image
)
)
Expand Down
Loading