Skip to content

Commit

Permalink
release: 0.7.6 (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb authored Nov 30, 2024
2 parents f84a18b + 7433f38 commit 0dca61b
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/api/inbox/get_all_unread_inboxes.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ inboxes = [
"body": "devxb에게 git-goods 길드가입 요청이 왔어요.",
"redirectTo": "/auctions/",
"type": "INBOX" // (INBOX, NOTICE...)
"status": "UNREAD" // READ or UNREAD
}
...
]
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/gitanimals/inbox/app/InboxFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -14,6 +15,7 @@ data class InboxResponse(
val body: String,
val redirectTo: String,
val type: InboxType,
val status: InboxStatus,
)

companion object {
Expand All @@ -28,6 +30,7 @@ data class InboxResponse(
body = it.body,
redirectTo = it.redirectTo,
type = it.type,
status = it.getStatus(),
)
}
)
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/org/gitanimals/inbox/domain/Inbox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -68,6 +75,7 @@ class Inbox(
type = type,
redirectTo = redirectTo,
image = image,
status = InboxStatus.UNREAD,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ interface InboxRepository: JpaRepository<Inbox, Long> {
@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<Inbox>
fun findByUserId(@Param("userId") userId: Long): List<Inbox>

@Query(
"""
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/org/gitanimals/inbox/domain/InboxService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/org/gitanimals/inbox/domain/InboxStatus.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.gitanimals.inbox.domain

enum class InboxStatus {
READ,
UNREAD,
}
2 changes: 2 additions & 0 deletions src/test/kotlin/org/gitanimals/inbox/domain/Fixture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -26,5 +27,6 @@ fun inbox(
type = type,
redirectTo = redirectTo,
image = image,
status = status,
)
}
11 changes: 5 additions & 6 deletions src/test/kotlin/org/gitanimals/inbox/domain/InboxServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
}
}
Expand Down

0 comments on commit 0dca61b

Please sign in to comment.