Skip to content

Commit

Permalink
Merge pull request #84 from co-niverse/feat/api-version
Browse files Browse the repository at this point in the history
api version library 적용
  • Loading branch information
GIVEN53 authored Nov 13, 2023
2 parents a14b37a + d10358f commit 904caed
Show file tree
Hide file tree
Showing 32 changed files with 623 additions and 368 deletions.
12 changes: 5 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ configurations {

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}

dependencies {
Expand All @@ -36,7 +37,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

// swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' // TODO

// jwt
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2'
Expand All @@ -54,12 +55,6 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
testImplementation 'de.flapdoodle.embed:de.flapdoodle.embed.mongo.spring30x:4.7.0'

// kafka
implementation 'org.springframework.kafka:spring-kafka:3.0.11'

// kinesis KPL
implementation 'software.amazon.kinesis:amazon-kinesis-client:2.5.2'

// aop
implementation 'org.springframework.boot:spring-boot-starter-aop'

Expand All @@ -80,6 +75,9 @@ dependencies {
implementation 'net.javacrumbs.shedlock:shedlock-spring:4.14.0'
implementation 'net.javacrumbs.shedlock:shedlock-provider-jdbc-template:4.14.0'

// api versioning
implementation 'com.github.GIVEN53:api-versioning-library:0.2.0'

}

tasks.named('test') {
Expand Down
1 change: 1 addition & 0 deletions src/lombok.config
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Value
lombok.addLombokGeneratedAnnotation = true
7 changes: 3 additions & 4 deletions src/main/java/com/coniverse/dangjang/DangjangApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
import given.apiversion.autoconfigure.EnableApiVersion;

@EnableApiVersion
@EnableJpaAuditing
@EnableAsync
@SpringBootApplication
public class DangjangApplication {
public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.coniverse.dangjang.domain.auth.service.OauthLoginService;
import com.coniverse.dangjang.global.dto.SuccessSingleResponse;

import given.apiversion.core.annotation.ApiVersion;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand All @@ -26,39 +27,75 @@
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/auth")
@RequestMapping("/auth")
public class LoginController {
private static final String ACCESS_TOKEN = "AccessToken";
private static final String AUTHORIZATION = "Authorization";
private final OauthLoginService oauthLoginService;
private static String headerKeyFcmToken = "FcmToken";
private static String headerKeyAccessToken = "AccessToken";

private static String headerKeyAuthorization = "Authorization";

/**
* @param params 카카오 accessToken
* @return ResponseEntity 로그인을 성공하면, JWT TOKEN과 사용자 정보(nickname, auth id)를 전달한다.
* @since 1.0.0
* @deprecated 1.6.0
*/
@Deprecated(since = "1.6.0")
@PostMapping("/kakao")
public ResponseEntity<SuccessSingleResponse<LoginResponse>> loginKakao(@Valid @RequestBody KakaoLoginRequest params) {
LoginResponse loginResponse = oauthLoginService.login(params);
String accessToken = oauthLoginService.getAuthToken(loginResponse.nickname());
return ResponseEntity.ok()
.header(headerKeyAccessToken.toString(), accessToken)
.header(ACCESS_TOKEN.toString(), accessToken)
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), loginResponse));
}

/**
* 카카오 로그인
*
* @param params 카카오 access token
* @return jwt token, 로그인 정보
* @since 1.6.0
*/
@ApiVersion("1")
@PostMapping("/kakao")
public ResponseEntity<SuccessSingleResponse<LoginResponse>> loginKakaoV1(@Valid @RequestBody KakaoLoginRequest params) {
LoginResponse loginResponse = oauthLoginService.login(params);
String accessToken = oauthLoginService.getAuthToken(loginResponse.nickname());
return ResponseEntity.ok()
.header(ACCESS_TOKEN.toString(), accessToken)
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), loginResponse));
}

/**
* @param params 네이버 accessToken
* @return ResponseEntity 로그인을 성공하면, JWT TOKEN과 사용자 정보(nickname, auth id)를 전달한다.
* @since 1.0.0
* @deprecated 1.6.0
*/
@Deprecated(since = "1.6.0")
@PostMapping("/naver")
public ResponseEntity<SuccessSingleResponse<LoginResponse>> loginNaver(@Valid @RequestBody NaverLoginRequest params) {
LoginResponse loginResponse = oauthLoginService.login(params);
String accessToken = oauthLoginService.getAuthToken(loginResponse.nickname());
return ResponseEntity.ok()
.header(headerKeyAccessToken, accessToken)
.header(ACCESS_TOKEN, accessToken)
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), loginResponse));
}

