Skip to content

Commit

Permalink
Merge pull request #106 from KAKAO-TOUR-API-CONTEST/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
femmefatalehaein authored Sep 29, 2024
2 parents 00535c8 + 1525737 commit 0ef5a84
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public ResponseDto modifyAlbum(@RequestBody ModifyAlbumRequest modifyAlbumReques
}




@GetMapping("")
public ResponseDto getAlbumList(@RequestParam Long childId ,String rgtDate){
List<AlbumListResponse> albumResponses =albumService.getAlbumList(childId,rgtDate);
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
16 changes: 11 additions & 5 deletions src/main/java/com/example/ai_jeju/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@ public ResponseDto CheckIfUser(@RequestParam(name = "email") String email, HttpS
}

//탈퇴하기
@PostMapping("/withdraw")
public ResponseEntity<String> 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);
}

}
}
3 changes: 3 additions & 0 deletions src/main/java/com/example/ai_jeju/domain/Store.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,19 @@ 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")
@ColumnDefault("0")
int noBmk;

@Column
@ColumnDefault("0")
int rcmdType;

@Column(name = "rcmd")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface BookmarkRepository extends JpaRepository<Bookmark,Long> {
List<Bookmark> findByStoreId(Long storeId);
List<Bookmark> findByUser(User user);
void deleteByUserAndStoreId(User user, Long storeId);
void deleteByUser(User user);


}
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ public interface ChildRepository extends JpaRepository<Child, Long> {

Optional<Child> findByChildId(Long childId);

void deleteByUser(User user);


}
23 changes: 18 additions & 5 deletions src/main/java/com/example/ai_jeju/service/AlbumService.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,23 @@ public void updateAlbum(ModifyAlbumRequest modifyAlbumRequest){
public AlbumDetailResponse getDetailAlbumList(Long albumId){

Optional<Album> optionalAlbum = albumRepository.findById(albumId);
if(optionalAlbum.isPresent()){
List<String> options = new ArrayList<>();
//albumOption이 존재하지 않은 경우도 있으니까.

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<String> imgSrcDtos = new ArrayList<>();
//album Item list
List<AlbumItem> albumItems = albumItemRepository.findByAlbum(album);
Expand All @@ -189,14 +204,12 @@ public AlbumDetailResponse getDetailAlbumList(Long albumId){
.AlbumDesc(album.getAlbumDesc())
.rgtDate(album.getRgtDate())
.imgSrcDtos(imgSrcDtos)
.options(options)
.build();
return albumDetailResponse;
}else{
//album없을때
return null;
}

}



public ScheduleResponse getScheculeListByChild(Long childId){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,9 @@ public MainResponse getMain(FilterDto filterDto, int randomSeed, int page){

Map<String, Object> result =storeRepositoryCustom.findByFilterDto(filterDto, randomSeed,page);
List<MainListResponse> mainListResponses = new ArrayList<>();

List<Store> stores = (List<Store>) result.get("stores");
for(Store store : stores){

for(Store store : stores){
MainListResponse mainListResponse = MainListResponse.builder()
.storeId(store.getStoreId())
.name(store.getName())
Expand Down
123 changes: 75 additions & 48 deletions src/main/java/com/example/ai_jeju/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -48,6 +49,9 @@ public class UserService {
@Autowired
private ChildRepository childRepository;

@Autowired
private BookmarkRepository bookmarkRepository;

@Autowired
private StoreRepository storeRepository;
/**
Expand Down Expand Up @@ -165,60 +169,83 @@ public User findByEmail(String email){
public Optional<User> 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<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");
}

@Transactional
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());
// 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<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 0ef5a84

Please sign in to comment.