Skip to content

Commit

Permalink
[Feat] service로 회원탈퇴 구현 및 updateStatus 구현 (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed Feb 14, 2024
1 parent 5c6a256 commit 2cc65d4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

@RequiredArgsConstructor
@Service
Expand Down Expand Up @@ -181,29 +183,15 @@ public void deleteValueByKey(String key) {
}

@Transactional
public ResponseEntity<?> deleteUser(HttpServletRequest request) {
public ResponseEntity<?> deleteMember(HttpServletRequest request) {
Long memberId = jwtTokenProvider.getMemberId(request);
Optional<Member> checkMember = memberRepository.findById(memberId);

if (checkMember.isEmpty()) {
throw new InvalidMemberException();
}

Member member = checkMember.get();
if (member.getStatus() != Status.INACTIVE) {
member = Member.builder()
.id(member.getId())
.oAuthId(member.getOAuthId())
.nickname(member.getNickname())
.memberNumber(member.getMemberNumber())
.email(member.getEmail())
.platformId(member.getPlatformId())
.platform(member.getPlatform())
.status(Status.INACTIVE) // 상태를 비활성화로 설정
.refreshToken(member.getRefreshToken())
.build();
memberRepository.save(member);
}
memberRepository.updateStatus(Status.INACTIVE, memberId);

ApiResponse apiResponse = ApiResponse.builder()
.check(true)
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/com/ttubeog/domain/member/domain/Member.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,4 @@ public boolean isRegisteredOAuthMember() {
return nickname != null;
}
public boolean isNickNameChanged() { return nicknameChange; }

public void updateName(String name) {
this.nickname = name;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public interface MemberRepository extends JpaRepository<Member,Long>{
@Query("update Member as m set m.nicknameChange = :nicknameChange where m.id = :memberId")
void updateMemberNicknameChange(@Param("nicknameChange") Boolean nicknameChange, @Param("memberId") Long memberId);

@Modifying
@Query("update Member m set m.status = :status where m.id = :memberId")
void updateStatus(@Param("status") Status status, @Param("memberId") Long memberId);

Boolean existsByNickname(String nickname);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,15 @@ public ResponseEntity<?> logout(
return memberService.deleteLogout(request);
}

// @Operation(summary = "회원탈퇴", description = "현재 접속된 회원이 탈퇴 합니다.")
// @ApiResponses(value = {
// @ApiResponse(responseCode = "200", description = "회원탈퇴 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}),
// @ApiResponse(responseCode = "400", description = "회원탈퇴 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
// })
// @DeleteMapping("/delete")
// public ResponseEntity<?> deleteUser(
// HttpServletRequest request
// ) {
// ResponseEntity<?> responseEntity = memberService.deleteUser(request);
//
// if (responseEntity.getStatusCode().is2xxSuccessful()) {
// LocalDateTime localDateTime = LocalDateTime.now().plusDays(3);
//
// scheduledExecutorService.schedule(() -> {
// ResponseEntity<?> deleteResponse = memberService.deleteInactiveMember();
//
// if (deleteResponse.getStatusCode().is2xxSuccessful()) {
// System.out.println("회원 삭제 성공");
// } else {
// System.out.println("회원 삭제 실패");
// }
// }, 3, TimeUnit.DAYS);
// }
// return responseEntity;
// }
@Operation(summary = "회원탈퇴", description = "현재 접속된 회원이 탈퇴 합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "회원탈퇴 성공", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = Message.class))}),
@ApiResponse(responseCode = "400", description = "회원탈퇴 실패", content = {@Content(mediaType = "application/json", schema = @Schema(implementation = ErrorResponse.class))}),
})
@DeleteMapping("/delete")
public ResponseEntity<?> deleteUser(
HttpServletRequest request
) {
return memberService.deleteMember(request);
}
}

0 comments on commit 2cc65d4

Please sign in to comment.