Skip to content

Commit

Permalink
feat: 친구 스페이스 친구가 받은 픽 API 추가, 기존 마이스페이스 - 내가 받은 픽 기능 재사용
Browse files Browse the repository at this point in the history
  • Loading branch information
toychip committed Aug 21, 2024
1 parent 5832305 commit 1df17f1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 13 deletions.
63 changes: 59 additions & 4 deletions api/src/main/kotlin/com/mashup/dojo/MemberController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import com.mashup.dojo.service.MemberService
import com.mashup.dojo.usecase.MemberUseCase
import io.github.oshai.kotlinlogging.KotlinLogging
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.media.ArraySchema
import io.swagger.v3.oas.annotations.media.Content
import io.swagger.v3.oas.annotations.media.ExampleObject
import io.swagger.v3.oas.annotations.media.Schema
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.web.bind.annotation.GetMapping
Expand Down Expand Up @@ -231,12 +233,12 @@ class MemberController(
)
]
)
fun myPick(): DojoApiResponse<MySpacePickResponse> {
fun mySpace(): DojoApiResponse<MySpacePickResponse> {
val memberId = MemberPrincipalContextHolder.current().id
val receivedMySpacePicks = memberUseCase.receivedMySpacePicks(memberId)
val response =
receivedMySpacePicks.map {
MySpacePickDetail(
SpacePickDetail(
pickId = it.pickId.value,
rank = it.rank,
pickContent = it.pickContent,
Expand All @@ -250,6 +252,48 @@ class MemberController(
)
}

@GetMapping("/member/friend-space/{friendId}/pick")
@Operation(
summary = "친구 스페이스 친구가 받은 픽 API",
description = "친구 스페이스 탭 중 친구가 받은 픽의 대한 API입니다. 공동 등수를 자동으로 계산하고 반환합니다. Pick이 많은 순서대로 등수를 나누고, 최신순, 내림차순으로 정렬합니다.",
responses = [
ApiResponse(
responseCode = "200",
description = "친구스페이스 - 친구가 받은 픽 Response",
content = [
Content(
mediaType = "application/json",
examples = [
ExampleObject(
name = "Example Response",
value = EXAMPLE_VALUE
)
]
)
]
)
]
)
fun friendSpace(
@PathVariable friendId: String,
): DojoApiResponse<FriendSpacePickResponse> {
val receivedMySpacePicks = memberUseCase.receivedFriendSpacePicks(MemberId(friendId))
val response =
receivedMySpacePicks.map {
SpacePickDetail(
pickId = it.pickId.value,
rank = it.rank,
pickContent = it.pickContent,
pickCount = it.pickCount,
createdAt = it.createdAt
)
}

return DojoApiResponse.success(
FriendSpacePickResponse(response)
)
}

@GetMapping("/member/search")
@Operation(
summary = "멤버 검색 API",
Expand Down Expand Up @@ -287,16 +331,27 @@ class MemberController(
val authToken: String,
)

data class MySpacePickDetail(
data class SpacePickDetail(
@Schema(description = "픽의 고유 ID", example = "pickId1")
val pickId: String,
@Schema(description = "픽의 순위", example = "1")
val rank: Int,
@Schema(description = "픽의 내용", example = "대충 작업해도 퀄리티 잘 내오는 사람은?")
val pickContent: String,
@Schema(description = "픽의 투표 수", example = "999")
val pickCount: Int,
@Schema(description = "픽이 생성된 날짜", example = "2024-08-12T17:18:52.132Z")
val createdAt: LocalDateTime,
)

data class MySpacePickResponse(
val mySpaceResponses: List<MySpacePickDetail>,
@ArraySchema(arraySchema = Schema(description = "MySpace 내가 받은 픽 목록"))
val mySpaceResponses: List<SpacePickDetail>,
)

data class FriendSpacePickResponse(
@ArraySchema(arraySchema = Schema(description = "FriendSpace 친구가 받은 픽 목록"))
val friendSpaceResponses: List<SpacePickDetail>,
)

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ interface PickService {

fun getNextPickTime(): LocalDateTime

fun getReceivedMySpacePicks(memberId: MemberId): List<MySpacePickDetail>
fun getReceivedSpacePicks(memberId: MemberId): List<SpacePickDetail>

data class GetPickPaging(
val picks: List<GetReceivedPick>,
Expand Down Expand Up @@ -112,7 +112,7 @@ interface PickService {
val latestPickedAt: LocalDateTime,
)

data class MySpacePickDetail(
data class SpacePickDetail(
val pickId: PickId,
val rank: Int = -1,
val pickContent: String,
Expand Down Expand Up @@ -385,10 +385,10 @@ class DefaultPickService(
return nextPickTime ?: today.plusDays(1).atTime(pickTimes.first())
}

override fun getReceivedMySpacePicks(memberId: MemberId): List<PickService.MySpacePickDetail> {
override fun getReceivedSpacePicks(memberId: MemberId): List<PickService.SpacePickDetail> {
return pickRepository.findTopRankPicksByMemberId(memberId = memberId.value, rank = defaultRankSize).map { pick ->
val pickCount = pickRepository.findPickDetailCount(memberId = memberId.value, questionId = pick.questionId)
PickService.MySpacePickDetail(
PickService.SpacePickDetail(
pickId = PickId(pick.pickId),
pickCount = pickCount.toInt(),
pickContent = pick.questionContent,
Expand Down Expand Up @@ -452,14 +452,14 @@ private fun PickEntity.toPick(): Pick {
)
}

fun List<PickService.MySpacePickDetail>.calculateRanks(): List<PickService.MySpacePickDetail> {
fun List<PickService.SpacePickDetail>.calculateRanks(): List<PickService.SpacePickDetail> {
if (this.isEmpty()) return this

// 첫 번째 조건: pickCount 내림차순 정렬
// 두 번째 조건: createdAt 내림차순 정렬
val sortedPicks =
this.sortedWith(
compareByDescending<PickService.MySpacePickDetail> { it.pickCount }
compareByDescending<PickService.SpacePickDetail> { it.pickCount }
.thenByDescending { it.createdAt }
)

Expand Down
12 changes: 9 additions & 3 deletions service/src/main/kotlin/com/mashup/dojo/usecase/MemberUseCase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ interface MemberUseCase {

fun updateFriendRelation(command: UpdateFriendCommand): MemberRelationId

fun receivedMySpacePicks(currentMemberId: MemberId): List<PickService.MySpacePickDetail>
fun receivedMySpacePicks(currentMemberId: MemberId): List<PickService.SpacePickDetail>

fun searchMember(
memberId: MemberId,
keyword: String,
): List<MemberSearchInfo>

fun receivedFriendSpacePicks(currentMemberId: MemberId): List<PickService.SpacePickDetail>
}

@Component
Expand Down Expand Up @@ -209,9 +211,13 @@ class DefaultMemberUseCase(
}
}

override fun receivedMySpacePicks(currentMemberId: MemberId): List<PickService.MySpacePickDetail> {
val mySpacePicks = pickService.getReceivedMySpacePicks(currentMemberId)
override fun receivedMySpacePicks(currentMemberId: MemberId): List<PickService.SpacePickDetail> {
val mySpacePicks = pickService.getReceivedSpacePicks(currentMemberId)
return mySpacePicks.calculateRanks()
}

override fun receivedFriendSpacePicks(currentMemberId: MemberId): List<PickService.SpacePickDetail> {
val mySpacePicks = pickService.getReceivedSpacePicks(currentMemberId)
return mySpacePicks.calculateRanks()
}
}

0 comments on commit 1df17f1

Please sign in to comment.