Skip to content

Commit

Permalink
feat: 보틀 목록에서 마지막 활성 시간을 제공한다 (#366)
Browse files Browse the repository at this point in the history
* feat: 보틀 목록에서 마지막 활성 시간을 제공한다

* feat: 코드리뷰 반영
  • Loading branch information
injoon2019 authored Aug 30, 2024
1 parent 80f43f9 commit 4725f2d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.nexters.bottles.api.bottle.facade.dto.PingPongLetter
import com.nexters.bottles.api.bottle.facade.dto.PingPongListResponse
import com.nexters.bottles.api.bottle.facade.dto.PingPongUserProfile
import com.nexters.bottles.api.bottle.facade.dto.RegisterLetterRequest
import com.nexters.bottles.api.bottle.util.getLastActivatedAtInKorean
import com.nexters.bottles.api.user.component.event.dto.UserApplicationEventDto
import com.nexters.bottles.app.bottle.domain.Bottle
import com.nexters.bottles.app.bottle.domain.Letter
Expand Down Expand Up @@ -115,7 +116,8 @@ class BottleFacade(
mbti = bottle.sourceUser.userProfile?.profileSelect?.mbti,
keyword = bottle.sourceUser.userProfile?.profileSelect?.keyword,
userImageUrl = bottle.sourceUser.userProfile?.imageUrl,
expiredAt = bottle.expiredAt
expiredAt = bottle.expiredAt,
lastActivatedAt = getLastActivatedAtInKorean(basedAt = bottle.sourceUser.lastActivatedAt, now = LocalDateTime.now())
)
}

Expand Down Expand Up @@ -202,6 +204,7 @@ class BottleFacade(
mbti = otherUser.userProfile?.profileSelect?.mbti,
keyword = otherUser.userProfile?.profileSelect?.keyword,
userImageUrl = otherUser.userProfile?.imageUrl,
lastActivatedAt = getLastActivatedAtInKorean(basedAt = otherUser.lastActivatedAt, now = LocalDateTime.now())
)
}

Expand Down Expand Up @@ -277,7 +280,9 @@ class BottleFacade(
meetingPlace = null,
meetingPlaceImageUrl = null,
)
)
).also {
applicationEventPublisher.publishEvent(UserApplicationEventDto(userId = userId, basedAt = LocalDateTime.now()))
}
}

private fun getDeleteAfterDays(bottle: Bottle): Long? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data class BottleDto(
val mbti: String?,
val keyword: List<String>?,
val userImageUrl: String?,
val lastActivatedAt: String?,

@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
val expiredAt: LocalDateTime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.nexters.bottles.api.bottle.facade.dto

import java.time.LocalDateTime

data class PingPongListResponse(
val activeBottles: List<PingPongBottleDto>,
val doneBottles: List<PingPongBottleDto>
Expand All @@ -14,4 +16,5 @@ data class PingPongBottleDto(
val mbti: String?,
val keyword: List<String>?,
val userImageUrl: String?,
val lastActivatedAt: String?,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nexters.bottles.api.bottle.util

import java.time.LocalDateTime
import java.time.temporal.ChronoUnit

fun getLastActivatedAtInKorean(basedAt: LocalDateTime, now: LocalDateTime): String {
val minutesBetween = ChronoUnit.MINUTES.between(basedAt, now)

return when {
minutesBetween >= 1440 -> "${minutesBetween / 1440}일 전" // 1440분은 24시간
minutesBetween >= 60 -> "${minutesBetween / 60}시간 전"
else -> "${minutesBetween}분 전"
}
}

0 comments on commit 4725f2d

Please sign in to comment.