parent
fd1b17e356
commit
7055bb9872
|
@ -5,6 +5,9 @@ import com.querydsl.jpa.impl.JPAQueryFactory
|
|||
import kr.co.vividnext.sodalive.content.QAudioContent.audioContent
|
||||
import kr.co.vividnext.sodalive.content.category.QCategoryContent.categoryContent
|
||||
import kr.co.vividnext.sodalive.content.comment.QAudioContentComment.audioContentComment
|
||||
import kr.co.vividnext.sodalive.content.hashtag.AudioContentHashTag
|
||||
import kr.co.vividnext.sodalive.content.hashtag.QAudioContentHashTag.audioContentHashTag
|
||||
import kr.co.vividnext.sodalive.content.hashtag.QHashTag.hashTag
|
||||
import kr.co.vividnext.sodalive.content.like.QAudioContentLike.audioContentLike
|
||||
import kr.co.vividnext.sodalive.content.main.ContentCreatorResponse
|
||||
import kr.co.vividnext.sodalive.content.main.GetAudioContentMainItem
|
||||
|
@ -169,6 +172,10 @@ interface AudioContentQueryRepository {
|
|||
fun findNextContent(seriesId: Long, title: String, isAdult: Boolean): OtherContentResponse?
|
||||
|
||||
fun findSeriesIdByContentId(contentId: Long, isAdult: Boolean): Long?
|
||||
|
||||
fun findContentHashTagByContentIdAndIsActive(contentId: Long, isActive: Boolean): List<AudioContentHashTag>
|
||||
|
||||
fun findContentIdAndHashTagId(contentId: Long, hashTagId: Int): AudioContentHashTag?
|
||||
}
|
||||
|
||||
@Repository
|
||||
|
@ -1240,4 +1247,31 @@ class AudioContentQueryRepositoryImpl(
|
|||
.limit(1)
|
||||
.fetchFirst()
|
||||
}
|
||||
|
||||
override fun findContentHashTagByContentIdAndIsActive(
|
||||
contentId: Long,
|
||||
isActive: Boolean
|
||||
): List<AudioContentHashTag> {
|
||||
return queryFactory
|
||||
.selectFrom(audioContentHashTag)
|
||||
.innerJoin(audioContentHashTag.audioContent, audioContent)
|
||||
.where(
|
||||
audioContentHashTag.isActive.eq(isActive)
|
||||
.and(audioContent.id.eq(contentId))
|
||||
)
|
||||
.fetch()
|
||||
}
|
||||
|
||||
override fun findContentIdAndHashTagId(contentId: Long, hashTagId: Int): AudioContentHashTag? {
|
||||
return queryFactory
|
||||
.selectFrom(audioContentHashTag)
|
||||
.innerJoin(audioContentHashTag.audioContent, audioContent)
|
||||
.innerJoin(audioContentHashTag.hashTag, hashTag)
|
||||
.where(
|
||||
audioContent.id.eq(contentId),
|
||||
hashTag.id.eq(hashTagId)
|
||||
)
|
||||
.orderBy(audioContentHashTag.id.asc())
|
||||
.fetchFirst()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,6 +104,7 @@ class AudioContentService(
|
|||
|
||||
if (request.title != null) audioContent.title = request.title
|
||||
if (request.detail != null) audioContent.detail = request.detail
|
||||
if (request.isPointAvailable != null) audioContent.isPointAvailable = request.isPointAvailable
|
||||
audioContent.isCommentAvailable = request.isCommentAvailable
|
||||
audioContent.isAdult = request.isAdult
|
||||
|
||||
|
@ -124,6 +125,41 @@ class AudioContentService(
|
|||
|
||||
audioContent.coverImage = coverImagePath
|
||||
}
|
||||
|
||||
if (!request.tags.isNullOrBlank()) {
|
||||
val normalizedTags = request.tags
|
||||
.replace("#", " #")
|
||||
.split(" ")
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotBlank() }
|
||||
.map { if (it.startsWith("#")) it else "#$it" }
|
||||
.distinct()
|
||||
|
||||
val currentContentTags = repository.findContentHashTagByContentIdAndIsActive(request.contentId, true)
|
||||
val currentTagMap = currentContentTags.associateBy { it.hashTag!!.tag }
|
||||
|
||||
val tagsToAdd = normalizedTags.subtract(currentTagMap.keys)
|
||||
val tagsToDeactivate = currentTagMap.keys.subtract(normalizedTags.toSet())
|
||||
|
||||
tagsToDeactivate.forEach {
|
||||
currentTagMap[it]?.let { cht -> cht.isActive = false }
|
||||
}
|
||||
|
||||
val newAudioContentHashTagList = tagsToAdd.map { tag ->
|
||||
val hashTag = hashTagRepository.findByTag(tag)
|
||||
?: hashTagRepository.save(HashTag(tag))
|
||||
|
||||
val audioContentHashTag = repository.findContentIdAndHashTagId(request.contentId, hashTag.id!!)
|
||||
?: AudioContentHashTag()
|
||||
audioContentHashTag.audioContent = audioContent
|
||||
audioContentHashTag.hashTag = hashTag
|
||||
audioContentHashTag.isActive = true
|
||||
|
||||
audioContentHashTag
|
||||
}
|
||||
|
||||
audioContent.audioContentHashTags.addAll(newAudioContentHashTagList)
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
|
|
@ -4,6 +4,8 @@ data class ModifyAudioContentRequest(
|
|||
val contentId: Long,
|
||||
val title: String?,
|
||||
val detail: String?,
|
||||
val tags: String?,
|
||||
val isAdult: Boolean,
|
||||
val isPointAvailable: Boolean?,
|
||||
val isCommentAvailable: Boolean
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue