-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
128 additions
and
0 deletions.
There are no files selected for viewing
128 changes: 128 additions & 0 deletions
128
src/main/java/com/beotkkot/qtudy/controller/mypage/MyPageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package com.beotkkot.qtudy.controller.mypage; | ||
|
||
import com.beotkkot.qtudy.dto.response.mypage.GetMyInterestResponseDto; | ||
import com.beotkkot.qtudy.dto.response.mypage.GetMyPageAllResponseDto; | ||
import com.beotkkot.qtudy.dto.response.mypage.GetMyPageInfoResponseDto; | ||
import com.beotkkot.qtudy.dto.response.mypage.MyInterestResponseDto; | ||
import com.beotkkot.qtudy.service.auth.AuthService; | ||
import com.beotkkot.qtudy.service.mypage.MyPageService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class MyPageController { | ||
|
||
private final AuthService authService; | ||
private final MyPageService myPageService; | ||
|
||
// ๊ด์ฌ ๋ถ์ผ ๋ชฉ๋ก ์ด๊ธฐ ์ ํ | ||
@PostMapping("/my/interests") | ||
public ResponseEntity<? super MyInterestResponseDto> saveMyInterests(@RequestParam("interests") List<Long> interests, @RequestHeader("Authorization") String token) { | ||
|
||
Long kakao_uid; | ||
try { | ||
kakao_uid = authService.getKakaoUserInfo(token).getId(); | ||
if (kakao_uid == null) | ||
return MyInterestResponseDto.noAuthentication(); | ||
} catch (Exception exception) { | ||
log.info(exception.getMessage()); | ||
return MyInterestResponseDto.databaseError(); | ||
} | ||
|
||
ResponseEntity<? super MyInterestResponseDto> response = myPageService.saveMyInterests(kakao_uid, interests); | ||
return response; | ||
} | ||
|
||
// ๋ด ๊ด์ฌ ๋ถ์ผ ๋ชฉ๋ก ์กฐํ | ||
@GetMapping("my/interests") | ||
public ResponseEntity<? super GetMyInterestResponseDto> getMyInterests(@RequestHeader("Authorization") String token) { | ||
Long kakao_uid; | ||
try { | ||
kakao_uid = authService.getKakaoUserInfo(token).getId(); | ||
if (kakao_uid == null) | ||
return GetMyInterestResponseDto.noAuthentication(); | ||
} catch (Exception exception) { | ||
log.info(exception.getMessage()); | ||
return GetMyInterestResponseDto.databaseError(); | ||
} | ||
ResponseEntity<? super GetMyInterestResponseDto> response = myPageService.getMyInterests(kakao_uid); | ||
return response; | ||
} | ||
|
||
// ๋ด ๊ด์ฌ ๋ถ์ผ ๋ชฉ๋ก ์์ | ||
@PatchMapping("my/interests") | ||
public ResponseEntity<? super MyInterestResponseDto> patchMyInterests(@RequestParam("interests") List<Long> interests, @RequestHeader("Authorization") String token) { | ||
Long kakao_uid; | ||
try { | ||
kakao_uid = authService.getKakaoUserInfo(token).getId(); | ||
if (kakao_uid == null) | ||
return MyInterestResponseDto.noAuthentication(); | ||
} catch (Exception exception) { | ||
log.info(exception.getMessage()); | ||
return MyInterestResponseDto.databaseError(); | ||
} | ||
ResponseEntity<? super MyInterestResponseDto> response = myPageService.patchMyInterests(kakao_uid, interests); | ||
return response; | ||
} | ||
|
||
// ์ฌ์ฉ์ ํ๋กํ ์กฐํ | ||
@GetMapping("/my") | ||
public ResponseEntity<? super GetMyPageInfoResponseDto> getMyPageInfo(@RequestHeader("Authorization") String token) { | ||
|
||
Long kakao_uid; | ||
String email; | ||
try { | ||
kakao_uid = authService.getKakaoUserInfo(token).getId(); | ||
if (kakao_uid == null) | ||
return GetMyPageInfoResponseDto.noAuthentication(); | ||
email = authService.getKakaoUserInfo(token).getEmail(); | ||
} catch (Exception exception) { | ||
log.info(exception.getMessage()); | ||
return GetMyPageInfoResponseDto.databaseError(); | ||
} | ||
|
||
ResponseEntity<? super GetMyPageInfoResponseDto> response = myPageService.getMyPageInfo(kakao_uid, email); | ||
|
||
return response; | ||
} | ||
|
||
// ๋ด๊ฐ ์์ฑํ ๊ฒ์๊ธ ํ์ธ | ||
@GetMapping("my/posts") | ||
public ResponseEntity<? super GetMyPageAllResponseDto> getAllPost(@RequestParam("page") int page, @RequestHeader("Authorization") String token) { | ||
Long kakao_uid; | ||
try { | ||
kakao_uid = authService.getKakaoUserInfo(token).getId(); | ||
if (kakao_uid == null) | ||
return GetMyPageAllResponseDto.noAuthentication(); | ||
} catch (Exception exception) { | ||
log.info(exception.getMessage()); | ||
return GetMyPageAllResponseDto.databaseError(); | ||
} | ||
|
||
ResponseEntity<? super GetMyPageAllResponseDto> response = myPageService.getAllPost(kakao_uid, page); | ||
return response; | ||
} | ||
|
||
// ๋ด๊ฐ ์คํฌ๋ฉํ ๊ธ ํ์ธ | ||
@GetMapping("/my/scrap") | ||
public ResponseEntity<? super GetMyPageAllResponseDto> getAllScrapPost(@RequestParam("page") int page, @RequestHeader("Authorization") String token) { | ||
Long kakao_uid; | ||
try { | ||
kakao_uid = authService.getKakaoUserInfo(token).getId(); | ||
if (kakao_uid == null) | ||
return GetMyPageAllResponseDto.noAuthentication(); | ||
} catch (Exception exception) { | ||
log.info(exception.getMessage()); | ||
return GetMyPageAllResponseDto.databaseError(); | ||
} | ||
|
||
ResponseEntity<? super GetMyPageAllResponseDto> response = myPageService.getAllScrapPost(kakao_uid, page); | ||
return response; | ||
} | ||
} |