diff --git a/.gitignore b/.gitignore index c2065bc..05f06ff 100755 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,6 @@ out/ ### VS Code ### .vscode/ + +### DBCODE ### +!**/src/main/resources/application.properties diff --git a/src/main/generated/com/example/ai_jeju/domain/QUser.java b/src/main/generated/com/example/ai_jeju/domain/QUser.java index 9d82ca4..2b2fe38 100644 --- a/src/main/generated/com/example/ai_jeju/domain/QUser.java +++ b/src/main/generated/com/example/ai_jeju/domain/QUser.java @@ -43,6 +43,8 @@ public class QUser extends EntityPathBase { public final StringPath rgtDate = createString("rgtDate"); + public final BooleanPath valid = createBoolean("valid"); + public QUser(String variable) { super(User.class, forVariable(variable)); } diff --git a/src/main/java/com/example/ai_jeju/controller/UserController.java b/src/main/java/com/example/ai_jeju/controller/UserController.java index f7a0da1..9b6264f 100755 --- a/src/main/java/com/example/ai_jeju/controller/UserController.java +++ b/src/main/java/com/example/ai_jeju/controller/UserController.java @@ -42,6 +42,7 @@ public ResponseDto CheckIfUser(@RequestParam(name = "email") String email, HttpS //탈퇴하기 @DeleteMapping("/withdraw") public ResponseDto signOut(@RequestHeader(value = "Authorization") String token, @RequestParam String email) { + String accessToken = token.replace("Bearer ",""); try { diff --git a/src/main/java/com/example/ai_jeju/domain/User.java b/src/main/java/com/example/ai_jeju/domain/User.java index 3049a7f..f75b154 100755 --- a/src/main/java/com/example/ai_jeju/domain/User.java +++ b/src/main/java/com/example/ai_jeju/domain/User.java @@ -47,6 +47,10 @@ public class User { @Column(name ="ifRcmd", nullable = false) private boolean ifRcmd; + @Column(name ="valid", nullable = true) + private boolean valid; + + //약관 1 @Column(name ="ag1", nullable = false) private boolean ag1; diff --git a/src/main/java/com/example/ai_jeju/repository/UserRepository.java b/src/main/java/com/example/ai_jeju/repository/UserRepository.java index 2002116..aec85b1 100755 --- a/src/main/java/com/example/ai_jeju/repository/UserRepository.java +++ b/src/main/java/com/example/ai_jeju/repository/UserRepository.java @@ -2,6 +2,9 @@ import com.example.ai_jeju.domain.User; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; import java.util.Optional; @@ -10,10 +13,12 @@ public interface UserRepository extends JpaRepository { Optional findByEmail(String email); Optional findById(Long userId); - OptionalfindUserByNickname(String nickname); + @Modifying + @Query("UPDATE User u set u.valid = :valid WHERE u.id = :id") + void updateUserByValid(@Param("id") Long userId, @Param("valid") Boolean valid); } \ No newline at end of file diff --git a/src/main/java/com/example/ai_jeju/service/BookmarkService.java b/src/main/java/com/example/ai_jeju/service/BookmarkService.java index c692daa..93d1b34 100644 --- a/src/main/java/com/example/ai_jeju/service/BookmarkService.java +++ b/src/main/java/com/example/ai_jeju/service/BookmarkService.java @@ -108,9 +108,10 @@ public List getBookmarkByCategoryId (Long userId, int categoryId){ .numOfBmk(bmks.size()) .build(); bookMarkItems.add(bookMarkItem); - return bookMarkItems; + } } + return bookMarkItems; } return null; } diff --git a/src/main/java/com/example/ai_jeju/service/UserService.java b/src/main/java/com/example/ai_jeju/service/UserService.java index ef47a7c..db249cf 100755 --- a/src/main/java/com/example/ai_jeju/service/UserService.java +++ b/src/main/java/com/example/ai_jeju/service/UserService.java @@ -67,19 +67,18 @@ public class UserService { return null; } - if (existingUser.isPresent()) { + if (existingUser.isPresent()&&existingUser.get().isValid()) { User user = existingUser.get(); String accessToken = tokenProvider.generateToken(user, ACCESS_TOKEN_DURATION); - Date expiredDate = tokenProvider.getExpiredDate(accessToken); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // Date를 String으로 변환 String dateString = formatter.format(expiredDate); result[0] = accessToken; result[1] = dateString; - return result; } else { + return null; } } @@ -127,6 +126,7 @@ public ResponseDto registerUser( SignUpRequest signUpRequest, HttpServletRequest .rgtDate(date.toString()) .phoneNum(signUpRequest.getPhoneNum()) .ifRcmd(signUpRequest.getIfRcmd()) + .valid(true) .build(); /*-------------------------------------------*/ @@ -165,7 +165,6 @@ public User findByEmail(String email){ ()-> new IllegalArgumentException("unexpected user")); } - public Optional findById(Long userId){ return userRepository.findById(userId); } @@ -181,11 +180,10 @@ public void withDraw(String accessToken, String email){ if(tokenProvider.validToken(accessToken)){ Optional delUser = userRepository.findById(tokenProvider.getUserId(accessToken)); if(delUser.isPresent()){ - childRepository.deleteByUser(delUser.get()); - bookmarkRepository.deleteByUser(delUser.get()); - userRepository.delete(delUser.get()); + User user = delUser.get(); + userRepository.updateUserByValid(user.getId(), false); // valid 항목을 변경하는 메서드 호출 + // 변경사항 저장 // soft-delete - }else{ // 존재하지 않는 회원입니다. throw new RuntimeException("존재하지 않는 회원입니다."); @@ -195,57 +193,6 @@ public void withDraw(String accessToken, String email){ throw new RuntimeException("유효하지 않은 토큰입니다."); } -// User delUser = this.findByEmail(withDrawRequest.getEmail()); -// String provider = delUser.getProvider(); -// if(tokenProvider.validToken(withDrawRequest.getAccessToken())){ -// userRepository.delete(delUser); -// ResponseUtil.SUCCESS("delete Success","") -// return("delete success"); -// }else{ -// -// } -// -// -// /*--------------------------------------------------------------------------------------------------*/ -// switch (provider){ -// case "kakao": -// url = "https://kapi.kakao.com/v1/user/unlink"; -// //헤더 만들기 -// HttpHeaders headers = new HttpHeaders(); -// headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); -// headers.set("Authorization", "Bearer " + accessToken); -// //전달할 Header 기반 HttpEntity 만들기 -// HttpEntity entity = new HttpEntity<>(headers); -// ResponseEntity response = restTemplate.postForEntity(url, entity, String.class); -// ResponseEntity result = ResponseEntity.status(response.getStatusCode()).body(response.getBody()); -// System.out.println("카카오 탈퇴 결과값 :"+result); -// //맞을때 -// if(result.equals("200")){ -// userRepository.delete(delUser); -// return("delete success"); -// } -// //아니면 그냥 break.. -// else{ -// return("delete fail"); -// } -// /*--------------------------------------------------------------------------------------------------*/ -// case "google": -// url = "https://accounts.google.com/o/oauth2/revoke?token="+accessToken; -// ResponseEntity googleRes = restTemplate.getForEntity(url, String.class); -// ResponseEntity googleResult = ResponseEntity.status(googleRes.getStatusCode()).body(googleRes.getBody()); -// System.out.println("구글 탈퇴 결과값 :"+googleResult); -// /*--------------------------------------------------------------------------------------------------*/ -// //맞을때 -// if(googleResult.equals("200")){ -// userRepository.delete(delUser); -// return("delete success"); -// } -// //아니면 그냥 break.. -// else{ -// return("delete fail"); -// } -// } -// return "result"; } //생성된 리프레시 토큰을 전달받아 데이터베이스 저장