-
Notifications
You must be signed in to change notification settings - Fork 0
#135 - 익명 프로필 조회 기능을 구현합니다. #152
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 all commits
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
26 changes: 26 additions & 0 deletions
26
app/src/main/kotlin/com/wespot/message/v2/GetAnonymousProfileController.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,26 @@ | ||
package com.wespot.message.v2 | ||
|
||
import com.wespot.message.dto.response.AnonymousProfileResponse | ||
import com.wespot.message.port.`in`.GetAnonymousProfileUseCase | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.PathVariable | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/messages") | ||
class GetAnonymousProfileController( | ||
private val getAnonymousProfileUseCase: GetAnonymousProfileUseCase, | ||
) { | ||
|
||
@GetMapping("/receiver/{receiverId}/profiles") | ||
fun getAnonymousProfileByReceiverId( | ||
@PathVariable receiverId: Long | ||
): ResponseEntity<List<AnonymousProfileResponse>> { | ||
val response = getAnonymousProfileUseCase.getAnonymousProfileByReceiverId(receiverId) | ||
|
||
return ResponseEntity.ok() | ||
.body(response) | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
core/src/main/kotlin/com/wespot/message/dto/response/AnonymousProfileResponse.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,32 @@ | ||
package com.wespot.message.dto.response | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat | ||
import com.wespot.message.v2.UserProfile | ||
import java.time.LocalDateTime | ||
|
||
data class AnonymousProfileResponse( | ||
val id: Long, | ||
val image: String, | ||
val name: String, | ||
val isAnonymous: Boolean, | ||
@JsonFormat(pattern = "yyyy.MM.dd HH:mm:ss") | ||
val recentlyTalk: LocalDateTime?, | ||
val myTurnToAnswer: Boolean | ||
) { | ||
|
||
companion object { | ||
fun from( | ||
userProfile: UserProfile | ||
): AnonymousProfileResponse { | ||
return AnonymousProfileResponse( | ||
id = userProfile.profileId, | ||
image = userProfile.image, | ||
name = userProfile.name, | ||
isAnonymous = userProfile.isAnonymous, | ||
recentlyTalk = userProfile.recentlyTalk(), | ||
myTurnToAnswer = userProfile.isAbleToAnswer() | ||
) | ||
} | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
core/src/main/kotlin/com/wespot/message/port/in/GetAnonymousProfileUseCase.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.AnonymousProfileResponse | ||
|
||
interface GetAnonymousProfileUseCase { | ||
|
||
fun getAnonymousProfileByReceiverId(receiverId: Long): List<AnonymousProfileResponse> | ||
|
||
} |
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
36 changes: 36 additions & 0 deletions
36
core/src/main/kotlin/com/wespot/message/service/v2/GetAnonymousProfileService.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,36 @@ | ||
package com.wespot.message.service.v2 | ||
|
||
import com.wespot.auth.service.SecurityUtils | ||
import com.wespot.message.dto.response.AnonymousProfileResponse | ||
import com.wespot.message.port.`in`.GetAnonymousProfileUseCase | ||
import com.wespot.message.port.out.MessageV2Port | ||
import com.wespot.message.v2.MessageRooms | ||
import com.wespot.message.v2.UserProfiles | ||
import com.wespot.user.port.out.UserPort | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class GetAnonymousProfileService( | ||
private val userPort: UserPort, | ||
private val messagePort: MessageV2Port, | ||
) : GetAnonymousProfileUseCase { | ||
|
||
@Transactional(readOnly = true) | ||
override fun getAnonymousProfileByReceiverId(receiverId: Long): List<AnonymousProfileResponse> { | ||
val sender = SecurityUtils.getLoginUser(userPort = userPort) | ||
val messageRooms = | ||
messagePort.findAllMessageRoomBySenderIdAndReceiverId(senderId = sender.id, receiverId = receiverId) | ||
val messageRoomIds = messageRooms.map { it.id } | ||
val messageDetails = messagePort.findAllLastMessageOfRoomByRoomIdIn(messageRoomIds) | ||
|
||
val rooms = | ||
MessageRooms.createOverview(user = sender, rooms = messageRooms, messageDetails = messageDetails) | ||
|
||
return UserProfiles.of(messageRooms = rooms) | ||
.asList() | ||
.map { AnonymousProfileResponse.from(it) } | ||
} | ||
|
||
} | ||
|
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
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
63 changes: 63 additions & 0 deletions
63
domain/src/main/kotlin/com/wespot/message/v2/UserProfile.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,63 @@ | ||||||
package com.wespot.message.v2 | ||||||
|
||||||
import com.wespot.user.User | ||||||
import com.wespot.user.message.AnonymousProfile | ||||||
import java.time.LocalDateTime | ||||||
|
||||||
data class UserProfile( | ||||||
val profileId: Long, | ||||||
val image: String, | ||||||
val name: String, | ||||||
val isAnonymous: Boolean, | ||||||
val messageRoom: MessageRoom? | ||||||
) { | ||||||
|
||||||
companion object { | ||||||
|
||||||
private val EMPTY_MESSAGE_ROOM = null | ||||||
|
||||||
fun createByAnonymousProfile( | ||||||
anonymousProfile: AnonymousProfile, | ||||||
messageRoom: List<MessageRoom> | ||||||
): UserProfile { | ||||||
return UserProfile( | ||||||
profileId = anonymousProfile.id, | ||||||
image = anonymousProfile.imageUrl, | ||||||
name = anonymousProfile.name, | ||||||
isAnonymous = true, | ||||||
messageRoom = messageRoom.find { it.isSameAnonymousProfile(anonymousProfile.id) } | ||||||
) | ||||||
} | ||||||
|
||||||
fun createByUserProfile( | ||||||
user: User, | ||||||
messageRoom: List<MessageRoom> | ||||||
): UserProfile { | ||||||
return UserProfile( | ||||||
profileId = user.profile.id, | ||||||
image = user.profile.iconUrl, | ||||||
name = user.name, | ||||||
isAnonymous = false, | ||||||
messageRoom = messageRoom.find { it.isSameUserProfileAndNotAnonymous(viewer = user) } | ||||||
) | ||||||
} | ||||||
|
||||||
} | ||||||
|
||||||
fun recentlyTalk(): LocalDateTime? { | ||||||
if (messageRoom == EMPTY_MESSAGE_ROOM) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Using an EMPTY_MESSAGE_ROOM constant set to null adds an extra layer of indirection; consider checking messageRoom directly for null to improve clarity.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
return null | ||||||
} | ||||||
|
||||||
return messageRoom.latestChatTime() | ||||||
} | ||||||
|
||||||
fun isAbleToAnswer(): Boolean { | ||||||
if (messageRoom == EMPTY_MESSAGE_ROOM) { | ||||||
return false | ||||||
} | ||||||
|
||||||
return messageRoom.isAbleToAnswer() | ||||||
} | ||||||
|
||||||
} |
50 changes: 50 additions & 0 deletions
50
domain/src/main/kotlin/com/wespot/message/v2/UserProfiles.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,50 @@ | ||
package com.wespot.message.v2 | ||
|
||
import com.wespot.exception.CustomException | ||
import com.wespot.exception.ExceptionView | ||
import org.springframework.http.HttpStatus | ||
|
||
data class UserProfiles( | ||
val userProfiles: List<UserProfile> | ||
) { | ||
|
||
companion object { | ||
|
||
fun of(messageRooms: MessageRooms): UserProfiles { | ||
val isContainsOwnerIsNotViewer = messageRooms.asList() | ||
.any { !it.isViewerOwnerOfMessageRoom() } | ||
if (isContainsOwnerIsNotViewer) { | ||
throw CustomException( | ||
message = "익명 프로필을 조회한자가 소유한 쪽지방이 아닌 쪽지를 가져왔습니다.", | ||
status = HttpStatus.BAD_REQUEST, | ||
view = ExceptionView.TOAST, | ||
) | ||
} | ||
|
||
val anonymousProfiles = messageRooms.asList() | ||
.filter { it.isAnonymous() } | ||
.map { it.anonymousProfile()!! } | ||
|
||
val resultOfUserProfiles = anonymousProfiles.map { anonymousProfile -> | ||
UserProfile.createByAnonymousProfile( | ||
anonymousProfile = anonymousProfile, | ||
messageRoom = messageRooms.asList() | ||
) | ||
} + UserProfile.createByUserProfile( | ||
user = messageRooms.viewer(), | ||
messageRoom = messageRooms.asList() | ||
) | ||
|
||
return UserProfiles( | ||
userProfiles = resultOfUserProfiles.sortedBy { it.recentlyTalk() } | ||
.reversed() | ||
) | ||
} | ||
|
||
} | ||
|
||
fun asList(): List<UserProfile> { | ||
return userProfiles | ||
} | ||
|
||
} |
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
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 method isAbleToAnswer appears to be a function and should be invoked (e.g., it.isAbleToAnswer()) rather than referenced as a property.
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.
nope i don't want