/**
* 네이버 로그인
*
* @param params 네이버 access token
* @return jwt token, 로그인 정보
* @since 1.6.0
*/
@ApiVersion("1")
@PostMapping("/naver")
public ResponseEntity<SuccessSingleResponse<LoginResponse>> loginNaverV1(@Valid @RequestBody NaverLoginRequest params) {
LoginResponse loginResponse = oauthLoginService.login(params);
String accessToken = oauthLoginService.getAuthToken(loginResponse.nickname());
return ResponseEntity.ok()
.header(ACCESS_TOKEN, accessToken)
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), loginResponse));
}

Expand All @@ -68,12 +105,30 @@ public ResponseEntity<SuccessSingleResponse<LoginResponse>> loginNaver(@Valid @R
* @param request 재발급 요청 , header에 accessToken이 필요
* @return AuthToken
* @since 1.0.0
* @deprecated 1.6.0
*/
@Deprecated(since = "1.6.0")
@PostMapping("/reissue")
public ResponseEntity<SuccessSingleResponse<?>> reissue(HttpServletRequest request) {
String newAccessToken = oauthLoginService.reissueToken(request.getHeader(headerKeyAuthorization));
String newAccessToken = oauthLoginService.reissueToken(request.getHeader(AUTHORIZATION));
return ResponseEntity.ok()
.header(ACCESS_TOKEN, newAccessToken)
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null));
}

/**
* refresh token으로 access token 재발급
*
* @param request 재발급 요청, header에 access token 필요
* @return AuthToken
* @since 1.6.0
*/
@ApiVersion("1")
@PostMapping("/reissue")
public ResponseEntity<SuccessSingleResponse<?>> reissueV1(HttpServletRequest request) {
String newAccessToken = oauthLoginService.reissueToken(request.getHeader(AUTHORIZATION));
return ResponseEntity.ok()
.header(headerKeyAccessToken, newAccessToken)
.header(ACCESS_TOKEN, newAccessToken)
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null));
}

Expand All @@ -83,10 +138,27 @@ public ResponseEntity<SuccessSingleResponse<?>> reissue(HttpServletRequest reque
* @param request HttpServletRequest oauthId
* @param logoutFcmTokenRequest fcmToken
* @since 1.1.0
* @deprecated 1.6.0
*/
@Deprecated(since = "1.6.0")
@PostMapping("/logout")
public ResponseEntity<SuccessSingleResponse> logout(HttpServletRequest request, @RequestBody LogoutFcmTokenRequest logoutFcmTokenRequest) {
oauthLoginService.logout(request.getHeader(headerKeyAuthorization), logoutFcmTokenRequest.fcmToken());
oauthLoginService.logout(request.getHeader(AUTHORIZATION), logoutFcmTokenRequest.fcmToken());
return ResponseEntity.ok()
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null));
}

