Skip to content

Commit

Permalink
Merge pull request #192 from Juinjang/feat/#191
Browse files Browse the repository at this point in the history
feat(#191) : 탈퇴 사유 기능 추가
  • Loading branch information
2hy2on authored Aug 20, 2024
2 parents bb4ae0a + ef919b7 commit b03afac
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ public enum ErrorStatus implements BaseErrorCode {
S3_DELTE_FAILED(HttpStatus.NOT_FOUND, "S34000", "해당 file이 s3에 존재하지 않습니다. 백엔드 팀에 문의바랍니다."),

//record 에러
RECORD_NOT_FOUND(HttpStatus.NOT_FOUND, "RECORD400", "record가 존재하지 않습니다");
RECORD_NOT_FOUND(HttpStatus.NOT_FOUND, "RECORD400", "record가 존재하지 않습니다"),

//withdraw 에러
WITHDRAW_REASON_NOT_FOUND(HttpStatus.NOT_FOUND, "WITHDRAW400", "해당 탈퇴 사유 enum 값이 존재하지 않습니다");


private final HttpStatus httpStatus;
Expand Down
24 changes: 22 additions & 2 deletions src/main/java/umc/th/juinjang/controller/OAuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
import umc.th.juinjang.apiPayload.code.status.SuccessStatus;
import umc.th.juinjang.apiPayload.exception.handler.MemberHandler;
import umc.th.juinjang.model.dto.auth.LoginResponseDto;
import umc.th.juinjang.model.dto.auth.WithdrawReasonRequestDto;
import umc.th.juinjang.model.dto.auth.apple.AppleLoginRequestDto;
import umc.th.juinjang.model.dto.auth.apple.AppleSignUpRequestDto;
import umc.th.juinjang.model.dto.auth.kakao.KakaoLoginRequestDto;
import umc.th.juinjang.model.dto.auth.kakao.KakaoSignUpRequestDto;
import umc.th.juinjang.model.entity.Member;
import umc.th.juinjang.model.entity.Withdraw;
import umc.th.juinjang.repository.withdraw.WithdrawRepository;
import umc.th.juinjang.service.JwtService;
import umc.th.juinjang.service.WithdrawService.WithdrawService;
import umc.th.juinjang.service.auth.OAuthService;

import java.io.IOException;
import java.util.List;

import static umc.th.juinjang.apiPayload.code.status.ErrorStatus.*;

Expand All @@ -36,6 +41,9 @@
public class OAuthController {

private final OAuthService oauthService;
private final WithdrawService withdrawService;

private final WithdrawRepository withdrawRepository;


// 카카오 로그인
Expand Down Expand Up @@ -102,7 +110,7 @@ public ApiResponse<LoginResponseDto> appleSignUp(@RequestBody @Validated AppleSi

// 카카오 탈퇴
@DeleteMapping("/withdraw/kakao")
public ApiResponse kakaoWithdraw(@AuthenticationPrincipal Member member, @RequestHeader("target-id") String kakaoTargetId) {
public ApiResponse kakaoWithdraw(@AuthenticationPrincipal Member member, @RequestHeader("target-id") String kakaoTargetId, @RequestBody @Validated WithdrawReasonRequestDto withdrawReasonReqDto) {
Long targetId;

if(kakaoTargetId == null) {
Expand All @@ -117,6 +125,9 @@ public ApiResponse kakaoWithdraw(@AuthenticationPrincipal Member member, @Reques
// 카카오 계정 연결 끊기
boolean isUnlink = oauthService.kakaoWithdraw(member, targetId);

// 탈퇴 사유 추가
withdrawService.addWithdrawReason(withdrawReasonReqDto.getWithdrawReason());

// 사용자 정보 삭제 (DB)
if (!isUnlink) {
throw new ExceptionHandler(NOT_UNLINK_KAKAO);
Expand All @@ -130,8 +141,17 @@ public ApiResponse kakaoWithdraw(@AuthenticationPrincipal Member member, @Reques
// 애플 탈퇴
@DeleteMapping("/withdraw/apple")
public ApiResponse withdraw(@AuthenticationPrincipal Member member,
@Nullable@RequestHeader("X-Apple-Code") final String code){
@Nullable@RequestHeader("X-Apple-Code") final String code, @RequestBody @Validated WithdrawReasonRequestDto withdrawReasonReqDto){
oauthService.appleWithdraw(member, code);
// 탈퇴 사유 추가
withdrawService.addWithdrawReason(withdrawReasonReqDto.getWithdrawReason());
return ApiResponse.onSuccess(SuccessStatus.MEMBER_DELETE);
}

// count 임시 test용 (최종 탈퇴 테스트 완료 후 지울 예정)
// @PostMapping("/withdraw/count")
// public ApiResponse<List<Withdraw>> withdrawReason(@RequestBody @Validated WithdrawReasonRequestDto withdrawReasonReqDto) {
// withdrawService.addWithdrawReason(withdrawReasonReqDto.getWithdrawReason());
// return ApiResponse.onSuccess(withdrawRepository.findAll());
// }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package umc.th.juinjang.model.dto.auth;

import jakarta.validation.constraints.NotEmpty;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class WithdrawReasonRequestDto {
@NotEmpty
List<String> withdrawReason;
}
31 changes: 31 additions & 0 deletions src/main/java/umc/th/juinjang/model/entity/Withdraw.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package umc.th.juinjang.model.entity;

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import umc.th.juinjang.model.entity.common.BaseEntity;
import umc.th.juinjang.model.entity.enums.WithdrawReason;

@Entity
@Getter
@Builder
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class Withdraw extends BaseEntity {

@Id
@Column(name="withdraw_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long withdrawId;

@Column(name="reason")
@Enumerated(EnumType.STRING)
private WithdrawReason withdrawReason;

@ColumnDefault("0")
private Long count;

public void updateCount(Long count) {
this.count = count;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package umc.th.juinjang.model.entity.enums;

public enum WithdrawReason {

NOT_USE, // 더 이상 쓸 일이 없어요
CANNOT_USE, // 앱 사용법을 모르겠어요
NOT_HELP, // 임장에 도움이 되지 않아요
CANNOT_FUNCTION, // 앱이 정상적으로 작동하지 않아요
CONCERN_SECURITY, // 보안이 걱정돼요
OTHER_SERVICE // 다른 서비스가 더 좋아요
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package umc.th.juinjang.repository.withdraw;

import org.springframework.data.jpa.repository.JpaRepository;
import umc.th.juinjang.model.entity.Withdraw;
import umc.th.juinjang.model.entity.enums.WithdrawReason;

import java.util.Optional;

public interface WithdrawRepository extends JpaRepository<Withdraw, Long> {
Optional<Withdraw> findByWithdrawReason(WithdrawReason withdrawReason);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package umc.th.juinjang.service.WithdrawService;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import umc.th.juinjang.apiPayload.ExceptionHandler;
import umc.th.juinjang.apiPayload.code.status.ErrorStatus;
import umc.th.juinjang.model.entity.Withdraw;
import umc.th.juinjang.model.entity.enums.WithdrawReason;
import umc.th.juinjang.repository.withdraw.WithdrawRepository;

import java.util.List;

@Slf4j
@Service
@Transactional
@RequiredArgsConstructor
public class WithdrawService {

private final WithdrawRepository withdrawRepository;

public void addWithdrawReason(List<String> withdrawReasons) {
for(String reason : withdrawReasons) {
WithdrawReason withdrawReason = WithdrawReason.valueOf(reason.toUpperCase());

Withdraw withdraw = withdrawRepository.findByWithdrawReason(withdrawReason)
.orElseThrow(() -> new ExceptionHandler(ErrorStatus.WITHDRAW_REASON_NOT_FOUND));

withdraw.updateCount(withdraw.getCount() + 1);
System.out.println("withdraw id : " + withdraw.getWithdrawId());
System.out.println("withdraw enum : " + withdraw.getWithdrawReason());
System.out.println("withdraw count : " + withdraw.getCount());
withdrawRepository.save(withdraw);
}
}
}

0 comments on commit b03afac

Please sign in to comment.