Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
@@ -0,0 +1,19 @@
package gomushin.backend.couple.dto.response

import gomushin.backend.member.domain.entity.Member
import io.swagger.v3.oas.annotations.media.Schema
import java.time.LocalDate

data class CoupleBirthDayResponse (
@Schema(description = "커플 생년월일", example = "2001-04-01")
val partnerBirthday : LocalDate?,
@Schema(description = "내 생년월일", example = "2001-03-01")
val myBirthDay : LocalDate?
) {
companion object {
fun of(coupleMember : Member, myMember : Member) = CoupleBirthDayResponse(
coupleMember.birthDate,
myMember.birthDate
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,10 @@ class CoupleFacade(
throw BadRequestException("sarangggun.couple.already-init")
}
}

fun getCoupleBirthDay(customUserDetails: CustomUserDetails): CoupleBirthDayResponse {
val couple = coupleInfoService.findCoupleMember(customUserDetails.getId())
val member = memberService.getById(customUserDetails.getId())
return CoupleBirthDayResponse.of(couple, member)
}
Comment on lines +134 to +138
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

커플 연결 여부에 대한 예외 처리가 필요합니다.

현재 구현에서는 사용자가 커플로 연결되어 있지 않은 경우에 대한 예외 처리가 누락되어 있습니다. getInfo() 메서드(24-33줄)와 같이 checkIsCouple()을 통해 사용자가 커플로 연결되어 있는지 확인하는 로직을 추가해야 합니다.

fun getCoupleBirthDay(customUserDetails: CustomUserDetails): CoupleBirthDayResponse {
+    val member = memberService.getById(customUserDetails.getId())
+
+    if (!member.checkIsCouple()) {
+        throw BadRequestException("saranggun.couple.not-connected")
+    }
+
    val couple = coupleInfoService.findCoupleMember(customUserDetails.getId())
-    val member = memberService.getById(customUserDetails.getId())
    return CoupleBirthDayResponse.of(couple, member)
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fun getCoupleBirthDay(customUserDetails: CustomUserDetails): CoupleBirthDayResponse {
val couple = coupleInfoService.findCoupleMember(customUserDetails.getId())
val member = memberService.getById(customUserDetails.getId())
return CoupleBirthDayResponse.of(couple, member)
}
fun getCoupleBirthDay(customUserDetails: CustomUserDetails): CoupleBirthDayResponse {
val member = memberService.getById(customUserDetails.getId())
if (!member.checkIsCouple()) {
throw BadRequestException("saranggun.couple.not-connected")
}
val couple = coupleInfoService.findCoupleMember(customUserDetails.getId())
return CoupleBirthDayResponse.of(couple, member)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ object ApiPath {
const val ANNIVERSARY_GENERATE = "/v1/couple/new-anniversary"
const val ANNIVERSARY_MAIN = "/v1/anniversary/main"
const val ANNIVERSARIES = "/v1/anniversaries"
const val COUPLE_BIRTHDAY = "/v1/couple/birthday"
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,14 @@ class CoupleInfoController (
):ApiResponse<CoupleEmotionResponse>{
return ApiResponse.success(coupleFacade.getCoupleEmotion(customUserDetails))
}

@ResponseStatus(HttpStatus.OK)
@GetMapping(ApiPath.COUPLE_BIRTHDAY)
@Operation(summary = "커플 생년월일 조회 api", description = "getCoupleBirthDay")
fun getCoupleBirthDay(
@AuthenticationPrincipal customUserDetails: CustomUserDetails
) :ApiResponse<CoupleBirthDayResponse>{
val coupleBirthDay = coupleFacade.getCoupleBirthDay(customUserDetails)
return ApiResponse.success(coupleBirthDay)
}
}
18 changes: 16 additions & 2 deletions src/test/kotlin/gomushin/backend/couple/facade/CoupleFacadeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class CoupleFacadeTest {
name = "곰신",
nickname = "곰신닉네임",
email = "[email protected]",
birthDate = null,
birthDate = LocalDate.of(2001, 3, 1),
profileImageUrl = null,
provider = Provider.KAKAO,
role = Role.MEMBER,
Expand All @@ -73,7 +73,7 @@ class CoupleFacadeTest {
name = "꽃신",
nickname = "꽃신닉네임",
email = "[email protected]",
birthDate = null,
birthDate = LocalDate.of(2001, 4, 1),
profileImageUrl = null,
provider = Provider.KAKAO,
role = Role.MEMBER,
Expand Down Expand Up @@ -206,4 +206,18 @@ class CoupleFacadeTest {
//then
verify(anniversaryService).generateAnniversary(couple, generateAnniversaryRequest)
}

@DisplayName("생년월일 조회 - 정상응답")
@Test
fun getCoupleBirthDay() {
//given
`when`(memberService.getById(customUserDetails.getId())).thenReturn(member1)
`when`(coupleInfoService.findCoupleMember(customUserDetails.getId())).thenReturn(member2)
//when
val result = coupleFacade.getCoupleBirthDay(customUserDetails)
//then
verify(coupleInfoService).findCoupleMember(customUserDetails.getId())
assertEquals(result.myBirthDay, member1.birthDate)
assertEquals(result.partnerBirthday, member2.birthDate)
}
}