Skip to content

Commit

Permalink
Merge pull request #122 from KAKAO-TOUR-API-CONTEST/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
femmefatalehaein authored Oct 1, 2024
2 parents 4846460 + e2f250f commit ab86b04
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 61 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ out/

### VS Code ###
.vscode/

### DBCODE ###
!**/src/main/resources/application.properties
2 changes: 2 additions & 0 deletions src/main/generated/com/example/ai_jeju/domain/QUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class QUser extends EntityPathBase<User> {

public final StringPath rgtDate = createString("rgtDate");

public final BooleanPath valid = createBoolean("valid");

public QUser(String variable) {
super(User.class, forVariable(variable));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/example/ai_jeju/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -10,10 +13,12 @@
public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByEmail(String email);
Optional<User> findById(Long userId);

Optional<User>findUserByNickname(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);


}
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,10 @@ public List<BookMarkItem> getBookmarkByCategoryId (Long userId, int categoryId){
.numOfBmk(bmks.size())
.build();
bookMarkItems.add(bookMarkItem);
return bookMarkItems;

}
}
return bookMarkItems;
}
return null;
}
Expand Down
65 changes: 6 additions & 59 deletions src/main/java/com/example/ai_jeju/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -127,6 +126,7 @@ public ResponseDto registerUser( SignUpRequest signUpRequest, HttpServletRequest
.rgtDate(date.toString())
.phoneNum(signUpRequest.getPhoneNum())
.ifRcmd(signUpRequest.getIfRcmd())
.valid(true)
.build();
/*-------------------------------------------*/

Expand Down Expand Up @@ -165,7 +165,6 @@ public User findByEmail(String email){
()-> new IllegalArgumentException("unexpected user"));
}


public Optional<User> findById(Long userId){
return userRepository.findById(userId);
}
Expand All @@ -181,11 +180,10 @@ public void withDraw(String accessToken, String email){
if(tokenProvider.validToken(accessToken)){
Optional<User> 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("존재하지 않는 회원입니다.");
Expand All @@ -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<String> entity = new HttpEntity<>(headers);
// ResponseEntity<String> response = restTemplate.postForEntity(url, entity, String.class);
// ResponseEntity<String> 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<String> googleRes = restTemplate.getForEntity(url, String.class);
// ResponseEntity<String> 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";
}

//생성된 리프레시 토큰을 전달받아 데이터베이스 저장
Expand Down

0 comments on commit ab86b04

Please sign in to comment.