Skip to content

Commit

Permalink
feat(server): show last read time in history list
Browse files Browse the repository at this point in the history
  • Loading branch information
FishHawk committed Jun 25, 2024
1 parent af0eada commit ed6fe63
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import infra.web.WebNovelListItem
import infra.web.WebNovelReadHistoryDbModel
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.serialization.Contextual
import kotlinx.serialization.Serializable
import org.bson.types.ObjectId

Expand All @@ -31,10 +33,16 @@ class WebNovelReadHistoryRepository(
page: Int,
pageSize: Int,
): Page<WebNovelListItem> {
@Serializable
data class WebNovelAndHistory(
@Contextual val createAt: Instant,
val novel: WebNovel,
)

@Serializable
data class PageModel(
val total: Int = 0,
val items: List<WebNovel>,
val items: List<WebNovelAndHistory>,
)

val doc = userReadHistoryWebCollection
Expand All @@ -56,7 +64,6 @@ class WebNovelReadHistoryRepository(
/* as = */ "novel"
),
unwind("\$novel"),
replaceRoot("\$novel"),
)
),
project(
Expand All @@ -71,7 +78,7 @@ class WebNovelReadHistoryRepository(
emptyPage()
} else {
Page(
items = doc.items.map { it.toOutline() },
items = doc.items.map { it.novel.toOutline().copy(lastReadAt = it.createAt) },
total = doc.total.toLong(),
pageSize = pageSize,
)
Expand Down

0 comments on commit ed6fe63

Please sign in to comment.