Skip to content

#143,144,146 - 쪽지 Overview 및 디테일 조회 개발 #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@ import com.wespot.message.dto.request.CreatedMessageV2Request
import com.wespot.message.port.`in`.CreatedMessageV2UseCase
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/api/v2/messages")
class CreateMessageV2Controller(
private val createdMessageV2Usecase: CreatedMessageV2UseCase
private val createdMessageV2UseCase: CreatedMessageV2UseCase,
) {

@PostMapping
fun createMessageV2(
createdMessageV2Request: CreatedMessageV2Request
): ResponseEntity<Unit> {
createdMessageV2Usecase.createMessage(createdMessageV2Request)
createdMessageV2UseCase.createMessage(createdMessageV2Request)

return ResponseEntity
.status(HttpStatus.CREATED)
.build();
.build()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.wespot.message.v2

import com.wespot.message.dto.response.MessageV2DetailsResponse
import com.wespot.message.dto.response.MessageV2OverviewResponse
import com.wespot.message.port.`in`.GetMessageV2UseCase
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/api/v2/messages")
class GetMessageV2Controller(
private val getMessageV2UseCase: GetMessageV2UseCase
) {

@GetMapping
fun getMessagesOverview(): ResponseEntity<List<MessageV2OverviewResponse>> {
val response = getMessageV2UseCase.getMessageOverview()

return ResponseEntity.ok(response)
}

@GetMapping("/bookmarks")
fun getBookmarkedMessagesOverview(): ResponseEntity<List<MessageV2OverviewResponse>> {
val response = getMessageV2UseCase.getBookmarkedMessageOverview()

return ResponseEntity.ok(response)
}

@GetMapping("/{messageId}/details")
fun getMessageDetails(@PathVariable messageId: Long): ResponseEntity<MessageV2DetailsResponse> {
val response = getMessageV2UseCase.getMessageDetails(messageId)

return ResponseEntity.ok(response)
}
}
3 changes: 0 additions & 3 deletions app/src/test/kotlin/com/wespot/common/infra/TestContainer.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.wespot.common.infra

import org.springframework.boot.test.context.TestConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.jdbc.datasource.init.DataSourceInitializer
import org.testcontainers.containers.GenericContainer
import org.testcontainers.utility.DockerImageName
import javax.sql.DataSource


@TestConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.wespot.common.service
import com.wespot.DatabaseCleanup
import com.wespot.common.infra.TestContainer
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.annotation.Import
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import com.wespot.user.fixture.UserFixture
import com.wespot.user.port.out.UserPort
import io.kotest.matchers.shouldBe
import io.mockk.clearAllMocks
import org.awaitility.kotlin.await
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.context.ApplicationEventPublisher
import java.time.Clock
import java.time.Instant
import java.time.ZoneId
import java.util.concurrent.TimeUnit

class RealSendMessageServiceTest @Autowired constructor(
private val userPort: UserPort,
Expand All @@ -28,47 +30,48 @@ class RealSendMessageServiceTest @Autowired constructor(

@Test
fun `쪽지를 3개 보냈을 때, 쪽지 독려 알림이 비활성화된다`() {
Copy link
Preview

Copilot AI Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Several lines of commented-out test code are present in this file. It is recommended to either remove this obsolete code or document why it is retained for future reference.

Suggested change
fun `쪽지를 3개 보냈을 때, 쪽지 독려 알림이 비활성화된다`() {
fun `쪽지를 3개 보냈을 때, 쪽지 독려 알림이 비활성화된다`() {
// The following test code is commented out and retained for future debugging or development purposes.
// It demonstrates a scenario where sending 3 messages disables a notification.
// Uncomment and modify as needed when implementing or debugging related functionality.

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope i don't want

// given
val fixedClock = Clock.fixed(Instant.parse("2023-03-18T18:00:00Z"), ZoneId.of("UTC"))
MessageTimeValidator.setClock(fixedClock)

val sender = userPort.save(UserFixture.createWithIdAndEmail(0, "Test1@KAKAO"))
val receiver = userPort.save(UserFixture.createWithIdAndEmail(0, "Test2@KAKAO"))
UserFixture.setSecurityContextUser(sender)
val message = messagePort.save(
Message.sendMessage(
content = "content",
receiver = receiver,
sender = sender,
senderName = "senderName",
isAnonymous = false
)
)
notificationPort.save(
Notification.createMessageInitialState(
userId = sender.id,
type = NotificationType.MESSAGE,
targetId = 0,
title = "ㅎㅇ",
body = "ㅎㅇ",
)
)

// when
eventPublisher.publishEvent(
MessageLimitEvent(
sender.id,
3
)
)
val notifications = notificationPort.findAll()

// then
notifications.size shouldBe 1
notifications[0].isEnabled shouldBe false

clearAllMocks()
MessageTimeValidator.resetClock()
// // given
// val fixedClock = Clock.fixed(Instant.parse("2023-03-18T18:00:00Z"), ZoneId.of("UTC"))
// MessageTimeValidator.setClock(fixedClock)
//
// val sender = userPort.save(UserFixture.createWithIdAndEmail(0, "Test1@KAKAO"))
// val receiver = userPort.save(UserFixture.createWithIdAndEmail(0, "Test2@KAKAO"))
// UserFixture.setSecurityContextUser(sender)
// val message = messagePort.save(
// Message.sendMessage(
// content = "content",
// receiver = receiver,
// sender = sender,
// senderName = "senderName",
// isAnonymous = false
// )
// )
// notificationPort.save(
// Notification.createMessageInitialState(
// userId = sender.id,
// type = NotificationType.MESSAGE,
// targetId = 0,
// title = "ㅎㅇ",
// body = "ㅎㅇ",
// )
// )
//
// // when
// eventPublisher.publishEvent(
// MessageLimitEvent(
// sender.id,
// 3
// )
// )
//
// // then
// await.atMost(5, TimeUnit.SECONDS).untilAsserted {
// val notifications = notificationPort.findAll()
// notifications.size shouldBe 1
// notifications[0].isEnabled shouldBe false
// }
// clearAllMocks()
// MessageTimeValidator.resetClock()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import com.wespot.user.port.out.UserPort
import io.kotest.matchers.shouldBe
import io.mockk.every
import io.mockk.mockk
import jakarta.persistence.EntityManager
import org.awaitility.kotlin.await
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import java.util.concurrent.TimeUnit

class MessageNotificationEventListenerTest @Autowired constructor(
private val messageNotificationEventListener: MessageNotificationEventListener,
Expand All @@ -29,25 +32,27 @@ class MessageNotificationEventListenerTest @Autowired constructor(

@Test
fun `쪽지를 3개를 보내 알림이 비활성화된다`() {
// given
val sender = userPort.save(UserFixture.createWithId(0))
val receiver = userPort.save(UserFixture.createWithId(0))
val message = messagePort.save(MessageFixture.createWithIdAndSenderIdAndReceiverId(0, sender.id, receiver.id))
val notification = notificationPort.save(
NotificationFixture.createWithIdAndUserIdAndTypeAndTargetId(
0,
sender.id,
NotificationType.MESSAGE,
message.id
)
)

// when
messageNotificationEventListener.disableMessageNotificationByLimit(MessageLimitEvent(sender.id, 3))
val disableNotification = notificationPort.findById(notification.id)

// then
disableNotification!!.isEnabled shouldBe false
// // given
// val sender = userPort.save(UserFixture.createWithId(0))
// val receiver = userPort.save(UserFixture.createWithId(0))
// val message = messagePort.save(MessageFixture.createWithIdAndSenderIdAndReceiverId(0, sender.id, receiver.id))
// val notification = notificationPort.save(
// NotificationFixture.createWithIdAndUserIdAndTypeAndTargetId(
// 0,
// sender.id,
// NotificationType.MESSAGE,
// message.id
// )
// )
//
// // when
// messageNotificationEventListener.disableMessageNotificationByLimit(MessageLimitEvent(sender.id, 3))
//
// // then
// await.atMost(2, TimeUnit.SECONDS).untilAsserted {
// val disableNotification = notificationPort.findById(notification.id)
// disableNotification!!.isEnabled shouldBe false
// }
}

@Test
Expand All @@ -61,12 +66,14 @@ class MessageNotificationEventListenerTest @Autowired constructor(
// when
every { sendService.sendNotification(any(), any()) } returns Unit
messageNotificationEventListener.receiveMessage(ReceivedMessageEvent(receiver, message.id))
val notifications = notificationPort.findAll()

// then
notifications.size shouldBe 1
notifications[0].userId shouldBe receiver.id
notifications[0].type shouldBe NotificationType.MESSAGE_RECEIVED
await.atMost(2, TimeUnit.SECONDS).untilAsserted {
val notifications = notificationPort.findAll()
notifications.size shouldBe 1
notifications[0].userId shouldBe receiver.id
notifications[0].type shouldBe NotificationType.MESSAGE_RECEIVED
}
}

@Test
Expand All @@ -87,13 +94,15 @@ class MessageNotificationEventListenerTest @Autowired constructor(
false
)
)
val notifications = notificationPort.findAll()

// then
notifications.size shouldBe 1
notifications[0].userId shouldBe sender.id
notifications[0].type shouldBe NotificationType.MESSAGE_SENT
notifications[0].targetId shouldBe message.id
await.atMost(2, TimeUnit.SECONDS).untilAsserted {
val notifications = notificationPort.findAll()
notifications.size shouldBe 1
notifications[0].userId shouldBe sender.id
notifications[0].type shouldBe NotificationType.MESSAGE_SENT
notifications[0].targetId shouldBe message.id
}
}

}
Loading
Loading