From 0369b159dcfcff0f58a2d9dbe13063aa5453d216 Mon Sep 17 00:00:00 2001 From: femmefatalehaein Date: Sun, 29 Sep 2024 21:24:14 +0900 Subject: [PATCH 1/2] check --- .../ai_jeju/controller/AlbumController.java | 4 +- .../ai_jeju/controller/TokenController.java | 7 +- .../ai_jeju/controller/UserController.java | 16 ++- .../com/example/ai_jeju/domain/Store.java | 3 + .../repository/BookmarkRepository.java | 1 + .../ai_jeju/repository/ChildRepository.java | 2 + .../example/ai_jeju/service/AlbumService.java | 16 +++ .../ai_jeju/service/MainVIewService.java | 3 +- .../example/ai_jeju/service/UserService.java | 123 +++++++++++------- 9 files changed, 114 insertions(+), 61 deletions(-) diff --git a/src/main/java/com/example/ai_jeju/controller/AlbumController.java b/src/main/java/com/example/ai_jeju/controller/AlbumController.java index 62b4416..84b5b32 100644 --- a/src/main/java/com/example/ai_jeju/controller/AlbumController.java +++ b/src/main/java/com/example/ai_jeju/controller/AlbumController.java @@ -46,8 +46,6 @@ public ResponseDto modifyAlbum(@RequestBody ModifyAlbumRequest modifyAlbumReques } - - @GetMapping("") public ResponseDto getAlbumList(@RequestParam Long childId ,String rgtDate){ List albumResponses =albumService.getAlbumList(childId,rgtDate); @@ -56,8 +54,10 @@ public ResponseDto getAlbumList(@RequestParam Long childId ,String rgtDate){ @GetMapping("/detail") public ResponseDto getDetailAlbumList(@RequestParam Long albumId){ + AlbumDetailResponse albumDetailResponse = albumService.getDetailAlbumList(albumId); return ResponseUtil.SUCCESS("사진첩 조회이 성공하셨습니다",albumDetailResponse); + } @GetMapping("/shares") diff --git a/src/main/java/com/example/ai_jeju/controller/TokenController.java b/src/main/java/com/example/ai_jeju/controller/TokenController.java index bed00a0..b18053f 100644 --- a/src/main/java/com/example/ai_jeju/controller/TokenController.java +++ b/src/main/java/com/example/ai_jeju/controller/TokenController.java @@ -22,19 +22,18 @@ public TokenController(TokenProvider tokenProvider) { } @GetMapping("") - public ResponseDto getMyTokenInfo(@RequestHeader("Authorization") String token) { + public ResponseDto getMyTokenInfo(@RequestHeader("") String token) { // Bearer 토큰 형식에서 "Bearer " 부분 제거 String accessToken = token.replace("Bearer ", ""); - Date expiredDate = tokenProvider.getExpiredDate(token); // 날짜 포맷 지정 (예: yyyy-MM-dd HH:mm:ss) SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // Date를 String으로 변환 String dateString = formatter.format(expiredDate); if (tokenProvider.validToken(token)) { - return ResponseUtil.SUCCESS("유효한 토큰입니다.",dateString); + return ResponseUtil.SUCCESS(true,dateString); } else { - return ResponseUtil.ERROR("유효하지 않은 토큰입니다.", null); + return ResponseUtil.ERROR(false, null); } 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 932dcba..f7a0da1 100755 --- a/src/main/java/com/example/ai_jeju/controller/UserController.java +++ b/src/main/java/com/example/ai_jeju/controller/UserController.java @@ -40,10 +40,16 @@ public ResponseDto CheckIfUser(@RequestParam(name = "email") String email, HttpS } //탈퇴하기 - @PostMapping("/withdraw") - public ResponseEntity signOut(@RequestBody WithdrawRequest withdrawRequest) { - String response = userService.withDraw(withdrawRequest); - return ResponseEntity.ok(response); - } + @DeleteMapping("/withdraw") + public ResponseDto signOut(@RequestHeader(value = "Authorization") String token, @RequestParam String email) { + String accessToken = token.replace("Bearer ",""); + + try { + userService.withDraw(accessToken, email); + return ResponseUtil.SUCCESS("탈퇴에 성공하였습니다.",null); + }catch (Exception e){ + return ResponseUtil.FAILURE(e, null); + } + } } diff --git a/src/main/java/com/example/ai_jeju/domain/Store.java b/src/main/java/com/example/ai_jeju/domain/Store.java index 4a6f27c..ccd018f 100644 --- a/src/main/java/com/example/ai_jeju/domain/Store.java +++ b/src/main/java/com/example/ai_jeju/domain/Store.java @@ -81,9 +81,11 @@ public class Store { @Column(name = "checkin",updatable = false,nullable = true) + @ColumnDefault("0") String checkin; @Column(name = "checkout",updatable = false,nullable = true) + @ColumnDefault("0") String checkout; @Column(name = "bookmarks") @@ -91,6 +93,7 @@ public class Store { int noBmk; @Column + @ColumnDefault("0") int rcmdType; @Column(name = "rcmd") diff --git a/src/main/java/com/example/ai_jeju/repository/BookmarkRepository.java b/src/main/java/com/example/ai_jeju/repository/BookmarkRepository.java index 6e6c497..3c3c66c 100644 --- a/src/main/java/com/example/ai_jeju/repository/BookmarkRepository.java +++ b/src/main/java/com/example/ai_jeju/repository/BookmarkRepository.java @@ -20,6 +20,7 @@ public interface BookmarkRepository extends JpaRepository { List findByStoreId(Long storeId); List findByUser(User user); void deleteByUserAndStoreId(User user, Long storeId); +void deleteByUser(User user); } diff --git a/src/main/java/com/example/ai_jeju/repository/ChildRepository.java b/src/main/java/com/example/ai_jeju/repository/ChildRepository.java index 429b358..035a995 100644 --- a/src/main/java/com/example/ai_jeju/repository/ChildRepository.java +++ b/src/main/java/com/example/ai_jeju/repository/ChildRepository.java @@ -20,5 +20,7 @@ public interface ChildRepository extends JpaRepository { Optional findByChildId(Long childId); + void deleteByUser(User user); + } diff --git a/src/main/java/com/example/ai_jeju/service/AlbumService.java b/src/main/java/com/example/ai_jeju/service/AlbumService.java index 59b4d0a..762195c 100644 --- a/src/main/java/com/example/ai_jeju/service/AlbumService.java +++ b/src/main/java/com/example/ai_jeju/service/AlbumService.java @@ -175,8 +175,23 @@ public void updateAlbum(ModifyAlbumRequest modifyAlbumRequest){ public AlbumDetailResponse getDetailAlbumList(Long albumId){ Optional optionalAlbum = albumRepository.findById(albumId); + List options = new ArrayList<>(); + //albumOption이 존재하지 않은 경우도 있으니까. if(optionalAlbum.isPresent()){ Album album = optionalAlbum.get(); + AlbumOption albumOption = albumOptionRepository.findByAlbum(album).get(); + if(albumOption.isOptionalPet()) options.add("동물"); + if(albumOption.isOptionalFriend()) options.add("친구"); + if(albumOption.isOptionalFamily()) options.add("가족"); + if(albumOption.isOptionalMorning()) options.add("아침"); + if(albumOption.isOptionalAfterNoon()) options.add("낮"); + if(albumOption.isOptionalNight()) options.add("저녁"); + if(albumOption.isOptionalDining()) options.add("식사"); + if(albumOption.isOptionalSnack()) options.add("간식"); + if(albumOption.isOptionalPlay()) options.add("놀이"); + if(albumOption.isOptionalStudy()) options.add("공부"); + if(albumOption.isOptionalExperience()) options.add("체험"); + if(albumOption.isOptionalWalk()) options.add("산책"); List imgSrcDtos = new ArrayList<>(); //album Item list List albumItems = albumItemRepository.findByAlbum(album); @@ -189,6 +204,7 @@ public AlbumDetailResponse getDetailAlbumList(Long albumId){ .AlbumDesc(album.getAlbumDesc()) .rgtDate(album.getRgtDate()) .imgSrcDtos(imgSrcDtos) + .options(options) .build(); return albumDetailResponse; }else{ diff --git a/src/main/java/com/example/ai_jeju/service/MainVIewService.java b/src/main/java/com/example/ai_jeju/service/MainVIewService.java index 19402bf..81f7d00 100644 --- a/src/main/java/com/example/ai_jeju/service/MainVIewService.java +++ b/src/main/java/com/example/ai_jeju/service/MainVIewService.java @@ -340,10 +340,9 @@ public MainResponse getMain(FilterDto filterDto, int randomSeed, int page){ Map result =storeRepositoryCustom.findByFilterDto(filterDto, randomSeed,page); List mainListResponses = new ArrayList<>(); - List stores = (List) result.get("stores"); - for(Store store : stores){ + for(Store store : stores){ MainListResponse mainListResponse = MainListResponse.builder() .storeId(store.getStoreId()) .name(store.getName()) 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 1908fd1..ef47a7c 100755 --- a/src/main/java/com/example/ai_jeju/service/UserService.java +++ b/src/main/java/com/example/ai_jeju/service/UserService.java @@ -14,6 +14,7 @@ import com.example.ai_jeju.util.ResponseUtil; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import jakarta.transaction.Transactional; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.*; import org.springframework.stereotype.Service; @@ -48,6 +49,9 @@ public class UserService { @Autowired private ChildRepository childRepository; + @Autowired + private BookmarkRepository bookmarkRepository; + @Autowired private StoreRepository storeRepository; /** @@ -165,60 +169,83 @@ public User findByEmail(String email){ public Optional findById(Long userId){ return userRepository.findById(userId); } + /** * withdroaw up flow * checkIfUser : 기존 회원여부 확인 * 기존 회원이라면 객체 (아이디만) 반환 , AccessToken 쿠키로 발급 */ - public String withDraw(WithdrawRequest withDrawRequest){ - String email = withDrawRequest.getEmail(); - String accessToken = withDrawRequest.getAccessToken(); - // 기본 빈 url - String url =""; - // email 기반으로 삭제할 user 객체 찾기 - // provider 추출하기 - User delUser = this.findByEmail(withDrawRequest.getEmail()); - String provider = delUser.getProvider(); - /*--------------------------------------------------------------------------------------------------*/ - 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"); - } + + @Transactional + 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()); + // soft-delete + + }else{ + // 존재하지 않는 회원입니다. + throw new RuntimeException("존재하지 않는 회원입니다."); + } } - return "result"; + else{ + 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"; } //생성된 리프레시 토큰을 전달받아 데이터베이스 저장 From fffa8f0c5e64873e1850ea6460e93e5c2408fa84 Mon Sep 17 00:00:00 2001 From: femmefatalehaein Date: Sun, 29 Sep 2024 21:33:48 +0900 Subject: [PATCH 2/2] [FIX] detail add options --- .../java/com/example/ai_jeju/service/AlbumService.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/example/ai_jeju/service/AlbumService.java b/src/main/java/com/example/ai_jeju/service/AlbumService.java index 762195c..cf569c7 100644 --- a/src/main/java/com/example/ai_jeju/service/AlbumService.java +++ b/src/main/java/com/example/ai_jeju/service/AlbumService.java @@ -177,7 +177,7 @@ public AlbumDetailResponse getDetailAlbumList(Long albumId){ Optional optionalAlbum = albumRepository.findById(albumId); List options = new ArrayList<>(); //albumOption이 존재하지 않은 경우도 있으니까. - if(optionalAlbum.isPresent()){ + Album album = optionalAlbum.get(); AlbumOption albumOption = albumOptionRepository.findByAlbum(album).get(); if(albumOption.isOptionalPet()) options.add("동물"); @@ -207,12 +207,9 @@ public AlbumDetailResponse getDetailAlbumList(Long albumId){ .options(options) .build(); return albumDetailResponse; - }else{ - //album없을때 - return null; } - } + public ScheduleResponse getScheculeListByChild(Long childId){