Skip to content

Commit

Permalink
Merge pull request #56 from Tea-Bliss/dev
Browse files Browse the repository at this point in the history
[fix] 회원 정보/비밀번호/주소 변경 API 추가 및 수정 완료
  • Loading branch information
mun9659 authored Jun 18, 2024
2 parents 30a8d46 + b7ccd00 commit 409b5b6
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ public ResponseEntity<MemberResponse> updatePassword(
@PatchMapping("/address")
@Operation(summary = "회원 주소 수정 요청", description = "회원 주소 수정 요청 API")
public ResponseEntity<MemberResponse> updateAddress(
@AuthenticationPrincipal MemberDetails memberDetails
@AuthenticationPrincipal MemberDetails memberDetails,
@RequestBody MemberAddressDto memberAddressDto
) {
return null;
int result = memberService.updateAddress(memberDetails.getMemberId(), memberAddressDto);

return ResponseEntity.ok(MemberResponse.ok(result));
}

}
22 changes: 22 additions & 0 deletions src/main/java/store/teabliss/member/dto/MemberAddressDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package store.teabliss.member.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;
import store.teabliss.member.entity.Member;

@Getter
public class MemberAddressDto {

@Schema(description = "회원 주소", example = "주소 입력")
private String address;

@Builder
public Member toEntity(Long memId) {
return Member.builder()
.memId(memId)
.address(address)
.build();
}

}
4 changes: 0 additions & 4 deletions src/main/java/store/teabliss/member/dto/MemberEditDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
@Getter
public class MemberEditDto {

@Schema(description = "이메일 주소", example = "[email protected]")
private String email;

@Schema(description = "닉네임", example = "nickname")
private String nickname;

Expand All @@ -22,7 +19,6 @@ public class MemberEditDto {
public Member toEntity(Long memId) {
return Member.builder()
.memId(memId)
.email(email)
.nickname(nickname)
.profile(profile)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ private ResponseEntity<MemberResponse> handler(DuplicationNicknameException e) {
return ResponseEntity.badRequest().body(response);
}

@ExceptionHandler(NotEqualPasswordException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
private ResponseEntity<MemberResponse> handler(NotEqualPasswordException e) {

MemberResponse response = MemberResponse.builder()
.status(e.getStatus())
.message(e.getMessage())
.build();

return ResponseEntity.badRequest().body(response);
}

@ExceptionHandler(MethodArgumentNotValidException.class)
private ResponseEntity<MemberResponse> handlerMethodArgumentNotValidException(MethodArgumentNotValidException e) {
Map<String, Object> errors = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public enum MemberStatus {
MEMBER_JOIN_FAIL(400, "회원가입에 실패했습니다."),
DUPLICATE_MEMBER(400, "이메일 중복된 회원이 있습니다."),
DUPLICATE_NICKNAME(400, "닉네임 중복된 회원이 있습니다."),
NOT_EQUAL_OLD_PASSWORD(400, "기존 비밀번호와 같지 않습니다."),
NOT_EQUAL_NEW_PASSWORD(400, "새 비밀번호 비교가 다릅니다."),
NOT_FOUND_MEMBER_BY_ID(400, "회원 아이디와 일치하는 정보가 없습니다."),
NOT_FOUND_MEMBER_BY_EMAIL(400, "회원 이메일과 일치하는 정보가 없습니다.");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package store.teabliss.member.exception;

public class NotEqualPasswordException extends MemberException {

public NotEqualPasswordException(String type) {
super(type.equals("old") ? MemberStatus.NOT_EQUAL_OLD_PASSWORD : MemberStatus.NOT_EQUAL_NEW_PASSWORD);
}

}
30 changes: 21 additions & 9 deletions src/main/java/store/teabliss/member/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import store.teabliss.member.dto.MemberDto;
import store.teabliss.member.dto.MemberEditDto;
import store.teabliss.member.dto.MemberPasswordDto;
import store.teabliss.member.dto.MemberSignUpDto;
import store.teabliss.member.dto.*;
import store.teabliss.member.entity.Member;
import store.teabliss.member.exception.DuplicationMemberEmailException;
import store.teabliss.member.exception.DuplicationNicknameException;
import store.teabliss.member.exception.NotEqualPasswordException;
import store.teabliss.member.exception.NotFoundMemberByIdException;
import store.teabliss.member.mapper.MemberMapper;

Expand Down Expand Up @@ -50,9 +48,13 @@ public MemberDto selectMemberId(Long memId) {
}

public int updateMember(Long memId, MemberEditDto memberEditDto) {
Member member = memberEditDto.toEntity(memId);
Member member = memberMapper.findById(memId).orElseThrow(
() -> new NotFoundMemberByIdException(memId)
);

return memberMapper.updateMember(member);
Member updateMember = memberEditDto.toEntity(memId);

return memberMapper.updateMember(updateMember);
}

public int updatePassword(Long memId, MemberPasswordDto memberPasswordDto) {
Expand All @@ -61,16 +63,26 @@ public int updatePassword(Long memId, MemberPasswordDto memberPasswordDto) {
);

if(!encoder.matches(memberPasswordDto.getOldPassword(), member.getPassword()))
throw new RuntimeException("기존 비밀번호 입력이 틀립니다.");
throw new NotEqualPasswordException("old");

if(!memberPasswordDto.getNewPassword().equals(memberPasswordDto.getNewPasswordCheck()))
throw new RuntimeException("새 비밀번호 비교가 틀립니다.");
throw new NotEqualPasswordException("new");

Member updateMember = memberPasswordDto.toEntity(memId);

updateMember.passwordEncode(encoder);

return memberMapper.updatePassword(member);
return memberMapper.updatePassword(updateMember);
}

public int updateAddress(Long memId, MemberAddressDto memberAddressDto) {
Member member = memberMapper.findById(memId).orElseThrow(
() -> new NotFoundMemberByIdException(memId)
);

Member updateMember = memberAddressDto.toEntity(memId);

return memberMapper.updateMember(updateMember);
}

}
7 changes: 4 additions & 3 deletions src/main/resources/mapper/MemberMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
)
</insert>

<select id="findById" parameterType="String">
<select id="findById" parameterType="Long">
SELECT
*
FROM MEMBER
WHERE 1=1
AND memId = #{value}
AND mem_id = #{value}
</select>

<select id="findByEmail" parameterType="String">
Expand Down Expand Up @@ -72,7 +72,8 @@
UPDATE MEMBER
SET
nickname = IFNULL(#{nickname}, nickname),
profile = IFNULL(#{profile}, profile)
profile = IFNULL(#{profile}, profile),
address = IFNULL(#{address}, address)
WHERE 1=1
AND mem_id = #{memId}
</update>
Expand Down

0 comments on commit 409b5b6

Please sign in to comment.