Skip to content

Commit

Permalink
feat: 회원 지역 수정 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
nuyh99 committed Nov 29, 2023
1 parent bb433e4 commit 017a1db
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 54 deletions.
5 changes: 1 addition & 4 deletions src/main/java/com/example/busan/member/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 9 additions & 19 deletions src/main/java/com/example/busan/member/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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, "지역이 필요합니다.");
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
}
46 changes: 24 additions & 22 deletions src/main/resources/static/api/openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ paths:
현재 유저 정보 조회하기:
value: "{\"name\":\"연어\",\"phone\":\"01012341234\",\"email\":\"\
[email protected]\",\"role\":\"USER\",\"company\":\"우형\",\"region\"\
:\"BUSAN\",\"createdAt\":\"2023-11-29T02:23:02.327603\"}"
:\"BUSAN\",\"createdAt\":\"2023-11-30T00:09:16.804123\"}"
post:
tags:
- members
Expand Down Expand Up @@ -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\":\"[email protected]\"\
회원 정보 수정하기 - 이름, 회사명:
value: "{\"name\":\"name\",\"company\":\"company\",\"region\":\"BUSAN\"\
}"
회원 정보 수정하기 - 이름, 회사명, 이메일:
value: "{\"name\":\"name\",\"company\":\"company\"}"
responses:
"204":
description: "204"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,19 @@ void changeProfile() throws Exception {
//given
httpSession.setAttribute(AUTHORIZATION, new Authentication("[email protected]", Role.ADMIN));
final String request = objectMapper.writeValueAsString(
new UpdateProfileRequest("name", "company", "[email protected]"));
new UpdateProfileRequest("name", "company", Region.BUSAN));

//when
final MockHttpServletResponse response = mockMvc.perform(
put("/members/profile").session(httpSession)
.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();

Expand Down
6 changes: 2 additions & 4 deletions src/test/java/com/example/busan/member/MemberServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,16 @@ private Member createMember() {
void updateProfile() {
//given
final Member member = createMember();
final UpdateProfileRequest request = new UpdateProfileRequest("updated", "updated", "[email protected]");
final UpdateProfileRequest request = new UpdateProfileRequest("updated", "updated", Region.BUSAN);

//when
memberService.updateProfile(member.getEmail(), request);

//then
final Member updated = memberRepository.findById("[email protected]").get();
final Member updated = memberRepository.findById(member.getEmail()).get();
assertSoftly(softAssertions -> {
softAssertions.assertThat(updated.getEmail()).isEqualTo("[email protected]");
softAssertions.assertThat(updated.getCompany()).isEqualTo("updated");
softAssertions.assertThat(updated.getName()).isEqualTo("updated");
softAssertions.assertThat(memberRepository.findById(member.getEmail())).isEmpty();
});
}

Expand Down

0 comments on commit 017a1db

Please sign in to comment.