parent
34440e9ba3
commit
d98268f809
|
@ -16,6 +16,7 @@ import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.like.CreatorCo
|
||||||
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.like.CreatorCommunityLikeRepository
|
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.like.CreatorCommunityLikeRepository
|
||||||
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.like.PostCommunityPostLikeRequest
|
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.like.PostCommunityPostLikeRequest
|
||||||
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.like.PostCommunityPostLikeResponse
|
import kr.co.vividnext.sodalive.explorer.profile.creatorCommunity.like.PostCommunityPostLikeResponse
|
||||||
|
import kr.co.vividnext.sodalive.extensions.getTimeAgoString
|
||||||
import kr.co.vividnext.sodalive.fcm.FcmEvent
|
import kr.co.vividnext.sodalive.fcm.FcmEvent
|
||||||
import kr.co.vividnext.sodalive.fcm.FcmEventType
|
import kr.co.vividnext.sodalive.fcm.FcmEventType
|
||||||
import kr.co.vividnext.sodalive.member.Member
|
import kr.co.vividnext.sodalive.member.Member
|
||||||
|
@ -28,8 +29,6 @@ import org.springframework.data.repository.findByIdOrNull
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import org.springframework.transaction.annotation.Transactional
|
import org.springframework.transaction.annotation.Transactional
|
||||||
import org.springframework.web.multipart.MultipartFile
|
import org.springframework.web.multipart.MultipartFile
|
||||||
import java.time.Duration
|
|
||||||
import java.time.LocalDateTime
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class CreatorCommunityService(
|
class CreatorCommunityService(
|
||||||
|
@ -243,7 +242,7 @@ class CreatorCommunityService(
|
||||||
it.toCommunityPostListResponse(
|
it.toCommunityPostListResponse(
|
||||||
imageHost = imageHost,
|
imageHost = imageHost,
|
||||||
audioUrl = audioUrl,
|
audioUrl = audioUrl,
|
||||||
date = getTimeAgoString(it.date),
|
date = it.date.getTimeAgoString(),
|
||||||
isLike = isLike,
|
isLike = isLike,
|
||||||
memberId = memberId,
|
memberId = memberId,
|
||||||
existOrdered = if (memberId == it.creatorId) {
|
existOrdered = if (memberId == it.creatorId) {
|
||||||
|
@ -314,7 +313,7 @@ class CreatorCommunityService(
|
||||||
return post.toCommunityPostListResponse(
|
return post.toCommunityPostListResponse(
|
||||||
imageHost = imageHost,
|
imageHost = imageHost,
|
||||||
audioUrl = audioUrl,
|
audioUrl = audioUrl,
|
||||||
date = getTimeAgoString(post.date),
|
date = post.date.getTimeAgoString(),
|
||||||
isLike = isLike,
|
isLike = isLike,
|
||||||
memberId = memberId,
|
memberId = memberId,
|
||||||
existOrdered = if (memberId == post.creatorId) {
|
existOrdered = if (memberId == post.creatorId) {
|
||||||
|
@ -328,19 +327,6 @@ class CreatorCommunityService(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTimeAgoString(dateTime: LocalDateTime): String {
|
|
||||||
val now = LocalDateTime.now()
|
|
||||||
val duration = Duration.between(dateTime, now)
|
|
||||||
|
|
||||||
return when {
|
|
||||||
duration.toMinutes() < 60 -> "${duration.toMinutes()}분전"
|
|
||||||
duration.toHours() < 24 -> "${duration.toHours()}시간전"
|
|
||||||
duration.toDays() < 30 -> "${duration.toDays()}일전"
|
|
||||||
duration.toDays() < 365 -> "${duration.toDays() / 30}개월전"
|
|
||||||
else -> "${duration.toDays() / 365}년전"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
fun communityPostLike(request: PostCommunityPostLikeRequest, member: Member): PostCommunityPostLikeResponse {
|
fun communityPostLike(request: PostCommunityPostLikeRequest, member: Member): PostCommunityPostLikeResponse {
|
||||||
var postLike = likeRepository.findByPostIdAndMemberId(postId = request.postId, memberId = member.id!!)
|
var postLike = likeRepository.findByPostIdAndMemberId(postId = request.postId, memberId = member.id!!)
|
||||||
|
@ -506,7 +492,7 @@ class CreatorCommunityService(
|
||||||
it.toCommunityPostListResponse(
|
it.toCommunityPostListResponse(
|
||||||
imageHost = imageHost,
|
imageHost = imageHost,
|
||||||
audioUrl = null,
|
audioUrl = null,
|
||||||
date = getTimeAgoString(it.date),
|
date = it.date.getTimeAgoString(),
|
||||||
isLike = isLike,
|
isLike = isLike,
|
||||||
memberId = memberId,
|
memberId = memberId,
|
||||||
existOrdered = if (memberId == it.creatorId) {
|
existOrdered = if (memberId == it.creatorId) {
|
||||||
|
@ -590,7 +576,7 @@ class CreatorCommunityService(
|
||||||
imageHost = imageHost,
|
imageHost = imageHost,
|
||||||
audioUrl = audioUrl,
|
audioUrl = audioUrl,
|
||||||
content = post.content,
|
content = post.content,
|
||||||
date = getTimeAgoString(post.createdAt!!),
|
date = post.createdAt!!.getTimeAgoString(),
|
||||||
isLike = isLike,
|
isLike = isLike,
|
||||||
existOrdered = true,
|
existOrdered = true,
|
||||||
likeCount = likeCount,
|
likeCount = likeCount,
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
package kr.co.vividnext.sodalive.extensions
|
||||||
|
|
||||||
|
import java.time.Duration
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
|
fun LocalDateTime.getTimeAgoString(): String {
|
||||||
|
val now = LocalDateTime.now()
|
||||||
|
val duration = Duration.between(this, now)
|
||||||
|
|
||||||
|
return when {
|
||||||
|
duration.toMinutes() < 1 -> "방금 전"
|
||||||
|
duration.toMinutes() < 60 -> "${duration.toMinutes()}분전"
|
||||||
|
duration.toHours() < 24 -> "${duration.toHours()}시간전"
|
||||||
|
duration.toDays() < 30 -> "${duration.toDays()}일전"
|
||||||
|
duration.toDays() < 365 -> "${duration.toDays() / 30}개월전"
|
||||||
|
else -> "${duration.toDays() / 365}년전"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue