From b67f81f300444bfe4b855193149175951e923e5b Mon Sep 17 00:00:00 2001 From: soohyeon Date: Wed, 25 Sep 2024 17:12:31 +0900 Subject: [PATCH 1/8] add :: create question api --- .../meogo/domain/question/domain/Question.kt | 15 ++++++++- .../question/domain/QuestionRepository.kt | 1 + .../domain/question/enum/QuestionType.kt | 5 +++ .../presentation/QuestionController.kt | 22 ++++++++++++- .../dto/request/QuestionRequest.kt | 11 +++++++ .../question/service/CreateQuestionService.kt | 32 +++++++++++++++++++ 6 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/org/meogo/domain/question/enum/QuestionType.kt create mode 100644 src/main/kotlin/org/meogo/domain/question/presentation/dto/request/QuestionRequest.kt create mode 100644 src/main/kotlin/org/meogo/domain/question/service/CreateQuestionService.kt diff --git a/src/main/kotlin/org/meogo/domain/question/domain/Question.kt b/src/main/kotlin/org/meogo/domain/question/domain/Question.kt index 1c02474..75ab764 100644 --- a/src/main/kotlin/org/meogo/domain/question/domain/Question.kt +++ b/src/main/kotlin/org/meogo/domain/question/domain/Question.kt @@ -1,9 +1,13 @@ package org.meogo.domain.question.domain +import org.meogo.domain.question.enum.QuestionType import org.meogo.domain.user.domain.User import java.time.LocalDateTime +import java.time.format.DateTimeFormatter import javax.persistence.Column import javax.persistence.Entity +import javax.persistence.EnumType +import javax.persistence.Enumerated import javax.persistence.FetchType import javax.persistence.GeneratedValue import javax.persistence.GenerationType @@ -23,7 +27,16 @@ class Question( @Column(nullable = false) val date: LocalDateTime, + @Column(name = "school_id", nullable = false) + val schoolId: Int, + + @Enumerated(EnumType.STRING) + @Column(name = "question_type", nullable = false) + val questionType: QuestionType, + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id", nullable = false) val user: User -) +) { + fun format(date: LocalDateTime) = date.format(DateTimeFormatter.ofPattern("yy.MM.dd HH:mm"))!! +} diff --git a/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt b/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt index 91f83eb..cb49726 100644 --- a/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt +++ b/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt @@ -3,5 +3,6 @@ package org.meogo.domain.question.domain import org.springframework.data.repository.Repository interface QuestionRepository : Repository { + fun save(question: Question) fun findById(id: Long): Question? } diff --git a/src/main/kotlin/org/meogo/domain/question/enum/QuestionType.kt b/src/main/kotlin/org/meogo/domain/question/enum/QuestionType.kt new file mode 100644 index 0000000..f3cc110 --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/question/enum/QuestionType.kt @@ -0,0 +1,5 @@ +package org.meogo.domain.question.enum + +enum class QuestionType { + LIFE, ENTRANCE, FACILITIES, ETC +} diff --git a/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt b/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt index 3c7e24e..a441f0b 100644 --- a/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt +++ b/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt @@ -1,3 +1,23 @@ package org.meogo.domain.question.presentation -class QuestionController +import lombok.RequiredArgsConstructor +import org.meogo.domain.question.presentation.dto.request.QuestionRequest +import org.meogo.domain.question.service.CreateQuestionService +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 +import javax.validation.Valid + +@RequiredArgsConstructor +@RestController +@RequestMapping("/question") +class QuestionController( + private val createQuestionService: CreateQuestionService +) { + @PostMapping + fun createQuestion( + @Valid @RequestBody + request: QuestionRequest + ) = createQuestionService.execute(request) +} diff --git a/src/main/kotlin/org/meogo/domain/question/presentation/dto/request/QuestionRequest.kt b/src/main/kotlin/org/meogo/domain/question/presentation/dto/request/QuestionRequest.kt new file mode 100644 index 0000000..967279c --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/question/presentation/dto/request/QuestionRequest.kt @@ -0,0 +1,11 @@ +package org.meogo.domain.question.presentation.dto.request + +import org.meogo.domain.question.enum.QuestionType +import javax.validation.constraints.Size + +data class QuestionRequest( + val schoolId: Int, + @field: Size(min = 1, max = 100) + val content: String, + val questionType: QuestionType +) diff --git a/src/main/kotlin/org/meogo/domain/question/service/CreateQuestionService.kt b/src/main/kotlin/org/meogo/domain/question/service/CreateQuestionService.kt new file mode 100644 index 0000000..ed6204b --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/question/service/CreateQuestionService.kt @@ -0,0 +1,32 @@ +package org.meogo.domain.question.service + +import org.meogo.domain.question.domain.Question +import org.meogo.domain.question.domain.QuestionRepository +import org.meogo.domain.question.presentation.dto.request.QuestionRequest +import org.meogo.domain.user.exception.UserNotFoundException +import org.meogo.domain.user.facade.UserFacade +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import java.time.LocalDateTime + +@Service +class CreateQuestionService( + private val questionRepository: QuestionRepository, + private val userFacade: UserFacade +) { + + @Transactional + fun execute(request: QuestionRequest) { + val user = userFacade.currentUser() ?: throw UserNotFoundException + + questionRepository.save( + Question( + content = request.content, + date = LocalDateTime.now(), + schoolId = request.schoolId, + questionType = request.questionType, + user = user + ) + ) + } +} From 10c5ddaafc11a17f9f1167aee76395326475eb45 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Wed, 25 Sep 2024 17:24:49 +0900 Subject: [PATCH 2/8] add :: querySchoolQuestion api --- .../question/domain/QuestionRepository.kt | 1 + .../presentation/QuestionController.kt | 13 ++++++++- .../response/QuerySchoolQuestionResponse.kt | 11 ++++++++ .../service/QuerySchoolQuestionService.kt | 27 +++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/org/meogo/domain/question/presentation/dto/response/QuerySchoolQuestionResponse.kt create mode 100644 src/main/kotlin/org/meogo/domain/question/service/QuerySchoolQuestionService.kt diff --git a/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt b/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt index cb49726..625b1c2 100644 --- a/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt +++ b/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt @@ -5,4 +5,5 @@ import org.springframework.data.repository.Repository interface QuestionRepository : Repository { fun save(question: Question) fun findById(id: Long): Question? + fun findBySchoolId(schoolId: Int): List? } diff --git a/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt b/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt index a441f0b..112c357 100644 --- a/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt +++ b/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt @@ -3,9 +3,14 @@ package org.meogo.domain.question.presentation import lombok.RequiredArgsConstructor import org.meogo.domain.question.presentation.dto.request.QuestionRequest import org.meogo.domain.question.service.CreateQuestionService +import org.meogo.domain.question.service.QuerySchoolQuestionService +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 @@ -13,11 +18,17 @@ import javax.validation.Valid @RestController @RequestMapping("/question") class QuestionController( - private val createQuestionService: CreateQuestionService + private val createQuestionService: CreateQuestionService, + private val querySchoolQuestionService: QuerySchoolQuestionService ) { + @ResponseStatus(HttpStatus.CREATED) @PostMapping fun createQuestion( @Valid @RequestBody request: QuestionRequest ) = createQuestionService.execute(request) + + @GetMapping("/query") + fun querySchoolQuestion(@RequestParam(name = "school_id")schoolId: Int) = + querySchoolQuestionService.execute(schoolId) } diff --git a/src/main/kotlin/org/meogo/domain/question/presentation/dto/response/QuerySchoolQuestionResponse.kt b/src/main/kotlin/org/meogo/domain/question/presentation/dto/response/QuerySchoolQuestionResponse.kt new file mode 100644 index 0000000..7f7790d --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/question/presentation/dto/response/QuerySchoolQuestionResponse.kt @@ -0,0 +1,11 @@ +package org.meogo.domain.question.presentation.dto.response + +import org.meogo.domain.question.enum.QuestionType + +data class QuerySchoolQuestionResponse( + val id: Long, + val content: String, + val date: String, + val questionType: QuestionType, + val name: String +) diff --git a/src/main/kotlin/org/meogo/domain/question/service/QuerySchoolQuestionService.kt b/src/main/kotlin/org/meogo/domain/question/service/QuerySchoolQuestionService.kt new file mode 100644 index 0000000..025ea7e --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/question/service/QuerySchoolQuestionService.kt @@ -0,0 +1,27 @@ +package org.meogo.domain.question.service + +import org.meogo.domain.question.domain.QuestionRepository +import org.meogo.domain.question.presentation.dto.response.QuerySchoolQuestionResponse +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional + +@Service +class QuerySchoolQuestionService( + private val questionRepository: QuestionRepository +) { + + @Transactional(readOnly = true) + fun execute(schoolId: Int): List { + val questions = questionRepository.findBySchoolId(schoolId) + + return questions?.map { question -> + QuerySchoolQuestionResponse( + id = question.id, + content = question.content, + date = question.format(question.date), + questionType = question.questionType, + name = question.user.accountId + ) + } ?: emptyList() + } +} From d51fc4838950de4c81aa0aa19657b02c9c2de4dc Mon Sep 17 00:00:00 2001 From: soohyeon Date: Wed, 25 Sep 2024 18:48:58 +0900 Subject: [PATCH 3/8] modify :: review/pic api --- .../review/presentation/dto/response/ReviewPictureResponse.kt | 1 + .../meogo/domain/review/service/QueryReviewPictureService.kt | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/org/meogo/domain/review/presentation/dto/response/ReviewPictureResponse.kt b/src/main/kotlin/org/meogo/domain/review/presentation/dto/response/ReviewPictureResponse.kt index bdfd271..40f97a8 100644 --- a/src/main/kotlin/org/meogo/domain/review/presentation/dto/response/ReviewPictureResponse.kt +++ b/src/main/kotlin/org/meogo/domain/review/presentation/dto/response/ReviewPictureResponse.kt @@ -1,5 +1,6 @@ package org.meogo.domain.review.presentation.dto.response data class ReviewPictureResponse( + val year: Int, val image: String ) diff --git a/src/main/kotlin/org/meogo/domain/review/service/QueryReviewPictureService.kt b/src/main/kotlin/org/meogo/domain/review/service/QueryReviewPictureService.kt index 4d88210..d471daa 100644 --- a/src/main/kotlin/org/meogo/domain/review/service/QueryReviewPictureService.kt +++ b/src/main/kotlin/org/meogo/domain/review/service/QueryReviewPictureService.kt @@ -19,9 +19,10 @@ class QueryReviewPictureService( val pictures = reviews .flatMap { review -> + val year = review.date.year review.picture?.split(",")?.map { pic -> val pictureUrl = fileUtil.generateObjectUrl(pic.trim(), Path.REVIEW) - ReviewPictureResponse(pictureUrl) + ReviewPictureResponse(year, pictureUrl) } ?: emptyList() } From bd2d698e4e09274c1aa995eca98ba303cb626c18 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Wed, 25 Sep 2024 19:07:06 +0900 Subject: [PATCH 4/8] add :: question modify api --- .../meogo/domain/question/domain/Question.kt | 8 ++++- .../presentation/QuestionController.kt | 15 +++++++++- .../dto/request/ModifyQuestionRequest.kt | 10 +++++++ .../question/service/ModifyQuestionService.kt | 29 +++++++++++++++++++ 4 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/org/meogo/domain/question/presentation/dto/request/ModifyQuestionRequest.kt create mode 100644 src/main/kotlin/org/meogo/domain/question/service/ModifyQuestionService.kt diff --git a/src/main/kotlin/org/meogo/domain/question/domain/Question.kt b/src/main/kotlin/org/meogo/domain/question/domain/Question.kt index 75ab764..729b808 100644 --- a/src/main/kotlin/org/meogo/domain/question/domain/Question.kt +++ b/src/main/kotlin/org/meogo/domain/question/domain/Question.kt @@ -32,11 +32,17 @@ class Question( @Enumerated(EnumType.STRING) @Column(name = "question_type", nullable = false) - val questionType: QuestionType, + var questionType: QuestionType, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id", nullable = false) val user: User ) { + fun modify(content: String, questionType: QuestionType): Question { + this.content = content + this.questionType = questionType + return this + } + fun format(date: LocalDateTime) = date.format(DateTimeFormatter.ofPattern("yy.MM.dd HH:mm"))!! } diff --git a/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt b/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt index 112c357..a267d4c 100644 --- a/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt +++ b/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt @@ -1,11 +1,14 @@ package org.meogo.domain.question.presentation import lombok.RequiredArgsConstructor +import org.meogo.domain.question.presentation.dto.request.ModifyQuestionRequest import org.meogo.domain.question.presentation.dto.request.QuestionRequest import org.meogo.domain.question.service.CreateQuestionService +import org.meogo.domain.question.service.ModifyQuestionService import org.meogo.domain.question.service.QuerySchoolQuestionService import org.springframework.http.HttpStatus import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PatchMapping import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping @@ -19,7 +22,8 @@ import javax.validation.Valid @RequestMapping("/question") class QuestionController( private val createQuestionService: CreateQuestionService, - private val querySchoolQuestionService: QuerySchoolQuestionService + private val querySchoolQuestionService: QuerySchoolQuestionService, + private val modifyQuestionService: ModifyQuestionService ) { @ResponseStatus(HttpStatus.CREATED) @PostMapping @@ -28,6 +32,15 @@ class QuestionController( request: QuestionRequest ) = createQuestionService.execute(request) + @PatchMapping("/modify") + fun modifyQuestion( + @RequestParam(name = "question_id") + questionId: Long, + @Valid @RequestBody + request: ModifyQuestionRequest + ) = + modifyQuestionService.execute(questionId, request) + @GetMapping("/query") fun querySchoolQuestion(@RequestParam(name = "school_id")schoolId: Int) = querySchoolQuestionService.execute(schoolId) diff --git a/src/main/kotlin/org/meogo/domain/question/presentation/dto/request/ModifyQuestionRequest.kt b/src/main/kotlin/org/meogo/domain/question/presentation/dto/request/ModifyQuestionRequest.kt new file mode 100644 index 0000000..c9fab54 --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/question/presentation/dto/request/ModifyQuestionRequest.kt @@ -0,0 +1,10 @@ +package org.meogo.domain.question.presentation.dto.request + +import org.meogo.domain.question.enum.QuestionType +import javax.validation.constraints.Size + +data class ModifyQuestionRequest( + @field: Size(min = 1, max = 100) + val content: String, + val questionType: QuestionType +) diff --git a/src/main/kotlin/org/meogo/domain/question/service/ModifyQuestionService.kt b/src/main/kotlin/org/meogo/domain/question/service/ModifyQuestionService.kt new file mode 100644 index 0000000..2dcb756 --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/question/service/ModifyQuestionService.kt @@ -0,0 +1,29 @@ +package org.meogo.domain.question.service + +import org.meogo.domain.question.domain.QuestionRepository +import org.meogo.domain.question.exception.QuestionNotFoundException +import org.meogo.domain.question.presentation.dto.request.ModifyQuestionRequest +import org.meogo.domain.user.exception.UserMisMatchException +import org.meogo.domain.user.exception.UserNotFoundException +import org.meogo.domain.user.facade.UserFacade +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional + +@Service +class ModifyQuestionService( + private val questionRepository: QuestionRepository, + private val userFacade: UserFacade +) { + + @Transactional + fun execute(questionId: Long, request: ModifyQuestionRequest) { + val user = userFacade.currentUser() ?: throw UserNotFoundException + val question = questionRepository.findById(questionId) ?: throw QuestionNotFoundException + + if (user != question.user) throw UserMisMatchException + + questionRepository.save( + question.modify(request.content, request.questionType) + ) + } +} From 1f4953cfcf348b7ed24b876a4303d64558913063 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Wed, 25 Sep 2024 19:16:58 +0900 Subject: [PATCH 5/8] add :: question deletle api --- .../comment/presentation/CommentController.kt | 2 +- .../question/domain/QuestionRepository.kt | 4 +++ .../presentation/QuestionController.kt | 10 ++++++- .../question/service/DeleteQuestionService.kt | 26 +++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/org/meogo/domain/question/service/DeleteQuestionService.kt diff --git a/src/main/kotlin/org/meogo/domain/comment/presentation/CommentController.kt b/src/main/kotlin/org/meogo/domain/comment/presentation/CommentController.kt index be44918..25e0bde 100644 --- a/src/main/kotlin/org/meogo/domain/comment/presentation/CommentController.kt +++ b/src/main/kotlin/org/meogo/domain/comment/presentation/CommentController.kt @@ -28,7 +28,7 @@ class CommentController( request: CommentRequest ) = createCommentService.execute(request) - @DeleteMapping + @DeleteMapping("/delete") @ResponseStatus(HttpStatus.NO_CONTENT) fun delete(@RequestParam(name = "comment_id")id: Long) = deleteCommentService.execute(id) diff --git a/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt b/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt index 625b1c2..124e38d 100644 --- a/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt +++ b/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt @@ -4,6 +4,10 @@ import org.springframework.data.repository.Repository interface QuestionRepository : Repository { fun save(question: Question) + fun findById(id: Long): Question? + fun findBySchoolId(schoolId: Int): List? + + fun deleteById(id: Long) } diff --git a/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt b/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt index a267d4c..98b2f1d 100644 --- a/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt +++ b/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt @@ -4,9 +4,11 @@ import lombok.RequiredArgsConstructor import org.meogo.domain.question.presentation.dto.request.ModifyQuestionRequest import org.meogo.domain.question.presentation.dto.request.QuestionRequest import org.meogo.domain.question.service.CreateQuestionService +import org.meogo.domain.question.service.DeleteQuestionService import org.meogo.domain.question.service.ModifyQuestionService import org.meogo.domain.question.service.QuerySchoolQuestionService import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.DeleteMapping import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PatchMapping import org.springframework.web.bind.annotation.PostMapping @@ -23,7 +25,8 @@ import javax.validation.Valid class QuestionController( private val createQuestionService: CreateQuestionService, private val querySchoolQuestionService: QuerySchoolQuestionService, - private val modifyQuestionService: ModifyQuestionService + private val modifyQuestionService: ModifyQuestionService, + private val deleteQuestionService: DeleteQuestionService ) { @ResponseStatus(HttpStatus.CREATED) @PostMapping @@ -44,4 +47,9 @@ class QuestionController( @GetMapping("/query") fun querySchoolQuestion(@RequestParam(name = "school_id")schoolId: Int) = querySchoolQuestionService.execute(schoolId) + + @ResponseStatus(HttpStatus.NO_CONTENT) + @DeleteMapping("/delete") + fun deleteQuestion(@RequestParam(name = "question_id")questionId: Long) = + deleteQuestionService.execute(questionId) } diff --git a/src/main/kotlin/org/meogo/domain/question/service/DeleteQuestionService.kt b/src/main/kotlin/org/meogo/domain/question/service/DeleteQuestionService.kt new file mode 100644 index 0000000..06fd3a2 --- /dev/null +++ b/src/main/kotlin/org/meogo/domain/question/service/DeleteQuestionService.kt @@ -0,0 +1,26 @@ +package org.meogo.domain.question.service + +import org.meogo.domain.question.domain.QuestionRepository +import org.meogo.domain.question.exception.QuestionNotFoundException +import org.meogo.domain.user.exception.UserMisMatchException +import org.meogo.domain.user.exception.UserNotFoundException +import org.meogo.domain.user.facade.UserFacade +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional + +@Service +class DeleteQuestionService( + private val questionRepository: QuestionRepository, + private val userFacade: UserFacade +) { + + @Transactional + fun execute(questionId: Long) { + val user = userFacade.currentUser() ?: throw UserNotFoundException + val question = questionRepository.findById(questionId) ?: throw QuestionNotFoundException + + if (user != question.user) throw UserMisMatchException + + questionRepository.deleteById(question.id) + } +} From c50853e2af220305c604c58a77850f61cf90e80f Mon Sep 17 00:00:00 2001 From: soohyeon Date: Wed, 25 Sep 2024 19:27:39 +0900 Subject: [PATCH 6/8] modify :: question sort --- .../meogo/domain/question/service/QuerySchoolQuestionService.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/org/meogo/domain/question/service/QuerySchoolQuestionService.kt b/src/main/kotlin/org/meogo/domain/question/service/QuerySchoolQuestionService.kt index 025ea7e..cc86026 100644 --- a/src/main/kotlin/org/meogo/domain/question/service/QuerySchoolQuestionService.kt +++ b/src/main/kotlin/org/meogo/domain/question/service/QuerySchoolQuestionService.kt @@ -22,6 +22,6 @@ class QuerySchoolQuestionService( questionType = question.questionType, name = question.user.accountId ) - } ?: emptyList() + }?.sortedByDescending { it.id } ?: emptyList() } } From 8b1e58d4e3ac62d9ffd488cd69a72bf880320017 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Wed, 25 Sep 2024 19:33:14 +0900 Subject: [PATCH 7/8] modify :: controller --- .../meogo/domain/comment/presentation/CommentController.kt | 4 +--- .../org/meogo/domain/post/presentation/PostController.kt | 2 +- .../meogo/domain/question/presentation/QuestionController.kt | 4 +--- .../org/meogo/domain/review/presentation/ReviewController.kt | 4 +--- .../org/meogo/domain/user/presentation/UserController.kt | 2 -- 5 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/org/meogo/domain/comment/presentation/CommentController.kt b/src/main/kotlin/org/meogo/domain/comment/presentation/CommentController.kt index 25e0bde..b6561f7 100644 --- a/src/main/kotlin/org/meogo/domain/comment/presentation/CommentController.kt +++ b/src/main/kotlin/org/meogo/domain/comment/presentation/CommentController.kt @@ -1,6 +1,5 @@ package org.meogo.domain.comment.presentation -import lombok.RequiredArgsConstructor import org.meogo.domain.comment.presentation.dto.request.CommentRequest import org.meogo.domain.comment.service.CreateCommentService import org.meogo.domain.comment.service.DeleteCommentService @@ -14,7 +13,6 @@ import org.springframework.web.bind.annotation.ResponseStatus import org.springframework.web.bind.annotation.RestController import javax.validation.Valid -@RequiredArgsConstructor @RestController @RequestMapping("/comment") class CommentController( @@ -28,7 +26,7 @@ class CommentController( request: CommentRequest ) = createCommentService.execute(request) - @DeleteMapping("/delete") + @DeleteMapping() @ResponseStatus(HttpStatus.NO_CONTENT) fun delete(@RequestParam(name = "comment_id")id: Long) = deleteCommentService.execute(id) diff --git a/src/main/kotlin/org/meogo/domain/post/presentation/PostController.kt b/src/main/kotlin/org/meogo/domain/post/presentation/PostController.kt index 4415d50..35adf95 100644 --- a/src/main/kotlin/org/meogo/domain/post/presentation/PostController.kt +++ b/src/main/kotlin/org/meogo/domain/post/presentation/PostController.kt @@ -45,7 +45,7 @@ class PostController( ) = createPostService.execute(request, image) - @DeleteMapping("/delete") + @DeleteMapping() @ResponseStatus(HttpStatus.NO_CONTENT) fun delete(@RequestParam("post_id") id: Long) = deletePostService.execute(id) diff --git a/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt b/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt index 98b2f1d..e433fb0 100644 --- a/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt +++ b/src/main/kotlin/org/meogo/domain/question/presentation/QuestionController.kt @@ -1,6 +1,5 @@ package org.meogo.domain.question.presentation -import lombok.RequiredArgsConstructor import org.meogo.domain.question.presentation.dto.request.ModifyQuestionRequest import org.meogo.domain.question.presentation.dto.request.QuestionRequest import org.meogo.domain.question.service.CreateQuestionService @@ -19,7 +18,6 @@ import org.springframework.web.bind.annotation.ResponseStatus import org.springframework.web.bind.annotation.RestController import javax.validation.Valid -@RequiredArgsConstructor @RestController @RequestMapping("/question") class QuestionController( @@ -49,7 +47,7 @@ class QuestionController( querySchoolQuestionService.execute(schoolId) @ResponseStatus(HttpStatus.NO_CONTENT) - @DeleteMapping("/delete") + @DeleteMapping() fun deleteQuestion(@RequestParam(name = "question_id")questionId: Long) = deleteQuestionService.execute(questionId) } 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 78f88a7..f9c8340 100644 --- a/src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt +++ b/src/main/kotlin/org/meogo/domain/review/presentation/ReviewController.kt @@ -1,6 +1,5 @@ package org.meogo.domain.review.presentation -import lombok.RequiredArgsConstructor import org.meogo.domain.review.presentation.dto.request.ModifyReviewRequest import org.meogo.domain.review.presentation.dto.request.ReviewRequest import org.meogo.domain.review.service.CreateReviewService @@ -25,7 +24,6 @@ import org.springframework.web.multipart.MultipartFile import javax.validation.Valid @RestController -@RequiredArgsConstructor @RequestMapping("/review") class ReviewController( private val createReviewService: CreateReviewService, @@ -54,7 +52,7 @@ class ReviewController( fun modify(@RequestParam(name = "review_id") reviewId: Long, @RequestBody request: ModifyReviewRequest) = modifyReviewService.modifyReview(reviewId, request) - @DeleteMapping("/delete") + @DeleteMapping() @ResponseStatus(value = HttpStatus.NO_CONTENT) fun delete(@RequestParam(name = "review_id") reviewId: Long) = deleteReviewService.deleteReview(reviewId) 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 fd0b586..d63fb24 100644 --- a/src/main/kotlin/org/meogo/domain/user/presentation/UserController.kt +++ b/src/main/kotlin/org/meogo/domain/user/presentation/UserController.kt @@ -1,6 +1,5 @@ package org.meogo.domain.user.presentation -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 @@ -24,7 +23,6 @@ import org.springframework.web.multipart.MultipartFile import javax.validation.Valid @RestController -@RequiredArgsConstructor @RequestMapping("/user") class UserController( private val userSignUpService: UserSignUpService, From 053a5f0654fe7567b53a53e3725d90c8d039cf65 Mon Sep 17 00:00:00 2001 From: soohyeon Date: Wed, 25 Sep 2024 19:33:33 +0900 Subject: [PATCH 8/8] modify :: fun --- .../org/meogo/domain/question/domain/QuestionRepository.kt | 4 ++-- .../meogo/domain/question/service/DeleteQuestionService.kt | 3 +-- .../meogo/domain/question/service/ModifyQuestionService.kt | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt b/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt index 124e38d..bf89229 100644 --- a/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt +++ b/src/main/kotlin/org/meogo/domain/question/domain/QuestionRepository.kt @@ -5,9 +5,9 @@ import org.springframework.data.repository.Repository interface QuestionRepository : Repository { fun save(question: Question) - fun findById(id: Long): Question? + fun findById(id: Long): Question - fun findBySchoolId(schoolId: Int): List? + fun findBySchoolId(schoolId: Int): List fun deleteById(id: Long) } diff --git a/src/main/kotlin/org/meogo/domain/question/service/DeleteQuestionService.kt b/src/main/kotlin/org/meogo/domain/question/service/DeleteQuestionService.kt index 06fd3a2..8e61359 100644 --- a/src/main/kotlin/org/meogo/domain/question/service/DeleteQuestionService.kt +++ b/src/main/kotlin/org/meogo/domain/question/service/DeleteQuestionService.kt @@ -1,7 +1,6 @@ package org.meogo.domain.question.service import org.meogo.domain.question.domain.QuestionRepository -import org.meogo.domain.question.exception.QuestionNotFoundException import org.meogo.domain.user.exception.UserMisMatchException import org.meogo.domain.user.exception.UserNotFoundException import org.meogo.domain.user.facade.UserFacade @@ -17,7 +16,7 @@ class DeleteQuestionService( @Transactional fun execute(questionId: Long) { val user = userFacade.currentUser() ?: throw UserNotFoundException - val question = questionRepository.findById(questionId) ?: throw QuestionNotFoundException + val question = questionRepository.findById(questionId) if (user != question.user) throw UserMisMatchException diff --git a/src/main/kotlin/org/meogo/domain/question/service/ModifyQuestionService.kt b/src/main/kotlin/org/meogo/domain/question/service/ModifyQuestionService.kt index 2dcb756..1b4111c 100644 --- a/src/main/kotlin/org/meogo/domain/question/service/ModifyQuestionService.kt +++ b/src/main/kotlin/org/meogo/domain/question/service/ModifyQuestionService.kt @@ -1,7 +1,6 @@ package org.meogo.domain.question.service import org.meogo.domain.question.domain.QuestionRepository -import org.meogo.domain.question.exception.QuestionNotFoundException import org.meogo.domain.question.presentation.dto.request.ModifyQuestionRequest import org.meogo.domain.user.exception.UserMisMatchException import org.meogo.domain.user.exception.UserNotFoundException @@ -18,7 +17,7 @@ class ModifyQuestionService( @Transactional fun execute(questionId: Long, request: ModifyQuestionRequest) { val user = userFacade.currentUser() ?: throw UserNotFoundException - val question = questionRepository.findById(questionId) ?: throw QuestionNotFoundException + val question = questionRepository.findById(questionId) if (user != question.user) throw UserMisMatchException