/**
* 로그아웃
*
* @param request HttpServletRequest
* @param logoutFcmTokenRequest fcm token 정보
* @since 1.6.0
*/
@ApiVersion("1")
@PostMapping("/logout")
public ResponseEntity<SuccessSingleResponse<?>> logoutV1(HttpServletRequest request, @RequestBody LogoutFcmTokenRequest logoutFcmTokenRequest) {
oauthLoginService.logout(request.getHeader(AUTHORIZATION), logoutFcmTokenRequest.fcmToken());
return ResponseEntity.ok()
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.coniverse.dangjang.global.dto.SuccessSingleResponse;
import com.coniverse.dangjang.global.validator.ValidLocalDate;

import given.apiversion.core.annotation.ApiVersion;
import lombok.RequiredArgsConstructor;

/**
Expand All @@ -24,9 +25,9 @@
* @since 1.0.0
*/
@RestController
@RequestMapping("/api/guide/blood-sugar")
@RequiredArgsConstructor
@Validated
@RequestMapping("/guide/blood-sugar")
public class BloodSugarGuideController {
private final BloodSugarGuideSearchService bloodSugarGuideSearchService;

Expand All @@ -37,11 +38,30 @@ public class BloodSugarGuideController {
* @param principal 사용자 정보
* @return 혈당 가이드 응답 dto
* @since 1.0.0
* @deprecated 1.6.0
*/
@Deprecated(since = "1.6.0")
@GetMapping
public ResponseEntity<SuccessSingleResponse<BloodSugarGuideResponse>> get(@ValidLocalDate @RequestParam String date,
@AuthenticationPrincipal User principal) {
BloodSugarGuideResponse response = bloodSugarGuideSearchService.findGuide(principal.getUsername(), date);
return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response));
}

/**
* 혈당 가이드를 조회한다.
*
* @param date 조회할 일자
* @param principal 사용자 정보
* @return 혈당 가이드 응답 dto
* @since 1.6.0
*/
@ApiVersion("1")
@GetMapping
public ResponseEntity<SuccessSingleResponse<BloodSugarGuideResponse>> getBloodSugarGuideV1(@ValidLocalDate @RequestParam String date,
@AuthenticationPrincipal User principal) {
BloodSugarGuideResponse response = bloodSugarGuideSearchService.findGuide(principal.getUsername(), date);
return ResponseEntity.ok()
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.coniverse.dangjang.global.dto.SuccessSingleResponse;
import com.coniverse.dangjang.global.validator.ValidLocalDate;

import given.apiversion.core.annotation.ApiVersion;
import lombok.RequiredArgsConstructor;

/**
Expand All @@ -23,10 +24,10 @@
* @author EVE
* @since 1.0.0
*/
@RequestMapping("/api/guide")
@RestController
@RequiredArgsConstructor
@Validated
@RequestMapping("/guide")
public class GuideController {
private final DayGuideService dayGuideService;

Expand All @@ -36,11 +37,29 @@ public class GuideController {
* @param date 조회날짜
* @author EVE
* @since 1.0.0
* @deprecated 1.6.0
*/
@Deprecated(since = "1.6.0")
@GetMapping
public ResponseEntity<SuccessSingleResponse<DayGuideResponse>> getDayGuide(@ValidLocalDate @RequestParam String date,
@AuthenticationPrincipal User principal) {
DayGuideResponse dayGuideResponse = dayGuideService.getDayGuide(principal.getUsername(), date);
return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), dayGuideResponse));
}

/**
* 하루 요약 가이드를 조회하여 전달한다
*
* @param date 조회날짜
* @author EVE
* @since 1.6.0
*/
@ApiVersion("1")
@GetMapping
public ResponseEntity<SuccessSingleResponse<DayGuideResponse>> getDayGuideV1(@ValidLocalDate @RequestParam String date,
@AuthenticationPrincipal User principal) {
DayGuideResponse dayGuideResponse = dayGuideService.getDayGuide(principal.getUsername(), date);
return ResponseEntity.ok()
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), dayGuideResponse));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.coniverse.dangjang.global.dto.SuccessSingleResponse;
import com.coniverse.dangjang.global.validator.ValidLocalDate;

import given.apiversion.core.annotation.ApiVersion;
import lombok.RequiredArgsConstructor;

/**
Expand All @@ -27,7 +28,7 @@
@RestController
@RequiredArgsConstructor
@Validated
@RequestMapping("/api/guide/exercise")
@RequestMapping("/guide/exercise")
public class ExerciseGuideController {
private final ExerciseGuideSearchService exerciseGuideSearchService;

Expand All @@ -38,13 +39,31 @@ public class ExerciseGuideController {
* @param principal 유저 정보
* @return 운동 가이드 응답
* @since 1.0.0
* @deprecated 1.6.0
*/

@Deprecated(since = "1.6.0")
@GetMapping
public ResponseEntity<SuccessSingleResponse<ExerciseGuideResponse>> get(@ValidLocalDate @RequestParam String date,
@AuthenticationPrincipal User principal) {
ExerciseGuideResponse response = exerciseGuideSearchService.findGuide(principal.getUsername(), date);
return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response));
return ResponseEntity.ok()
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response));
}

/**
* 운동 조회
*
* @param date 조회하는 날짜
* @param principal 유저 정보
* @return 운동 가이드 응답
* @since 1.6.0
*/
@ApiVersion("1")
@GetMapping
public ResponseEntity<SuccessSingleResponse<ExerciseGuideResponse>> getExerciseGuideV1(@ValidLocalDate @RequestParam String date,
@AuthenticationPrincipal User principal) {
ExerciseGuideResponse response = exerciseGuideSearchService.findGuide(principal.getUsername(), date);
return ResponseEntity.ok()
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response));
}
}
Loading

0 comments on commit 904caed

Please sign in to comment.