크리에이터 커뮤니티

- 오디오 등록 기능 추가
This commit is contained in:
Klaus 2024-08-01 22:03:41 +09:00
parent 2860deb90a
commit ca4ea0e5ea
3 changed files with 30 additions and 1 deletions

View File

@ -17,6 +17,8 @@ data class CreatorCommunity(
var isCommentAvailable: Boolean, var isCommentAvailable: Boolean,
var isAdult: Boolean, var isAdult: Boolean,
@Column(nullable = true) @Column(nullable = true)
var audioPath: String? = null,
@Column(nullable = true)
var imagePath: String? = null, var imagePath: String? = null,
var isActive: Boolean = true var isActive: Boolean = true
) : BaseEntity() { ) : BaseEntity() {

View File

@ -27,6 +27,9 @@ class CreatorCommunityController(private val service: CreatorCommunityService) {
@PostMapping @PostMapping
@PreAuthorize("hasRole('CREATOR')") @PreAuthorize("hasRole('CREATOR')")
fun createCommunityPost( fun createCommunityPost(
@Nullable
@RequestPart("contentFile")
audioFile: MultipartFile?,
@Nullable @Nullable
@RequestPart("postImage") @RequestPart("postImage")
postImage: MultipartFile?, postImage: MultipartFile?,
@ -37,6 +40,7 @@ class CreatorCommunityController(private val service: CreatorCommunityService) {
ApiResponse.ok( ApiResponse.ok(
service.createCommunityPost( service.createCommunityPost(
audioFile = audioFile,
postImage = postImage, postImage = postImage,
requestString = requestString, requestString = requestString,
member = member member = member

View File

@ -50,13 +50,22 @@ class CreatorCommunityService(
private val imageHost: String private val imageHost: String
) { ) {
@Transactional @Transactional
fun createCommunityPost(postImage: MultipartFile?, requestString: String, member: Member) { fun createCommunityPost(
audioFile: MultipartFile?,
postImage: MultipartFile?,
requestString: String,
member: Member
) {
val request = objectMapper.readValue(requestString, CreateCommunityPostRequest::class.java) val request = objectMapper.readValue(requestString, CreateCommunityPostRequest::class.java)
if (request.price > 0 && postImage == null) { if (request.price > 0 && postImage == null) {
throw SodaException("유료 게시글 등록을 위해서는 이미지가 필요합니다.") throw SodaException("유료 게시글 등록을 위해서는 이미지가 필요합니다.")
} }
if (audioFile != null && postImage == null) {
throw SodaException("오디오 등록을 위해서는 이미지가 필요합니다.")
}
val post = CreatorCommunity( val post = CreatorCommunity(
content = request.content, content = request.content,
price = request.price, price = request.price,
@ -84,6 +93,20 @@ class CreatorCommunityService(
post.imagePath = imagePath post.imagePath = imagePath
} }
if (audioFile != null) {
val metadata = ObjectMetadata()
metadata.contentLength = audioFile.size
val audioPath = s3Uploader.upload(
inputStream = audioFile.inputStream,
bucket = imageBucket,
filePath = "creator_community/${post.id}/${generateFileName(prefix = "${post.id}-audio")}.m4a",
metadata = metadata
)
post.audioPath = audioPath
}
applicationEventPublisher.publishEvent( applicationEventPublisher.publishEvent(
FcmEvent( FcmEvent(
type = FcmEventType.CHANGE_NOTICE, type = FcmEventType.CHANGE_NOTICE,