Skip to content

Commit 0dca61b

Browse files
authored
release: 0.7.6 (#82)
2 parents f84a18b + 7433f38 commit 0dca61b

File tree

9 files changed

+30
-12
lines changed

9 files changed

+30
-12
lines changed

docs/api/inbox/get_all_unread_inboxes.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ inboxes = [
1818
"body": "devxb에게 git-goods 길드가입 요청이 왔어요.",
1919
"redirectTo": "/auctions/",
2020
"type": "INBOX" // (INBOX, NOTICE...)
21+
"status": "UNREAD" // READ or UNREAD
2122
}
2223
...
2324
]

src/main/kotlin/org/gitanimals/inbox/app/InboxFacade.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class InboxFacade(
1313
fun findAllUnreadByToken(token: String): InboxApplication {
1414
val userId = identityApi.getUserByToken(token).id.toLong()
1515

16-
return inboxService.findAllUnreadByUserId(userId)
16+
return inboxService.findAllByUserId(userId)
1717
}
1818

1919
fun readInboxByTokenAndId(token: String, id: Long) {

src/main/kotlin/org/gitanimals/inbox/controller/response/InboxResponse.kt

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.gitanimals.inbox.controller.response
22

33
import org.gitanimals.inbox.domain.InboxApplication
4+
import org.gitanimals.inbox.domain.InboxStatus
45
import org.gitanimals.inbox.domain.InboxType
56

67
data class InboxResponse(
@@ -14,6 +15,7 @@ data class InboxResponse(
1415
val body: String,
1516
val redirectTo: String,
1617
val type: InboxType,
18+
val status: InboxStatus,
1719
)
1820

1921
companion object {
@@ -28,6 +30,7 @@ data class InboxResponse(
2830
body = it.body,
2931
redirectTo = it.redirectTo,
3032
type = it.type,
33+
status = it.getStatus(),
3134
)
3235
}
3336
)

src/main/kotlin/org/gitanimals/inbox/domain/Inbox.kt

+8
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,19 @@ class Inbox(
3636
@Embedded
3737
val publisher: Publisher,
3838

39+
@Enumerated(EnumType.STRING)
40+
@Column(name = "status")
41+
private var status: InboxStatus,
42+
3943
@Column(name = "read_at")
4044
private var readAt: Instant?,
4145
) : AbstractTime() {
4246

47+
fun getStatus(): InboxStatus = status
48+
4349
fun read() {
4450
readAt = Instant.now()
51+
status = InboxStatus.READ
4552
}
4653

4754
companion object {
@@ -68,6 +75,7 @@ class Inbox(
6875
type = type,
6976
redirectTo = redirectTo,
7077
image = image,
78+
status = InboxStatus.UNREAD,
7179
)
7280
}
7381
}

src/main/kotlin/org/gitanimals/inbox/domain/InboxRepository.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ interface InboxRepository: JpaRepository<Inbox, Long> {
99
@Query(
1010
"""
1111
select i from inbox as i
12-
where i.userId = :userId
13-
and i.readAt is null
12+
where i.userId = :userId
1413
"""
1514
)
16-
fun findAllUnReadByUserId(@Param("userId") userId: Long): List<Inbox>
15+
fun findByUserId(@Param("userId") userId: Long): List<Inbox>
1716

1817
@Query(
1918
"""

src/main/kotlin/org/gitanimals/inbox/domain/InboxService.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class InboxService(
1010
private val inboxRepository: InboxRepository,
1111
) {
1212

13-
fun findAllUnreadByUserId(userId: Long): InboxApplication {
14-
val inboxes = inboxRepository.findAllUnReadByUserId(userId)
13+
fun findAllByUserId(userId: Long): InboxApplication {
14+
val inboxes = inboxRepository.findByUserId(userId)
1515

1616
return InboxApplication(userId, inboxes)
1717
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.gitanimals.inbox.domain
2+
3+
enum class InboxStatus {
4+
READ,
5+
UNREAD,
6+
}

src/test/kotlin/org/gitanimals/inbox/domain/Fixture.kt

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fun inbox(
1212
type: InboxType = InboxType.INBOX,
1313
redirectTo: String = "/",
1414
image: String = "/inboxes/default.png",
15+
status: InboxStatus = InboxStatus.UNREAD,
1516
): Inbox {
1617
return Inbox(
1718
id = IdGenerator.generate(),
@@ -26,5 +27,6 @@ fun inbox(
2627
type = type,
2728
redirectTo = redirectTo,
2829
image = image,
30+
status = status,
2931
)
3032
}

src/test/kotlin/org/gitanimals/inbox/domain/InboxServiceTest.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ internal class InboxServiceTest(
2020
private val inboxRepository: InboxRepository,
2121
) : DescribeSpec({
2222

23-
describe("findAllUnreadByUserId 메소드는") {
23+
describe("findAllByUserId 메소드는") {
2424
context("userId를 입력받으면") {
2525
val userId = 1L
2626
inboxRepository.saveAndFlush(inbox(userId = userId))
2727
inboxRepository.saveAndFlush(inbox(userId = userId))
2828

29-
it("읽지 않은 모든 Inbox를 조회한다.") {
30-
val result = inboxService.findAllUnreadByUserId(userId)
29+
it("유저의 모든 Inbox를 조회한다.") {
30+
val result = inboxService.findAllByUserId(userId)
3131

3232
result.inboxes.size shouldBe 2
3333
}
@@ -38,13 +38,12 @@ internal class InboxServiceTest(
3838
context("userId와 inbox id를 입력받으면") {
3939
val userId = 2L
4040
val inbox1 = inboxRepository.saveAndFlush(inbox(userId = userId))
41-
val inbox2 = inboxRepository.saveAndFlush(inbox(userId = userId))
4241

4342
it("userId와 id에 해당하는 inbox를 읽음 처리한다") {
4443
inboxService.readById(userId, inbox1.id)
45-
val result = inboxService.findAllUnreadByUserId(userId)
44+
val result = inboxService.findAllByUserId(userId)
4645

47-
result.inboxes.size shouldBe 1
46+
result.inboxes[0].getStatus() shouldBe InboxStatus.READ
4847
}
4948
}
5049
}

0 commit comments

Comments
 (0)