refactor: timeAgo 함수
- LocalDateTime 확장함수 처리
This commit is contained in:
		| @@ -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.PostCommunityPostLikeRequest | ||||
| 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.FcmEventType | ||||
| 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.transaction.annotation.Transactional | ||||
| import org.springframework.web.multipart.MultipartFile | ||||
| import java.time.Duration | ||||
| import java.time.LocalDateTime | ||||
|  | ||||
| @Service | ||||
| class CreatorCommunityService( | ||||
| @@ -243,7 +242,7 @@ class CreatorCommunityService( | ||||
|                 it.toCommunityPostListResponse( | ||||
|                     imageHost = imageHost, | ||||
|                     audioUrl = audioUrl, | ||||
|                     date = getTimeAgoString(it.date), | ||||
|                     date = it.date.getTimeAgoString(), | ||||
|                     isLike = isLike, | ||||
|                     memberId = memberId, | ||||
|                     existOrdered = if (memberId == it.creatorId) { | ||||
| @@ -314,7 +313,7 @@ class CreatorCommunityService( | ||||
|         return post.toCommunityPostListResponse( | ||||
|             imageHost = imageHost, | ||||
|             audioUrl = audioUrl, | ||||
|             date = getTimeAgoString(post.date), | ||||
|             date = post.date.getTimeAgoString(), | ||||
|             isLike = isLike, | ||||
|             memberId = memberId, | ||||
|             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 | ||||
|     fun communityPostLike(request: PostCommunityPostLikeRequest, member: Member): PostCommunityPostLikeResponse { | ||||
|         var postLike = likeRepository.findByPostIdAndMemberId(postId = request.postId, memberId = member.id!!) | ||||
| @@ -506,7 +492,7 @@ class CreatorCommunityService( | ||||
|                 it.toCommunityPostListResponse( | ||||
|                     imageHost = imageHost, | ||||
|                     audioUrl = null, | ||||
|                     date = getTimeAgoString(it.date), | ||||
|                     date = it.date.getTimeAgoString(), | ||||
|                     isLike = isLike, | ||||
|                     memberId = memberId, | ||||
|                     existOrdered = if (memberId == it.creatorId) { | ||||
| @@ -590,7 +576,7 @@ class CreatorCommunityService( | ||||
|             imageHost = imageHost, | ||||
|             audioUrl = audioUrl, | ||||
|             content = post.content, | ||||
|             date = getTimeAgoString(post.createdAt!!), | ||||
|             date = post.createdAt!!.getTimeAgoString(), | ||||
|             isLike = isLike, | ||||
|             existOrdered = true, | ||||
|             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}년전" | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user