-
Notifications
You must be signed in to change notification settings - Fork 0
#134 - 바뀐 인텔리에 따라 스펙을 수정합니다. #166
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
app/src/main/kotlin/com/wespot/message/v2/MessageV2UsingStatusController.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.wespot.message.v2 | ||
|
||
import com.wespot.message.dto.response.MessageV2StatusResponse | ||
import com.wespot.message.port.`in`.MessageV2UsingStatusUseCase | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/api/v2/messages") | ||
class MessageV2UsingStatusController( | ||
private val messageV2UsingStatusUseCase: MessageV2UsingStatusUseCase, | ||
) { | ||
|
||
@GetMapping("/status") | ||
fun getMessageStatus(): ResponseEntity<MessageV2StatusResponse> { | ||
val response = messageV2UsingStatusUseCase.getMessageStatus() | ||
|
||
return ResponseEntity.ok(response) | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
core/src/main/kotlin/com/wespot/message/dto/response/MessageV2StatusResponse.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.wespot.message.dto.response | ||
|
||
import com.wespot.message.v2.MessageV2 | ||
|
||
data class MessageV2StatusResponse( | ||
val isSendAllowed: Boolean, | ||
val countRemainingMessages: Int, | ||
val countUnReadMessages: Int, | ||
val countUnReplayMessages: Int, | ||
) { | ||
|
||
companion object { | ||
|
||
fun of( | ||
isSendAllowed: Boolean, | ||
countRemainingMessages: Int, | ||
countUnReadMessages: Int, | ||
countUnReplayMessages: Int, | ||
): MessageV2StatusResponse { | ||
return MessageV2StatusResponse( | ||
isSendAllowed = isSendAllowed, | ||
countRemainingMessages = countRemainingMessages, | ||
countUnReadMessages = countUnReadMessages, | ||
countUnReplayMessages = countUnReplayMessages, | ||
) | ||
} | ||
|
||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
core/src/main/kotlin/com/wespot/message/port/in/MessageV2UsingStatusUseCase.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.wespot.message.port.`in` | ||
|
||
import com.wespot.message.dto.response.MessageV2StatusResponse | ||
|
||
interface MessageV2UsingStatusUseCase { | ||
|
||
fun getMessageStatus(): MessageV2StatusResponse | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
core/src/main/kotlin/com/wespot/message/service/v2/MessageV2UsingStatusService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.wespot.message.service.v2 | ||
|
||
import com.wespot.auth.service.SecurityUtils | ||
import com.wespot.message.dto.response.MessageV2StatusResponse | ||
import com.wespot.message.port.`in`.MessageV2UsingStatusUseCase | ||
import com.wespot.message.port.out.MessageV2Port | ||
import com.wespot.message.v2.MessageV2 | ||
import com.wespot.user.port.out.UserPort | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
import java.time.LocalDate | ||
|
||
@Service | ||
class MessageV2UsingStatusService( | ||
private val userPort: UserPort, | ||
private val messageV2Port: MessageV2Port, | ||
) : MessageV2UsingStatusUseCase { | ||
|
||
@Transactional(readOnly = true) | ||
override fun getMessageStatus(): MessageV2StatusResponse { | ||
val loginUser = SecurityUtils.getLoginUser(userPort = userPort) | ||
val today = LocalDate.now() | ||
val yesterday = today.minusDays(1) | ||
val messages = | ||
messageV2Port.findAllLastMessageOfRoomByReceiverIdAndFromDate( | ||
receiverId = loginUser.id, | ||
from = yesterday | ||
) | ||
val countTodaySentMessage = messageV2Port.countTodaySendMessages(senderId = loginUser.id) | ||
|
||
return MessageV2StatusResponse.of( | ||
isSendAllowed = MessageV2.COUNT_OF_MAX_ABLE_TO_SEND_MESSAGE_PER_DAY == countTodaySentMessage, | ||
countRemainingMessages = MessageV2.COUNT_OF_MAX_ABLE_TO_SEND_MESSAGE_PER_DAY - countTodaySentMessage, | ||
countUnReadMessages = messages.filter { !it.isRead(viewer = loginUser) }.size, | ||
countUnReplayMessages = messages.filter { it.isSentAtSameDate(date = today) }.size | ||
) | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for determining if sending is allowed appears reversed; consider allowing sending only when countTodaySentMessage is less than COUNT_OF_MAX_ABLE_TO_SEND_MESSAGE_PER_DAY.
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh thanks!!