From 0382376c9bcb8e53deae1c5ee74d6f1d1c2d23de Mon Sep 17 00:00:00 2001 From: "DESKTOP-USQPRVG\\gram" Date: Wed, 26 Jul 2023 10:09:26 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20deleteNotice=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../csereal/core/notice/api/NoticeController.kt | 10 ++++++++++ .../csereal/core/notice/database/NoticeEntity.kt | 4 ++++ .../csereal/core/notice/dto/NoticeDto.kt | 2 ++ .../csereal/core/notice/service/NoticeService.kt | 12 ++++++++++++ 4 files changed, 28 insertions(+) diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/notice/api/NoticeController.kt b/src/main/kotlin/com/wafflestudio/csereal/core/notice/api/NoticeController.kt index 396509af..c3f67c4f 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/notice/api/NoticeController.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/notice/api/NoticeController.kt @@ -5,6 +5,8 @@ import com.wafflestudio.csereal.core.notice.dto.NoticeDto import com.wafflestudio.csereal.core.notice.dto.UpdateNoticeRequest import com.wafflestudio.csereal.core.notice.service.NoticeService import jakarta.validation.Valid +import org.springframework.http.HttpStatus +import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* @RequestMapping("/notice") @@ -33,4 +35,12 @@ class NoticeController( ) : NoticeDto { return noticeService.updateNotice(noticeId, request) } + + @DeleteMapping("/{noticeId}") + fun deleteNotice( + @PathVariable noticeId: Long + ) : ResponseEntity { + noticeService.deleteNotice(noticeId) + return ResponseEntity("삭제되었습니다. (noticeId: $noticeId)", HttpStatus.OK) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/NoticeEntity.kt b/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/NoticeEntity.kt index cec32fc6..afea3802 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/NoticeEntity.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/notice/database/NoticeEntity.kt @@ -7,6 +7,10 @@ import jakarta.persistence.Entity @Entity(name = "notice") class NoticeEntity( + + @Column + var isDeleted: Boolean = false, + @Column var title: String, diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/notice/dto/NoticeDto.kt b/src/main/kotlin/com/wafflestudio/csereal/core/notice/dto/NoticeDto.kt index 4d6fffe1..a858c1dc 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/notice/dto/NoticeDto.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/notice/dto/NoticeDto.kt @@ -5,6 +5,7 @@ import java.time.LocalDateTime data class NoticeDto( val id: Long, + val isDeleted: Boolean, val title: String, val description: String, // val postType: String, @@ -20,6 +21,7 @@ data class NoticeDto( fun of(entity: NoticeEntity): NoticeDto = entity.run { NoticeDto( id = this.id, + isDeleted = false, title = this.title, description = this.description, // postType = this.postType, diff --git a/src/main/kotlin/com/wafflestudio/csereal/core/notice/service/NoticeService.kt b/src/main/kotlin/com/wafflestudio/csereal/core/notice/service/NoticeService.kt index 3437d761..265c08d7 100644 --- a/src/main/kotlin/com/wafflestudio/csereal/core/notice/service/NoticeService.kt +++ b/src/main/kotlin/com/wafflestudio/csereal/core/notice/service/NoticeService.kt @@ -14,6 +14,7 @@ interface NoticeService { fun readNotice(noticeId: Long): NoticeDto fun createNotice(request: CreateNoticeRequest): NoticeDto fun updateNotice(noticeId: Long, request: UpdateNoticeRequest) : NoticeDto + fun deleteNotice(noticeId: Long) } @Service @@ -25,6 +26,7 @@ class NoticeServiceImpl( override fun readNotice(noticeId: Long): NoticeDto { val notice: NoticeEntity = noticeRepository.findByIdOrNull(noticeId) ?: throw CserealException.Csereal400("존재하지 않는 공지사항입니다.(noticeId: $noticeId)") + if(notice.isDeleted) throw CserealException.Csereal400("삭제된 공지사항입니다.(noticeId: $noticeId)") return NoticeDto.of(notice) } @@ -45,6 +47,7 @@ class NoticeServiceImpl( override fun updateNotice(noticeId: Long, request: UpdateNoticeRequest) : NoticeDto { val notice: NoticeEntity = noticeRepository.findByIdOrNull(noticeId) ?: throw CserealException.Csereal400("존재하지 않는 공지사항입니다.(noticeId: $noticeId") + if(notice.isDeleted) throw CserealException.Csereal400("삭제된 공지사항입니다.(noticeId: $noticeId") notice.title = request.title ?: notice.title notice.description = request.description ?: notice.description @@ -53,4 +56,13 @@ class NoticeServiceImpl( return NoticeDto.of(notice) } + + @Transactional + override fun deleteNotice(noticeId: Long) { + val notice : NoticeEntity = noticeRepository.findByIdOrNull(noticeId) + ?: throw CserealException.Csereal400("존재하지 않는 공지사항입니다.(noticeId: $noticeId)") + + notice.isDeleted = true + + } } \ No newline at end of file