diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/service/NotificationDetailApiImpl.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/service/NotificationDetailApiImpl.kt index ac10d54..87573bd 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/service/NotificationDetailApiImpl.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/service/NotificationDetailApiImpl.kt @@ -91,7 +91,7 @@ class NotificationDetailApiImpl( override fun queryNotificationDetail(userId: UUID): DetailResponse { postDetailRepositorySpi.updateAllDetailByUserIdAndIsReadFalse(userId) return DetailResponse( - queryDetailRepositorySpi.findAllByUserId(userId) + queryDetailRepositorySpi.findAllByUserIdOrderBySentAtDesc(userId) .map { DetailElement( id = it.id, diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/spi/QueryDetailRepositorySpi.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/spi/QueryDetailRepositorySpi.kt index fdb1cdb..f6c849f 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/spi/QueryDetailRepositorySpi.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/detail/spi/QueryDetailRepositorySpi.kt @@ -6,6 +6,6 @@ import java.util.UUID @Spi interface QueryDetailRepositorySpi { - fun findAllByUserId(userId: UUID): List + fun findAllByUserIdOrderBySentAtDesc(userId: UUID): List fun findAllByUseridAndIsReadFalse(userId: UUID): Int } diff --git a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemoryDetailRepository.kt b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemoryDetailRepository.kt index 6236274..0d1617b 100644 --- a/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemoryDetailRepository.kt +++ b/notification-domain/src/main/kotlin/io/github/v1servicenotification/stubs/InMemoryDetailRepository.kt @@ -21,7 +21,7 @@ class InMemoryDetailRepository( detailMap[detail.id] = detail } - override fun findAllByUserId(userId: UUID): List { + override fun findAllByUserIdOrderBySentAtDesc(userId: UUID): List { return detailMap.filter { it.value.userId == userId } .map { val category = categoryMap[it.value.categoryId] @@ -35,7 +35,7 @@ class InMemoryDetailRepository( it.value.userId, category.topic, ) - } + }.sortedByDescending { it.sentAt } } override fun findAllByUseridAndIsReadFalse(userId: UUID): Int { diff --git a/notification-domain/src/test/kotlin/io/github/v1servicenotification/detail/DetailApiImplTest.kt b/notification-domain/src/test/kotlin/io/github/v1servicenotification/detail/DetailApiImplTest.kt index d80723d..2c3c6f4 100644 --- a/notification-domain/src/test/kotlin/io/github/v1servicenotification/detail/DetailApiImplTest.kt +++ b/notification-domain/src/test/kotlin/io/github/v1servicenotification/detail/DetailApiImplTest.kt @@ -75,9 +75,9 @@ class DetailApiImplTest { detailApi.postGroupNotification(category.topic, content, threadId) - assertThat(detailSpi.findAllByUserId(userId).size).isEqualTo(1) + assertThat(detailSpi.findAllByUserIdOrderBySentAtDesc(userId).size).isEqualTo(1) - detailSpi.findAllByUserId(userId) + detailSpi.findAllByUserIdOrderBySentAtDesc(userId) .forEach { assertThat(it.title).isEqualTo(title) assertThat(it.content).isEqualTo(content) @@ -110,7 +110,7 @@ class DetailApiImplTest { detailApi.postGroupNotification(category.topic, content, threadId) - detailSpi.findAllByUserId(userId) + detailSpi.findAllByUserIdOrderBySentAtDesc(userId) .forEach { assertThat(it.title).isEqualTo(title) assertThat(it.content).isEqualTo(content) @@ -143,7 +143,7 @@ class DetailApiImplTest { detailApi.postGroupNotification(category.topic, content, threadId) - detailSpi.findAllByUserId(userId) + detailSpi.findAllByUserIdOrderBySentAtDesc(userId) .forEach { assertThat(it.title).isEqualTo(title) assertThat(it.content).isEqualTo(content) @@ -181,7 +181,7 @@ class DetailApiImplTest { detailApi.postNotification(userId, category.topic, content, threadId) - detailSpi.findAllByUserId(userId) + detailSpi.findAllByUserIdOrderBySentAtDesc(userId) .forEach { assertThat(it.title).isEqualTo(title) assertThat(it.content).isEqualTo(content) diff --git a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/detail/domain/repository/CustomDetailRepositoryImpl.kt b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/detail/domain/repository/CustomDetailRepositoryImpl.kt index 3159603..9fb621b 100644 --- a/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/detail/domain/repository/CustomDetailRepositoryImpl.kt +++ b/notification-infrastructure/src/main/kotlin/io/github/v1servicenotification/domain/detail/domain/repository/CustomDetailRepositoryImpl.kt @@ -19,7 +19,7 @@ class CustomDetailRepositoryImpl( private val detailMapper: DetailMapper, private val query: JPAQueryFactory, ) : QueryDetailRepositorySpi, PostDetailRepositorySpi { - override fun findAllByUserId(userId: UUID): List { + override fun findAllByUserIdOrderBySentAtDesc(userId: UUID): List { return query .select( QDetailVO( @@ -49,7 +49,7 @@ class CustomDetailRepositoryImpl( topic = it.topic, ) } - .toList() + .toList().sortedByDescending { it.sentAt } } override fun findAllByUseridAndIsReadFalse(userId: UUID): Int {