-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 카카오 OpenAPI 수정 및 Class 구조 변경 (#3)
- Loading branch information
Showing
31 changed files
with
771 additions
and
661 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
docker-test-server/src/main/java/com/example/server/controller/HomeController.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,57 @@ | ||
package com.example.server.controller; | ||
|
||
import java.util.Objects; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.example.server.error.CException; | ||
import com.example.server.model.User; | ||
import com.example.server.model.UserPet; | ||
import com.example.server.service.HomeService; | ||
import com.example.server.service.InvalidTokenService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController // REST API 컨트롤러 선언, @Controller + @ResponseBody 결합 | ||
@RequiredArgsConstructor // final 필드의 생성자 자동 생성 | ||
@RequestMapping("/api/home") | ||
public class HomeController { | ||
private final InvalidTokenService invalidTokenService; | ||
private final HomeService homeService; | ||
|
||
// 홈페이지 | ||
// 펫이름 가져오기 | ||
// Input : 파라미터 AccessToken | ||
// Output(200) : 홈페이지[이미 가입한 회원] | ||
// Output(401) : 유효하지 않은 토큰 | ||
// Output(402) : 리프레시토큰으로 토큰 재발급 필요. | ||
// Output(500) : 서버에러 | ||
@GetMapping("") | ||
public ResponseEntity<?> home(@RequestHeader("AccessToken") String AccessToken) { | ||
User user = null; | ||
try { | ||
invalidTokenService.isTokenInvalid(AccessToken); | ||
System.out.println(AccessToken); | ||
user = homeService.getPetInformation(AccessToken); | ||
} catch (CException e) { | ||
return ResponseEntity.status(e.getErrorCode().getStatus()).body(e.getErrorCode().getMessage()); | ||
} catch (Exception e) { | ||
return ResponseEntity.status(500).body(e.toString()); | ||
} | ||
|
||
if(Objects.isNull(user)) | ||
return ResponseEntity.status(500).body("유저 정보를 가져오지 못 했습니다."); | ||
|
||
System.out.print("User : "); | ||
System.out.println(user.toString()); | ||
|
||
UserPet userPet = new UserPet(user.getPetName(), user.getPetWeight()); | ||
|
||
// access 토큰 확인 | ||
return ResponseEntity.status(200).body(userPet); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
docker-test-server/src/main/java/com/example/server/controller/LoginController.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,42 @@ | ||
package com.example.server.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.example.server.error.CException; | ||
import com.example.server.service.LoginService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/login") | ||
public class LoginController { | ||
private final LoginService loginService; | ||
|
||
// 로그인시 재가입 여부를 판단하는 API | ||
// Input : AccessToken, RefreshToken, ExpiresIn, RefreshTokenExpiresIn | ||
// Output(403) : 이미 가입한 사용자 -> 데이터 Update -> 홈페이지 | ||
// Output(401) : 유효하지 않은 토큰 | ||
// Output(200) : 재가입 No -> 회원가입 페이지 | ||
@GetMapping("") | ||
public ResponseEntity<?> login( | ||
@RequestHeader("AccessToken") String AccessToken, | ||
@RequestHeader("ExpiresIn") Integer ExpiresIn, | ||
@RequestHeader("RefreshToken") String RefreshToken, | ||
@RequestHeader("RefreshTokenExpiresIn") Integer RefreshTokenExpiresIn | ||
){ | ||
try { | ||
loginService.isUserRejoin(AccessToken, ExpiresIn, RefreshToken, RefreshTokenExpiresIn); | ||
} catch (CException e) { | ||
return ResponseEntity.status(e.getErrorCode().getStatus()).body(e.getErrorCode().getMessage()); | ||
} catch (Exception e) { | ||
return ResponseEntity.status(500).body(e.toString()); | ||
} | ||
|
||
return ResponseEntity.status(200).body("."); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
docker-test-server/src/main/java/com/example/server/controller/RegisterController.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,43 @@ | ||
package com.example.server.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.example.server.error.CException; | ||
import com.example.server.service.RegisterService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/register") | ||
public class RegisterController { | ||
private final RegisterService registerService; | ||
|
||
// 회원가입이 끝나면 저장하기 위한 API | ||
// Input : AccessToken, ExpiresI, RefreshToken, RefreshTokenExpiresIn, PetName, PetWeight | ||
// Output : status(200, 401, 500) | ||
@PostMapping("") | ||
public ResponseEntity<?> register( | ||
@RequestHeader("AccessToken") String AccessToken, | ||
@RequestHeader("ExpiresIn") Integer ExpiresIn, | ||
@RequestHeader("RefreshToken") String RefreshToken, | ||
@RequestHeader("RefreshTokenExpiresIn") Integer RefreshTokenExpiresIn, | ||
@RequestHeader("PetName") String PetName, | ||
@RequestHeader("PetWeight") Integer PetWeight | ||
) { | ||
Integer status = 200; | ||
try { | ||
registerService.isUserRejoin(AccessToken, ExpiresIn, RefreshToken, RefreshTokenExpiresIn, PetName, PetWeight); | ||
} catch (CException e) { | ||
return ResponseEntity.status(e.getErrorCode().getStatus()).body(e.getErrorCode().getMessage()); | ||
} catch (Exception e) { | ||
return ResponseEntity.status(500).body(e.toString()); | ||
} | ||
|
||
return ResponseEntity.status(status).body("."); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
docker-test-server/src/main/java/com/example/server/controller/TartarController.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,36 @@ | ||
package com.example.server.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.example.server.error.CException; | ||
import com.example.server.service.InvalidTokenService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/tartar") | ||
public class TartarController { | ||
private final InvalidTokenService invalidTokenService; | ||
|
||
// Default : | ||
// 1. Token이 유효한지 확인. | ||
|
||
// 사용자가 애완견 이빨을 찍으면 | ||
@GetMapping("") | ||
public ResponseEntity<?> tartar(@RequestHeader("AccessToken") String AccessToken) { | ||
try { | ||
invalidTokenService.isTokenInvalid(AccessToken); | ||
} catch (CException e) { | ||
ResponseEntity.status(e.getErrorCode().getStatus()).body(e.getErrorCode().getMessage()); | ||
} catch (Exception e) { | ||
ResponseEntity.status(500).body(e.toString()); | ||
} | ||
|
||
return ResponseEntity.status(200).body("null"); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
docker-test-server/src/main/java/com/example/server/controller/ToothController.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,36 @@ | ||
package com.example.server.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.example.server.error.CException; | ||
import com.example.server.service.InvalidTokenService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/tooth") | ||
public class ToothController { | ||
// 양치질이 끝나면 또는 주기적으로 Front에서 데이터를 보내면 | ||
// TimeStream에 저장해주는 역할 API. | ||
|
||
private final InvalidTokenService invalidTokenService; | ||
|
||
// 사용자가 애완견 이빨을 찍으면 | ||
@GetMapping("") | ||
public ResponseEntity<?> tooth(@RequestHeader("AccessToken") String AccessToken) { | ||
try { | ||
invalidTokenService.isTokenInvalid(AccessToken); | ||
} catch (CException e) { | ||
ResponseEntity.status(e.getErrorCode().getStatus()).body(e.getErrorCode().getMessage()); | ||
} catch (Exception e) { | ||
ResponseEntity.status(500).body(e.toString()); | ||
} | ||
|
||
return ResponseEntity.status(200).body("null"); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
docker-test-server/src/main/java/com/example/server/controller/UpdateAccessController.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,34 @@ | ||
package com.example.server.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.example.server.error.CException; | ||
import com.example.server.service.UpdateAccessService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController // REST API 컨트롤러 선언, @Controller + @ResponseBody 결합 | ||
@RequiredArgsConstructor // final 필드의 생성자 자동 생성 | ||
@RequestMapping("/api/update") | ||
public class UpdateAccessController { | ||
private UpdateAccessService updateAccessService; | ||
|
||
// AccessToken을 새로 발급 받았을때 사용하는 API. | ||
// 서버에 새로운 AccessToken을 제공. | ||
@GetMapping("/accesstoken") | ||
public ResponseEntity<?> updateAccessToken(@RequestHeader("AccessToken") String AccessToken, | ||
@RequestHeader("ExpiresIn") Integer ExpiresIn) { | ||
try { | ||
updateAccessService.updateAccessTokenById(AccessToken, ExpiresIn); | ||
} catch(CException e) { | ||
ResponseEntity.status(e.getErrorCode().getStatus()).body(e.getErrorCode().getMessage()); | ||
} catch(Exception e) { | ||
ResponseEntity.status(500).body(e.toString()); | ||
} | ||
return ResponseEntity.status(null).body(null); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
docker-test-server/src/main/java/com/example/server/controller/UserController.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,77 @@ | ||
package com.example.server.controller; | ||
|
||
import java.util.Objects; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.example.server.error.CException; | ||
import com.example.server.model.User; | ||
import com.example.server.model.UserPet; | ||
import com.example.server.service.InvalidTokenService; | ||
import com.example.server.service.UserService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/user") | ||
public class UserController { | ||
private InvalidTokenService invalidTokenService; | ||
private UserService userService; | ||
|
||
@GetMapping("test") | ||
public ResponseEntity<?> test() { | ||
return ResponseEntity.ok().body("."); | ||
} | ||
|
||
// 마이페이지 | ||
// 마이페이지를 보여주는 API | ||
// Input : AccessToken | ||
// Output : User | ||
@GetMapping("/getinfo") | ||
public ResponseEntity<?> mypageGetinfo(@RequestHeader("AccessToken") String AccessToken) { | ||
User user = null; | ||
try { | ||
invalidTokenService.isTokenInvalid(AccessToken); | ||
user = userService.getPetInformation(AccessToken); | ||
} catch (CException e) { | ||
ResponseEntity.status(e.getErrorCode().getStatus()).body(e.getErrorCode().getMessage()); | ||
} catch (Exception e) { | ||
ResponseEntity.status(500).body(e.toString()); | ||
} | ||
|
||
if(Objects.isNull(user)) | ||
ResponseEntity.status(500).body("유저 정보를 가져오지 못 했습니다."); | ||
|
||
UserPet userPet = new UserPet(user.getPetName(), user.getPetWeight()); | ||
|
||
return ResponseEntity.status(200).body(userPet); | ||
} | ||
|
||
// 마이페이지 수정 | ||
// 마이페이지를 수정하는 API | ||
// Input : AccessToken, PetName, PetWeight | ||
// Output : status(200, 401, 500) | ||
@PutMapping("/setinfo") | ||
public ResponseEntity<?> mypageGetinfo( | ||
@RequestHeader("AccessToken") String AccessToken, | ||
@RequestHeader("PetName") String PetName, | ||
@RequestHeader("PetWeight") Integer PetWeight | ||
) { | ||
try { | ||
invalidTokenService.isTokenInvalid(AccessToken); | ||
userService.setPetInformation(AccessToken, PetName, PetWeight); | ||
} catch (CException e) { | ||
ResponseEntity.status(e.getErrorCode().getStatus()).body(e.getErrorCode().getMessage()); | ||
} catch (Exception e) { | ||
ResponseEntity.status(500).body(e.toString()); | ||
} | ||
|
||
return ResponseEntity.ok().body("."); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
docker-test-server/src/main/java/com/example/server/error/CException.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,18 @@ | ||
package com.example.server.error; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class CException extends RuntimeException { | ||
private final ErrorCode errorCode; | ||
|
||
public CException(ErrorCode errorCode) { | ||
super(errorCode.getMessage()); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public CException(ErrorCode errorCode, String message) { | ||
super(message); | ||
this.errorCode = errorCode; | ||
} | ||
} |
Oops, something went wrong.