크리에이터 커뮤니티

- 오디오 등록 기능 추가
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 isAdult: Boolean,
@Column(nullable = true)
var audioPath: String? = null,
@Column(nullable = true)
var imagePath: String? = null,
var isActive: Boolean = true
) : BaseEntity() {

View File

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

View File

@ -50,13 +50,22 @@ class CreatorCommunityService(
private val imageHost: String
) {
@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)
if (request.price > 0 && postImage == null) {
throw SodaException("유료 게시글 등록을 위해서는 이미지가 필요합니다.")
}
if (audioFile != null && postImage == null) {
throw SodaException("오디오 등록을 위해서는 이미지가 필요합니다.")
}
val post = CreatorCommunity(
content = request.content,
price = request.price,
@ -84,6 +93,20 @@ class CreatorCommunityService(
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(
FcmEvent(
type = FcmEventType.CHANGE_NOTICE,