From 7433f38ac8b5a340d51e0f38815732e7af2fc6e8 Mon Sep 17 00:00:00 2001 From: devxb Date: Sat, 30 Nov 2024 23:33:10 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=95=8C=EB=A6=BC=20=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=20=EC=A0=95=EC=B1=85=EC=9D=84=20=EC=88=98=EC=A0=95=ED=95=98?= =?UTF-8?q?=EA=B3=A0=20=EC=95=8C=EB=A6=BC=EB=8F=84=EB=A9=94=EC=9D=B8?= =?UTF-8?q?=EC=97=90=20=EC=83=81=ED=83=9C=EB=A5=BC=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api/inbox/get_all_unread_inboxes.md | 1 + .../kotlin/org/gitanimals/inbox/app/InboxFacade.kt | 2 +- .../inbox/controller/response/InboxResponse.kt | 3 +++ src/main/kotlin/org/gitanimals/inbox/domain/Inbox.kt | 8 ++++++++ .../org/gitanimals/inbox/domain/InboxRepository.kt | 5 ++--- .../org/gitanimals/inbox/domain/InboxService.kt | 4 ++-- .../kotlin/org/gitanimals/inbox/domain/InboxStatus.kt | 6 ++++++ .../kotlin/org/gitanimals/inbox/domain/Fixture.kt | 2 ++ .../org/gitanimals/inbox/domain/InboxServiceTest.kt | 11 +++++------ 9 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 src/main/kotlin/org/gitanimals/inbox/domain/InboxStatus.kt diff --git a/docs/api/inbox/get_all_unread_inboxes.md b/docs/api/inbox/get_all_unread_inboxes.md index 1ddaa49..db76675 100644 --- a/docs/api/inbox/get_all_unread_inboxes.md +++ b/docs/api/inbox/get_all_unread_inboxes.md @@ -18,6 +18,7 @@ inboxes = [ "body": "devxb에게 git-goods 길드가입 요청이 왔어요.", "redirectTo": "/auctions/", "type": "INBOX" // (INBOX, NOTICE...) + "status": "UNREAD" // READ or UNREAD } ... ] diff --git a/src/main/kotlin/org/gitanimals/inbox/app/InboxFacade.kt b/src/main/kotlin/org/gitanimals/inbox/app/InboxFacade.kt index 58317d2..fa35229 100644 --- a/src/main/kotlin/org/gitanimals/inbox/app/InboxFacade.kt +++ b/src/main/kotlin/org/gitanimals/inbox/app/InboxFacade.kt @@ -13,7 +13,7 @@ class InboxFacade( fun findAllUnreadByToken(token: String): InboxApplication { val userId = identityApi.getUserByToken(token).id.toLong() - return inboxService.findAllUnreadByUserId(userId) + return inboxService.findAllByUserId(userId) } fun readInboxByTokenAndId(token: String, id: Long) { diff --git a/src/main/kotlin/org/gitanimals/inbox/controller/response/InboxResponse.kt b/src/main/kotlin/org/gitanimals/inbox/controller/response/InboxResponse.kt index 18233b2..a8bb9fe 100644 --- a/src/main/kotlin/org/gitanimals/inbox/controller/response/InboxResponse.kt +++ b/src/main/kotlin/org/gitanimals/inbox/controller/response/InboxResponse.kt @@ -1,6 +1,7 @@ package org.gitanimals.inbox.controller.response import org.gitanimals.inbox.domain.InboxApplication +import org.gitanimals.inbox.domain.InboxStatus import org.gitanimals.inbox.domain.InboxType data class InboxResponse( @@ -14,6 +15,7 @@ data class InboxResponse( val body: String, val redirectTo: String, val type: InboxType, + val status: InboxStatus, ) companion object { @@ -28,6 +30,7 @@ data class InboxResponse( body = it.body, redirectTo = it.redirectTo, type = it.type, + status = it.getStatus(), ) } ) diff --git a/src/main/kotlin/org/gitanimals/inbox/domain/Inbox.kt b/src/main/kotlin/org/gitanimals/inbox/domain/Inbox.kt index dbff93f..5b0b33f 100644 --- a/src/main/kotlin/org/gitanimals/inbox/domain/Inbox.kt +++ b/src/main/kotlin/org/gitanimals/inbox/domain/Inbox.kt @@ -36,12 +36,19 @@ class Inbox( @Embedded val publisher: Publisher, + @Enumerated(EnumType.STRING) + @Column(name = "status") + private var status: InboxStatus, + @Column(name = "read_at") private var readAt: Instant?, ) : AbstractTime() { + fun getStatus(): InboxStatus = status + fun read() { readAt = Instant.now() + status = InboxStatus.READ } companion object { @@ -68,6 +75,7 @@ class Inbox( type = type, redirectTo = redirectTo, image = image, + status = InboxStatus.UNREAD, ) } } diff --git a/src/main/kotlin/org/gitanimals/inbox/domain/InboxRepository.kt b/src/main/kotlin/org/gitanimals/inbox/domain/InboxRepository.kt index 95f50e4..f1fbf16 100644 --- a/src/main/kotlin/org/gitanimals/inbox/domain/InboxRepository.kt +++ b/src/main/kotlin/org/gitanimals/inbox/domain/InboxRepository.kt @@ -9,11 +9,10 @@ interface InboxRepository: JpaRepository { @Query( """ select i from inbox as i - where i.userId = :userId - and i.readAt is null + where i.userId = :userId """ ) - fun findAllUnReadByUserId(@Param("userId") userId: Long): List + fun findByUserId(@Param("userId") userId: Long): List @Query( """ diff --git a/src/main/kotlin/org/gitanimals/inbox/domain/InboxService.kt b/src/main/kotlin/org/gitanimals/inbox/domain/InboxService.kt index 8ac3abc..fd700ba 100644 --- a/src/main/kotlin/org/gitanimals/inbox/domain/InboxService.kt +++ b/src/main/kotlin/org/gitanimals/inbox/domain/InboxService.kt @@ -10,8 +10,8 @@ class InboxService( private val inboxRepository: InboxRepository, ) { - fun findAllUnreadByUserId(userId: Long): InboxApplication { - val inboxes = inboxRepository.findAllUnReadByUserId(userId) + fun findAllByUserId(userId: Long): InboxApplication { + val inboxes = inboxRepository.findByUserId(userId) return InboxApplication(userId, inboxes) } diff --git a/src/main/kotlin/org/gitanimals/inbox/domain/InboxStatus.kt b/src/main/kotlin/org/gitanimals/inbox/domain/InboxStatus.kt new file mode 100644 index 0000000..82c17a9 --- /dev/null +++ b/src/main/kotlin/org/gitanimals/inbox/domain/InboxStatus.kt @@ -0,0 +1,6 @@ +package org.gitanimals.inbox.domain + +enum class InboxStatus { + READ, + UNREAD, +} diff --git a/src/test/kotlin/org/gitanimals/inbox/domain/Fixture.kt b/src/test/kotlin/org/gitanimals/inbox/domain/Fixture.kt index 2a1c2ea..8fed0d4 100644 --- a/src/test/kotlin/org/gitanimals/inbox/domain/Fixture.kt +++ b/src/test/kotlin/org/gitanimals/inbox/domain/Fixture.kt @@ -12,6 +12,7 @@ fun inbox( type: InboxType = InboxType.INBOX, redirectTo: String = "/", image: String = "/inboxes/default.png", + status: InboxStatus = InboxStatus.UNREAD, ): Inbox { return Inbox( id = IdGenerator.generate(), @@ -26,5 +27,6 @@ fun inbox( type = type, redirectTo = redirectTo, image = image, + status = status, ) } diff --git a/src/test/kotlin/org/gitanimals/inbox/domain/InboxServiceTest.kt b/src/test/kotlin/org/gitanimals/inbox/domain/InboxServiceTest.kt index 26799b2..af3b3e3 100644 --- a/src/test/kotlin/org/gitanimals/inbox/domain/InboxServiceTest.kt +++ b/src/test/kotlin/org/gitanimals/inbox/domain/InboxServiceTest.kt @@ -20,14 +20,14 @@ internal class InboxServiceTest( private val inboxRepository: InboxRepository, ) : DescribeSpec({ - describe("findAllUnreadByUserId 메소드는") { + describe("findAllByUserId 메소드는") { context("userId를 입력받으면") { val userId = 1L inboxRepository.saveAndFlush(inbox(userId = userId)) inboxRepository.saveAndFlush(inbox(userId = userId)) - it("읽지 않은 모든 Inbox를 조회한다.") { - val result = inboxService.findAllUnreadByUserId(userId) + it("유저의 모든 Inbox를 조회한다.") { + val result = inboxService.findAllByUserId(userId) result.inboxes.size shouldBe 2 } @@ -38,13 +38,12 @@ internal class InboxServiceTest( context("userId와 inbox id를 입력받으면") { val userId = 2L val inbox1 = inboxRepository.saveAndFlush(inbox(userId = userId)) - val inbox2 = inboxRepository.saveAndFlush(inbox(userId = userId)) it("userId와 id에 해당하는 inbox를 읽음 처리한다") { inboxService.readById(userId, inbox1.id) - val result = inboxService.findAllUnreadByUserId(userId) + val result = inboxService.findAllByUserId(userId) - result.inboxes.size shouldBe 1 + result.inboxes[0].getStatus() shouldBe InboxStatus.READ } } }