From 2bf358d0b7cd5440883666e419837d7a04fe61d1 Mon Sep 17 00:00:00 2001 From: nuyh Date: Thu, 30 Nov 2023 00:24:19 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=ED=9C=B4=EB=8C=80=ED=8F=B0=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=EB=A1=9C=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20?= =?UTF-8?q?=EC=B0=BE=EA=B8=B0=20=EB=B0=B0=EC=97=B4=EB=A1=9C=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../busan/auth/dto/FindEmailResponse.java | 14 +++++++- .../busan/auth/service/AuthService.java | 8 ++--- .../busan/member/domain/MemberRepository.java | 3 +- src/main/resources/static/api/openapi3.yaml | 34 +++++++++++-------- .../busan/auth/AuthControllerTest.java | 6 ++-- .../busan/auth/AuthenticationServiceTest.java | 2 +- 6 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/example/busan/auth/dto/FindEmailResponse.java b/src/main/java/com/example/busan/auth/dto/FindEmailResponse.java index 88251e0..df7060d 100644 --- a/src/main/java/com/example/busan/auth/dto/FindEmailResponse.java +++ b/src/main/java/com/example/busan/auth/dto/FindEmailResponse.java @@ -1,4 +1,16 @@ package com.example.busan.auth.dto; -public record FindEmailResponse(String email) { +import com.example.busan.member.domain.Member; + +import java.util.List; + +public record FindEmailResponse(List emails) { + + public static FindEmailResponse from(final List members) { + final List emails = members.stream() + .map(Member::getEmail) + .toList(); + + return new FindEmailResponse(emails); + } } diff --git a/src/main/java/com/example/busan/auth/service/AuthService.java b/src/main/java/com/example/busan/auth/service/AuthService.java index 0f3134d..69a0492 100644 --- a/src/main/java/com/example/busan/auth/service/AuthService.java +++ b/src/main/java/com/example/busan/auth/service/AuthService.java @@ -9,6 +9,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Transactional(readOnly = true) @Service public class AuthService { @@ -31,9 +33,7 @@ public Authentication login(final LoginRequest request) { } public FindEmailResponse findEmailByPhone(final String phone) { - final Member member = memberRepository.findByPhone(phone) - .orElseThrow(() -> new IllegalArgumentException("가입된 유저가 아닙니다.")); - - return new FindEmailResponse(member.getEmail()); + final List members = memberRepository.findByPhone(phone); + return FindEmailResponse.from(members); } } diff --git a/src/main/java/com/example/busan/member/domain/MemberRepository.java b/src/main/java/com/example/busan/member/domain/MemberRepository.java index 873c8fc..4303c02 100644 --- a/src/main/java/com/example/busan/member/domain/MemberRepository.java +++ b/src/main/java/com/example/busan/member/domain/MemberRepository.java @@ -2,11 +2,12 @@ import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.Optional; public interface MemberRepository extends JpaRepository { - Optional findByPhone(String phone); + List findByPhone(String phone); Optional findByEmailAndPhone(String email, String phone); } diff --git a/src/main/resources/static/api/openapi3.yaml b/src/main/resources/static/api/openapi3.yaml index f803f98..96b0b74 100644 --- a/src/main/resources/static/api/openapi3.yaml +++ b/src/main/resources/static/api/openapi3.yaml @@ -80,10 +80,10 @@ paths: content: application/json: schema: - $ref: '#/components/schemas/auth-email-1599798553' + $ref: '#/components/schemas/auth-email802416584' examples: 휴대폰 번호로 이메일 찾기: - value: "{\"email\":\"test@gmail.com\"}" + value: "{\"emails\":[\"test@gmail.com\"]}" /auth/login: post: tags: @@ -154,7 +154,7 @@ paths: 현재 유저 정보 조회하기: value: "{\"name\":\"연어\",\"phone\":\"01012341234\",\"email\":\"\ test@naver.com\",\"role\":\"USER\",\"company\":\"우형\",\"region\"\ - :\"BUSAN\",\"createdAt\":\"2023-11-30T00:09:16.804123\"}" + :\"BUSAN\",\"createdAt\":\"2023-11-30T00:23:50.435321\"}" post: tags: - members @@ -281,13 +281,13 @@ paths: examples: 자신의 회의실 예약 목록 최신 순으로 보기: value: "[{\"id\":1,\"status\":\"RESERVED\",\"cancelReason\":null,\"\ - startTime\":\"2023-11-30T00:09:18.518235\",\"endTime\":\"2023-11-30T02:09:18.518239\"\ + startTime\":\"2023-11-30T00:23:52.419309\",\"endTime\":\"2023-11-30T02:23:52.419313\"\ ,\"name\":\"황재현\",\"phone\":\"01012341234\",\"reservedAt\":\"\ - 2023-11-30T00:09:18.518249\",\"roomId\":1,\"roomName\":\"대회의실\"\ + 2023-11-30T00:23:52.419324\",\"roomId\":1,\"roomName\":\"대회의실\"\ },{\"id\":2,\"status\":\"CANCELED\",\"cancelReason\":\"쓰기 싫어졌어\ - 요..\",\"startTime\":\"2023-11-30T00:09:18.518257\",\"endTime\"\ - :\"2023-11-30T02:09:18.518259\",\"name\":\"황재현\",\"phone\":\"\ - 01012341234\",\"reservedAt\":\"2023-11-30T00:09:18.518263\",\"\ + 요..\",\"startTime\":\"2023-11-30T00:23:52.419331\",\"endTime\"\ + :\"2023-11-30T02:23:52.419333\",\"name\":\"황재현\",\"phone\":\"\ + 01012341234\",\"reservedAt\":\"2023-11-30T00:23:52.419335\",\"\ roomId\":1,\"roomName\":\"대회의실\"}]" post: tags: @@ -404,12 +404,6 @@ components: roomId: type: number description: 예약할 회의실 ID - auth-email-1599798553: - type: object - properties: - email: - type: string - description: 해당 번호의 이메일 auth-phone2135928301: type: object properties: @@ -535,6 +529,18 @@ components: email: type: string description: 이메일 + auth-email802416584: + type: object + properties: + emails: + type: array + description: 해당 번호로된 이메일 리스트 + items: + oneOf: + - type: object + - type: boolean + - type: string + - type: number reservations-reservationId-361069914: type: object properties: diff --git a/src/test/java/com/example/busan/auth/AuthControllerTest.java b/src/test/java/com/example/busan/auth/AuthControllerTest.java index f123df7..65c02ef 100644 --- a/src/test/java/com/example/busan/auth/AuthControllerTest.java +++ b/src/test/java/com/example/busan/auth/AuthControllerTest.java @@ -16,6 +16,8 @@ import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpSession; +import java.util.List; + import static com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper.document; import static com.example.busan.auth.AuthController.AUTHORIZATION; import static org.assertj.core.api.Assertions.assertThat; @@ -132,7 +134,7 @@ void authenticatePhone2() throws Exception { void findEmailByPhone() throws Exception { //given given(authService.findEmailByPhone(any())) - .willReturn(new FindEmailResponse("test@gmail.com")); + .willReturn(new FindEmailResponse(List.of("test@gmail.com"))); //when final MockHttpServletResponse response = mockMvc.perform( @@ -141,7 +143,7 @@ void findEmailByPhone() throws Exception { .andDo(print()) .andDo(document("휴대폰 번호로 이메일 찾기", queryParameters(parameterWithName("phone").description("인증 완료된 휴대폰 번호")), - responseFields(fieldWithPath("email").description("해당 번호의 이메일")))) + responseFields(fieldWithPath("emails").description("해당 번호로된 이메일 리스트")))) .andReturn() .getResponse(); diff --git a/src/test/java/com/example/busan/auth/AuthenticationServiceTest.java b/src/test/java/com/example/busan/auth/AuthenticationServiceTest.java index ba3e944..919664f 100644 --- a/src/test/java/com/example/busan/auth/AuthenticationServiceTest.java +++ b/src/test/java/com/example/busan/auth/AuthenticationServiceTest.java @@ -73,7 +73,7 @@ void findEmailByPhone() { final FindEmailResponse response = authService.findEmailByPhone(request.phone()); //then - assertThat(response.email()).isEqualTo(member.getEmail()); + assertThat(response.emails()).contains(member.getEmail()); } private Member createMember() {