From 017a1dbebc4bb1960467d1bfe68e6d6563188030 Mon Sep 17 00:00:00 2001 From: nuyh Date: Thu, 30 Nov 2023 00:11:09 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=9A=8C=EC=9B=90=20=EC=A7=80=EC=97=AD?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/busan/member/MemberService.java | 5 +- .../example/busan/member/domain/Member.java | 28 ++++------- .../member/dto/UpdateProfileRequest.java | 4 +- src/main/resources/static/api/openapi3.yaml | 46 ++++++++++--------- .../busan/member/MemberControllerTest.java | 8 ++-- .../busan/member/MemberServiceTest.java | 6 +-- 6 files changed, 43 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/example/busan/member/MemberService.java b/src/main/java/com/example/busan/member/MemberService.java index aad0537..5d26d46 100644 --- a/src/main/java/com/example/busan/member/MemberService.java +++ b/src/main/java/com/example/busan/member/MemberService.java @@ -51,10 +51,7 @@ public EmailDuplicateResponse isDuplicated(final String email) { @Transactional public void updateProfile(final String email, final UpdateProfileRequest request) { final Member member = findOrThrow(email); - - final Member updated = member.updateProfile(request.email(), request.company(), request.name()); - memberRepository.save(updated); - memberRepository.delete(member); + member.updateProfile(request.company(), request.name(), request.region()); } private Member findOrThrow(final String email) { diff --git a/src/main/java/com/example/busan/member/domain/Member.java b/src/main/java/com/example/busan/member/domain/Member.java index a1a88aa..dc65f7d 100644 --- a/src/main/java/com/example/busan/member/domain/Member.java +++ b/src/main/java/com/example/busan/member/domain/Member.java @@ -49,22 +49,6 @@ public class Member { protected Member() { } - private Member(final String email, - final String name, - final String password, - final Region region, - final String company, - final String phone, - final Role role) { - this.email = email; - this.name = name; - this.password = password; - this.region = region; - this.company = company; - this.phone = phone; - this.role = role; - } - public Member(final String email, final String name, final String password, @@ -93,6 +77,10 @@ private void validate(final String email, validateCompany(company); validatePassword(password); validatePhone(phone); + validateRegion(region); + } + + private void validateRegion(final Region region) { Assert.notNull(region, "지역이 필요합니다."); } @@ -129,11 +117,13 @@ public void checkPassword(final String password, final PasswordEncoder passwordE passwordEncoder.validateEquals(password, this.password); } - public Member updateProfile(final String email, final String company, final String name) { - validateEmail(email); + public void updateProfile(final String company, final String name, final Region region) { validateCompany(company); validateName(name); - return new Member(email, name, password, region, company, phone, role); + validateRegion(region); + this.company = company; + this.name = name; + this.region = region; } public void updatePhone(final String phone) { diff --git a/src/main/java/com/example/busan/member/dto/UpdateProfileRequest.java b/src/main/java/com/example/busan/member/dto/UpdateProfileRequest.java index 5395c4b..6ec16aa 100644 --- a/src/main/java/com/example/busan/member/dto/UpdateProfileRequest.java +++ b/src/main/java/com/example/busan/member/dto/UpdateProfileRequest.java @@ -1,4 +1,6 @@ package com.example.busan.member.dto; -public record UpdateProfileRequest(String name, String company, String email) { +import com.example.busan.member.domain.Region; + +public record UpdateProfileRequest(String name, String company, Region region) { } diff --git a/src/main/resources/static/api/openapi3.yaml b/src/main/resources/static/api/openapi3.yaml index dc007eb..f803f98 100644 --- a/src/main/resources/static/api/openapi3.yaml +++ b/src/main/resources/static/api/openapi3.yaml @@ -154,7 +154,7 @@ paths: 현재 유저 정보 조회하기: value: "{\"name\":\"연어\",\"phone\":\"01012341234\",\"email\":\"\ test@naver.com\",\"role\":\"USER\",\"company\":\"우형\",\"region\"\ - :\"BUSAN\",\"createdAt\":\"2023-11-29T02:23:02.327603\"}" + :\"BUSAN\",\"createdAt\":\"2023-11-30T00:09:16.804123\"}" post: tags: - members @@ -216,16 +216,18 @@ paths: put: tags: - members - operationId: "회원 정보 수정하기 - 이름, 회사명, 이메일" + operationId: "회원 정보 수정하기 - 이름, 회사명" requestBody: content: application/json: schema: - $ref: '#/components/schemas/members-profile273689223' + $ref: '#/components/schemas/members-profile-1939820512' examples: - 회원 정보 수정하기 - 이름, 회사명, 이메일: - value: "{\"name\":\"name\",\"company\":\"company\",\"email\":\"test@naver.com\"\ + 회원 정보 수정하기 - 이름, 회사명: + value: "{\"name\":\"name\",\"company\":\"company\",\"region\":\"BUSAN\"\ }" + 회원 정보 수정하기 - 이름, 회사명, 이메일: + value: "{\"name\":\"name\",\"company\":\"company\"}" responses: "204": description: "204" @@ -279,13 +281,13 @@ paths: examples: 자신의 회의실 예약 목록 최신 순으로 보기: value: "[{\"id\":1,\"status\":\"RESERVED\",\"cancelReason\":null,\"\ - startTime\":\"2023-11-29T02:23:03.983094\",\"endTime\":\"2023-11-29T04:23:03.983099\"\ + startTime\":\"2023-11-30T00:09:18.518235\",\"endTime\":\"2023-11-30T02:09:18.518239\"\ ,\"name\":\"황재현\",\"phone\":\"01012341234\",\"reservedAt\":\"\ - 2023-11-29T02:23:03.98311\",\"roomId\":1,\"roomName\":\"대회의실\"\ + 2023-11-30T00:09:18.518249\",\"roomId\":1,\"roomName\":\"대회의실\"\ },{\"id\":2,\"status\":\"CANCELED\",\"cancelReason\":\"쓰기 싫어졌어\ - 요..\",\"startTime\":\"2023-11-29T02:23:03.98312\",\"endTime\"\ - :\"2023-11-29T04:23:03.983122\",\"name\":\"황재현\",\"phone\":\"\ - 01012341234\",\"reservedAt\":\"2023-11-29T02:23:03.983124\",\"\ + 요..\",\"startTime\":\"2023-11-30T00:09:18.518257\",\"endTime\"\ + :\"2023-11-30T02:09:18.518259\",\"name\":\"황재현\",\"phone\":\"\ + 01012341234\",\"reservedAt\":\"2023-11-30T00:09:18.518263\",\"\ roomId\":1,\"roomName\":\"대회의실\"}]" post: tags: @@ -378,6 +380,18 @@ paths: }]}]" components: schemas: + members-profile-1939820512: + type: object + properties: + name: + type: string + description: 이름 + company: + type: string + description: 회사명 + region: + type: string + description: 지역 reservations-740649445: type: object properties: @@ -497,18 +511,6 @@ components: name: type: string description: 회의실 이름 - members-profile273689223: - type: object - properties: - name: - type: string - description: 이름 - company: - type: string - description: 회사명 - email: - type: string - description: 이메일 members1182193868: type: object properties: diff --git a/src/test/java/com/example/busan/member/MemberControllerTest.java b/src/test/java/com/example/busan/member/MemberControllerTest.java index bd40e5e..f37697f 100644 --- a/src/test/java/com/example/busan/member/MemberControllerTest.java +++ b/src/test/java/com/example/busan/member/MemberControllerTest.java @@ -129,7 +129,7 @@ void changeProfile() throws Exception { //given httpSession.setAttribute(AUTHORIZATION, new Authentication("test@gmail.com", Role.ADMIN)); final String request = objectMapper.writeValueAsString( - new UpdateProfileRequest("name", "company", "test@naver.com")); + new UpdateProfileRequest("name", "company", Region.BUSAN)); //when final MockHttpServletResponse response = mockMvc.perform( @@ -137,11 +137,11 @@ void changeProfile() throws Exception { .content(request) .contentType(MediaType.APPLICATION_JSON)) .andDo(print()) - .andDo(document("회원 정보 수정하기 - 이름, 회사명, 이메일", + .andDo(document("회원 정보 수정하기 - 이름, 회사명", requestFields( fieldWithPath("name").description("이름"), - fieldWithPath("company").description("회사명"), - fieldWithPath("email").description("이메일")))) + fieldWithPath("region").description("지역"), + fieldWithPath("company").description("회사명")))) .andReturn() .getResponse(); diff --git a/src/test/java/com/example/busan/member/MemberServiceTest.java b/src/test/java/com/example/busan/member/MemberServiceTest.java index 8fe0bf0..81eeec3 100644 --- a/src/test/java/com/example/busan/member/MemberServiceTest.java +++ b/src/test/java/com/example/busan/member/MemberServiceTest.java @@ -84,18 +84,16 @@ private Member createMember() { void updateProfile() { //given final Member member = createMember(); - final UpdateProfileRequest request = new UpdateProfileRequest("updated", "updated", "test@apple.com"); + final UpdateProfileRequest request = new UpdateProfileRequest("updated", "updated", Region.BUSAN); //when memberService.updateProfile(member.getEmail(), request); //then - final Member updated = memberRepository.findById("test@apple.com").get(); + final Member updated = memberRepository.findById(member.getEmail()).get(); assertSoftly(softAssertions -> { - softAssertions.assertThat(updated.getEmail()).isEqualTo("test@apple.com"); softAssertions.assertThat(updated.getCompany()).isEqualTo("updated"); softAssertions.assertThat(updated.getName()).isEqualTo("updated"); - softAssertions.assertThat(memberRepository.findById(member.getEmail())).isEmpty(); }); }