Skip to content

Commit

Permalink
refactor: 휴대폰 번호로 이메일 찾기 배열로 응답
Browse files Browse the repository at this point in the history
  • Loading branch information
nuyh99 committed Nov 29, 2023
1 parent 017a1db commit 2bf358d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 23 deletions.
14 changes: 13 additions & 1 deletion src/main/java/com/example/busan/auth/dto/FindEmailResponse.java
Original file line number Diff line number Diff line change
@@ -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<String> emails) {

public static FindEmailResponse from(final List<Member> members) {
final List<String> emails = members.stream()
.map(Member::getEmail)
.toList();

return new FindEmailResponse(emails);
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/example/busan/auth/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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<Member> members = memberRepository.findByPhone(phone);
return FindEmailResponse.from(members);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface MemberRepository extends JpaRepository<Member, String> {

Optional<Member> findByPhone(String phone);
List<Member> findByPhone(String phone);

Optional<Member> findByEmailAndPhone(String email, String phone);
}
34 changes: 20 additions & 14 deletions src/main/resources/static/api/openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,10 @@ paths:
content:
application/json:
schema:
$ref: '#/components/schemas/auth-email-1599798553'
$ref: '#/components/schemas/auth-email802416584'
examples:
휴대폰 번호로 이메일 찾기:
value: "{\"email\":\"[email protected]\"}"
value: "{\"emails\":[\"[email protected]\"]}"
/auth/login:
post:
tags:
Expand Down Expand Up @@ -154,7 +154,7 @@ paths:
현재 유저 정보 조회하기:
value: "{\"name\":\"연어\",\"phone\":\"01012341234\",\"email\":\"\
[email protected]\",\"role\":\"USER\",\"company\":\"우형\",\"region\"\
:\"BUSAN\",\"createdAt\":\"2023-11-30T00:09:16.804123\"}"
:\"BUSAN\",\"createdAt\":\"2023-11-30T00:23:50.435321\"}"
post:
tags:
- members
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/com/example/busan/auth/AuthControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -132,7 +134,7 @@ void authenticatePhone2() throws Exception {
void findEmailByPhone() throws Exception {
//given
given(authService.findEmailByPhone(any()))
.willReturn(new FindEmailResponse("[email protected]"));
.willReturn(new FindEmailResponse(List.of("[email protected]")));

//when
final MockHttpServletResponse response = mockMvc.perform(
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 2bf358d

Please sign in to comment.