feat: 커뮤니티 글 등록/수정
- 유료 글에서만 gif를 등록할 수 있도록 수정
This commit is contained in:
@@ -21,6 +21,7 @@ import kr.co.vividnext.sodalive.fcm.FcmEventType
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||
import kr.co.vividnext.sodalive.utils.generateFileName
|
||||
import kr.co.vividnext.sodalive.utils.validateImage
|
||||
import org.springframework.beans.factory.annotation.Value
|
||||
import org.springframework.context.ApplicationEventPublisher
|
||||
import org.springframework.data.repository.findByIdOrNull
|
||||
@@ -71,6 +72,8 @@ class CreatorCommunityService(
|
||||
throw SodaException("오디오 등록을 위해서는 이미지가 필요합니다.")
|
||||
}
|
||||
|
||||
postImage?.let { validateImage(it, request.price > 0) }
|
||||
|
||||
val post = CreatorCommunity(
|
||||
content = request.content,
|
||||
price = request.price,
|
||||
@@ -129,6 +132,8 @@ class CreatorCommunityService(
|
||||
val post = repository.findByIdAndMemberId(id = request.creatorCommunityId, memberId = member.id!!)
|
||||
?: throw SodaException("잘못된 요청입니다.")
|
||||
|
||||
postImage?.let { validateImage(it, post.price > 0) }
|
||||
|
||||
if (request.content != null) {
|
||||
post.content = request.content
|
||||
}
|
||||
|
@@ -0,0 +1,21 @@
|
||||
package kr.co.vividnext.sodalive.utils
|
||||
|
||||
import kr.co.vividnext.sodalive.common.SodaException
|
||||
import org.apache.tika.Tika
|
||||
import org.springframework.web.multipart.MultipartFile
|
||||
|
||||
/**
|
||||
* 이미지 파일인지 확인하고,
|
||||
* GIF의 경우 외부 조건(gifAllowed)에 따라 허용 여부 판단
|
||||
*/
|
||||
fun validateImage(file: MultipartFile, gifAllowed: Boolean) {
|
||||
val mimeType = Tika().detect(file.bytes)
|
||||
|
||||
if (!mimeType.startsWith("image/")) {
|
||||
throw SodaException("이미지 파일만 업로드할 수 있습니다.")
|
||||
}
|
||||
|
||||
if (mimeType == "image/gif" && !gifAllowed) {
|
||||
throw SodaException("GIF 파일은 유료 게시물만 업로드 할 수 있습니다.")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user