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

🔀 :: (ENTRY-162) 공지사항 수정 api 개발 #35

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
36 changes: 26 additions & 10 deletions src/main/kotlin/hs/kr/equus/feed/domain/notice/domain/Notice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
@Column(name = "file_name", nullable = true)
var fileName: String? = null,
rudeh2926 marked this conversation as resolved.
Show resolved Hide resolved

@Column(name = "admin_name", nullable = false, columnDefinition = "BINARY(16)")
val adminId: UUID,
@Column(name = "admin_id", nullable = false, columnDefinition = "BINARY(16)")
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,
rudeh2926 marked this conversation as resolved.
Show resolved Hide resolved
type: NoticeType
) {
this.title = title
this.content = content
this.type = type
this.isPinned = isPinned
this.adminId = adminId
this.fileName = fileName
}
}
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
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
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
@RequestMapping("/notice")
class NoticeController(
private val createNoticeService: CreateNoticeService,
private val uploadNoticeImageService: UploadNoticeImageService,
private val modifyNoticeService: ModifyNoticeService,
private val queryNoticeTitleService: QueryNoticeTitleService
) {

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ 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일수가 없습니다")
val type: NoticeType,

val fileName: String
val fileName: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package hs.kr.equus.feed.domain.notice.presentation.dto.request

import hs.kr.equus.feed.domain.notice.domain.type.NoticeType
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일수가 없습니다")
rudeh2926 marked this conversation as resolved.
Show resolved Hide resolved
val type: NoticeType,

val fileName: String? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class CreateNoticeService(
isPinned = request.isPinned,
adminId = admin,
fileName = request.fileName

)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down