From cedb4e3f9d788a89ea3df59c310eae663ba06176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EA=B2=BD?= Date: Wed, 10 Apr 2024 14:33:35 +0900 Subject: [PATCH 1/6] add :: notice exception --- .../domain/notice/exception/NoticeNotFoundException.kt | 8 ++++++++ .../hs/kr/equus/feed/global/error/exception/ErrorCode.kt | 1 + 2 files changed, 9 insertions(+) create mode 100644 src/main/kotlin/hs/kr/equus/feed/domain/notice/exception/NoticeNotFoundException.kt diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/exception/NoticeNotFoundException.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/exception/NoticeNotFoundException.kt new file mode 100644 index 0000000..21edae8 --- /dev/null +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/exception/NoticeNotFoundException.kt @@ -0,0 +1,8 @@ +package hs.kr.equus.feed.domain.notice.exception + +import hs.kr.equus.feed.global.error.exception.EquusException +import hs.kr.equus.feed.global.error.exception.ErrorCode + +object NoticeNotFoundException : EquusException ( + ErrorCode.NOTICE_NOT_FOUND +) diff --git a/src/main/kotlin/hs/kr/equus/feed/global/error/exception/ErrorCode.kt b/src/main/kotlin/hs/kr/equus/feed/global/error/exception/ErrorCode.kt index be4847d..64b47d2 100644 --- a/src/main/kotlin/hs/kr/equus/feed/global/error/exception/ErrorCode.kt +++ b/src/main/kotlin/hs/kr/equus/feed/global/error/exception/ErrorCode.kt @@ -26,6 +26,7 @@ enum class ErrorCode( QUESTION_NOT_FOUND(404, "Question Not Found"), REPLY_NOT_FOUND(404, "Reply Not Found"), FAQ_NOT_FOUND(404, "Faq Not Found"), + NOTICE_NOT_FOUND(404, "Notice Not Found"), // Bad Request FILE_IS_EMPTY(400, "File does not exist"), From aae21547ddd0243161b2954384f9fa702ab7c389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EA=B2=BD?= Date: Wed, 10 Apr 2024 16:00:08 +0900 Subject: [PATCH 2/6] modify :: entity --- .../equus/feed/domain/notice/domain/Notice.kt | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt index 800b624..fce70da 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt @@ -13,22 +13,38 @@ class Notice( id: UUID? = null, @Column(name = "title", length = 100, nullable = false) - val title: String, + var title: String, @Column(name = "content", length = 5000, nullable = false) - val content: String, + var content: String, @Column(name = "file_name") - val fileName: String, + var fileName: String? = null, @Column(name = "admin_name", nullable = false, columnDefinition = "BINARY(16)") - val adminId: UUID, + var adminId: UUID, @Column(nullable = false) - val isPinned: Boolean, + var isPinned: Boolean, @Column(nullable = false) @Enumerated(value = EnumType.STRING) - val type: NoticeType - -) : BaseEntity(id) + var type: NoticeType + +) : BaseEntity(id) { + fun modifyNotice( + title: String, + content: String, + isPinned: Boolean, + adminId: UUID, + fileName: String, + type: NoticeType + ) { + this.title = title; + this.content = content; + this.type = type; + this.isPinned = isPinned; + this.adminId = adminId; + this.fileName = fileName; + } +} From 44ad983f2bf166d1b4fba272614d91c4507db23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EA=B2=BD?= Date: Wed, 10 Apr 2024 16:00:31 +0900 Subject: [PATCH 3/6] add :: modify notice api --- .../notice/presentation/NoticeController.kt | 13 ++++++ .../dto/request/ModifyNoticeRequest.kt | 25 +++++++++++ .../notice/service/ModifyNoticeService.kt | 41 +++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/ModifyNoticeRequest.kt create mode 100644 src/main/kotlin/hs/kr/equus/feed/domain/notice/service/ModifyNoticeService.kt diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/NoticeController.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/NoticeController.kt index 0906656..cf761c5 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/NoticeController.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/NoticeController.kt @@ -1,11 +1,15 @@ package hs.kr.equus.feed.domain.notice.presentation import hs.kr.equus.feed.domain.notice.presentation.dto.request.CreateNoticeRequest +import hs.kr.equus.feed.domain.notice.presentation.dto.request.ModifyNoticeRequest import hs.kr.equus.feed.domain.notice.service.CreateNoticeService +import hs.kr.equus.feed.domain.notice.service.ModifyNoticeService import hs.kr.equus.feed.domain.notice.service.QueryNoticeTitleService import hs.kr.equus.feed.domain.notice.service.UploadNoticeImageService 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.PathVariable import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestBody import org.springframework.web.bind.annotation.RequestMapping @@ -13,6 +17,7 @@ import org.springframework.web.bind.annotation.RequestPart import org.springframework.web.bind.annotation.ResponseStatus import org.springframework.web.bind.annotation.RestController import org.springframework.web.multipart.MultipartFile +import java.util.UUID import javax.validation.Valid @RestController @@ -20,6 +25,7 @@ import javax.validation.Valid class NoticeController( private val createNoticeService: CreateNoticeService, private val uploadNoticeImageService: UploadNoticeImageService, + private val modifyNoticeService: ModifyNoticeService, private val queryNoticeTitleService: QueryNoticeTitleService ) { @@ -32,6 +38,13 @@ class NoticeController( createNoticeService.execute(createNoticeRequest) } + @PatchMapping("/{notice-id}") + fun modifyNotice( + @PathVariable(name = "notice-id") id: UUID, + @RequestBody modifyNoticeRequest: ModifyNoticeRequest + ) = + modifyNoticeService.execute(id, modifyNoticeRequest) + @PostMapping("/image") fun uploadImage( @RequestPart(name = "photo") image: MultipartFile diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/ModifyNoticeRequest.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/ModifyNoticeRequest.kt new file mode 100644 index 0000000..3dc379c --- /dev/null +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/ModifyNoticeRequest.kt @@ -0,0 +1,25 @@ +package hs.kr.equus.feed.domain.notice.presentation.dto.request + +import hs.kr.equus.feed.domain.notice.domain.type.NoticeType +import org.springframework.web.multipart.MultipartFile +import javax.validation.constraints.NotBlank +import javax.validation.constraints.NotNull +import javax.validation.constraints.Size + +data class ModifyNoticeRequest ( + @field:NotBlank(message = "title은 null, 공백, 띄어쓰기를 허용하지 않습니다.") + @Size(max = 100, message = "title은 최대 100자까지 가능합니다.") + val title: String, + + @field:NotBlank(message = "content은 null, 공백, 띄어쓰기를 허용하지 않습니다.") + @Size(max = 5000, message = "content은 최대 5000자까지 가능합니다.") + val content: String, + + @field:NotNull(message = "Pinned은 null일수가 없습니다") + val isPinned: Boolean, + + @field:NotNull(message = "type은 null일수가 없습니다") + val type: NoticeType, + + val fileName: String +) diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/service/ModifyNoticeService.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/service/ModifyNoticeService.kt new file mode 100644 index 0000000..de98196 --- /dev/null +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/service/ModifyNoticeService.kt @@ -0,0 +1,41 @@ +package hs.kr.equus.feed.domain.notice.service + +import hs.kr.equus.feed.domain.notice.domain.repository.NoticeRepository +import hs.kr.equus.feed.domain.notice.exception.NoticeNotFoundException +import hs.kr.equus.feed.domain.notice.presentation.dto.request.ModifyNoticeRequest +import hs.kr.equus.feed.global.utils.user.UserUtils +import hs.kr.equus.feed.infrastructure.s3.service.S3Service +import org.springframework.data.repository.findByIdOrNull +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import java.util.UUID + +@Service +class ModifyNoticeService( + private val noticeRepository: NoticeRepository, + private val userUtils: UserUtils, + private val s3Service: S3Service +) { + companion object{ + const val PATH = "notice/" + } + + @Transactional + fun execute(id: UUID, request: ModifyNoticeRequest): String { + val adminId = userUtils.getCurrentUser().id + val notice = noticeRepository.findByIdOrNull(id) ?: throw NoticeNotFoundException + + + request.run { + notice.modifyNotice( + title = title, + content = content, + isPinned = isPinned, + type = type, + fileName = request.fileName, + adminId = adminId + ) + } + return s3Service.generateObjectUrl(request.fileName, PATH) + } +} From 244b92907158911b5e022baa78153de08a46565c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EA=B2=BD?= Date: Wed, 10 Apr 2024 16:01:01 +0900 Subject: [PATCH 4/6] ktlint --- .../hs/kr/equus/feed/domain/notice/domain/Notice.kt | 12 ++++++------ .../notice/exception/NoticeNotFoundException.kt | 2 +- .../presentation/dto/request/CreateNoticeRequest.kt | 2 +- .../presentation/dto/request/ModifyNoticeRequest.kt | 3 +-- .../domain/notice/service/CreateNoticeService.kt | 1 - .../domain/notice/service/ModifyNoticeService.kt | 7 +++---- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt index fce70da..8695160 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt @@ -40,11 +40,11 @@ class Notice( fileName: String, type: NoticeType ) { - this.title = title; - this.content = content; - this.type = type; - this.isPinned = isPinned; - this.adminId = adminId; - this.fileName = fileName; + this.title = title + this.content = content + this.type = type + this.isPinned = isPinned + this.adminId = adminId + this.fileName = fileName } } diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/exception/NoticeNotFoundException.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/exception/NoticeNotFoundException.kt index 21edae8..650c49c 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/notice/exception/NoticeNotFoundException.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/exception/NoticeNotFoundException.kt @@ -3,6 +3,6 @@ package hs.kr.equus.feed.domain.notice.exception import hs.kr.equus.feed.global.error.exception.EquusException import hs.kr.equus.feed.global.error.exception.ErrorCode -object NoticeNotFoundException : EquusException ( +object NoticeNotFoundException : EquusException( ErrorCode.NOTICE_NOT_FOUND ) diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/CreateNoticeRequest.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/CreateNoticeRequest.kt index a4f18b1..293034f 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/CreateNoticeRequest.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/CreateNoticeRequest.kt @@ -21,5 +21,5 @@ data class CreateNoticeRequest( @field:NotNull(message = "type은 null일수가 없습니다") val type: NoticeType, - val fileName: String + val fileName: String? = null ) diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/ModifyNoticeRequest.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/ModifyNoticeRequest.kt index 3dc379c..3597623 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/ModifyNoticeRequest.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/ModifyNoticeRequest.kt @@ -1,12 +1,11 @@ package hs.kr.equus.feed.domain.notice.presentation.dto.request import hs.kr.equus.feed.domain.notice.domain.type.NoticeType -import org.springframework.web.multipart.MultipartFile import javax.validation.constraints.NotBlank import javax.validation.constraints.NotNull import javax.validation.constraints.Size -data class ModifyNoticeRequest ( +data class ModifyNoticeRequest( @field:NotBlank(message = "title은 null, 공백, 띄어쓰기를 허용하지 않습니다.") @Size(max = 100, message = "title은 최대 100자까지 가능합니다.") val title: String, diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/service/CreateNoticeService.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/service/CreateNoticeService.kt index f752e41..253982e 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/notice/service/CreateNoticeService.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/service/CreateNoticeService.kt @@ -27,7 +27,6 @@ class CreateNoticeService( isPinned = request.isPinned, adminId = admin, fileName = request.fileName - ) ) } diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/service/ModifyNoticeService.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/service/ModifyNoticeService.kt index de98196..0251182 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/notice/service/ModifyNoticeService.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/service/ModifyNoticeService.kt @@ -16,16 +16,15 @@ class ModifyNoticeService( private val userUtils: UserUtils, private val s3Service: S3Service ) { - companion object{ - const val PATH = "notice/" - } + companion object { + const val PATH = "notice/" + } @Transactional fun execute(id: UUID, request: ModifyNoticeRequest): String { val adminId = userUtils.getCurrentUser().id val notice = noticeRepository.findByIdOrNull(id) ?: throw NoticeNotFoundException - request.run { notice.modifyNotice( title = title, From 4e5f0b6d63b33e4cf14e4f6ba1231956367347cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EA=B2=BD?= Date: Wed, 10 Apr 2024 21:07:56 +0900 Subject: [PATCH 5/6] refactor --- src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt | 2 +- .../notice/presentation/dto/request/CreateNoticeRequest.kt | 2 +- .../notice/presentation/dto/request/ModifyNoticeRequest.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt index 8695160..02d3398 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt @@ -18,7 +18,7 @@ class Notice( @Column(name = "content", length = 5000, nullable = false) var content: String, - @Column(name = "file_name") + @Column(name = "file_name", nullable = true) var fileName: String? = null, @Column(name = "admin_name", nullable = false, columnDefinition = "BINARY(16)") diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/CreateNoticeRequest.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/CreateNoticeRequest.kt index 293034f..e9f0c89 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/CreateNoticeRequest.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/CreateNoticeRequest.kt @@ -15,7 +15,7 @@ data class CreateNoticeRequest( @Size(max = 5000, message = "content은 최대 5000자까지 가능합니다.") val content: String, - @field:NotNull(message = "Pinned은 null일수가 없습니다") + @field:NotNull(message = "Pinned는 null일수가 없습니다") val isPinned: Boolean, @field:NotNull(message = "type은 null일수가 없습니다") diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/ModifyNoticeRequest.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/ModifyNoticeRequest.kt index 3597623..b13d6d0 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/ModifyNoticeRequest.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/presentation/dto/request/ModifyNoticeRequest.kt @@ -20,5 +20,5 @@ data class ModifyNoticeRequest( @field:NotNull(message = "type은 null일수가 없습니다") val type: NoticeType, - val fileName: String + val fileName: String? = null ) From 094dd1c70f34d99be1243f89556ce24e01154a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EA=B2=BD?= Date: Wed, 10 Apr 2024 22:24:36 +0900 Subject: [PATCH 6/6] refactor :: column name --- src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt b/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt index 02d3398..2c76e28 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt @@ -21,7 +21,7 @@ class Notice( @Column(name = "file_name", nullable = true) var fileName: String? = null, - @Column(name = "admin_name", nullable = false, columnDefinition = "BINARY(16)") + @Column(name = "admin_id", nullable = false, columnDefinition = "BINARY(16)") var adminId: UUID, @Column(nullable = false)