Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] deprecated 코드 제거, 혈당 가이드 중복 처리 #88

Merged
merged 13 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,6 @@ public class LoginController {
private static final String AUTHORIZATION = "Authorization";
private final OauthLoginService oauthLoginService;

/**
* @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(ACCESS_TOKEN.toString(), accessToken)
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), loginResponse));
}

/**
* 카카오 로그인
*
Expand All @@ -66,22 +50,6 @@ public ResponseEntity<SuccessSingleResponse<LoginResponse>> loginKakaoV1(@Valid
.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(ACCESS_TOKEN, accessToken)
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), loginResponse));
}

/**
* 네이버 로그인
*
Expand All @@ -99,23 +67,6 @@ public ResponseEntity<SuccessSingleResponse<LoginResponse>> loginNaverV1(@Valid
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), loginResponse));
}

/**
* refreshToken으로 AuthToken 재발급
*
* @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(AUTHORIZATION));
return ResponseEntity.ok()
.header(ACCESS_TOKEN, newAccessToken)
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null));
}

/**
* refresh token으로 access token 재발급
*
Expand All @@ -132,22 +83,6 @@ public ResponseEntity<SuccessSingleResponse<?>> reissueV1(HttpServletRequest req
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null));
}

/**
* 로그아웃
*
* @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(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 @@ -31,23 +31,6 @@
public class BloodSugarGuideController {
private final BloodSugarGuideSearchService bloodSugarGuideSearchService;

/**
* 혈당 가이드를 조회한다.
*
* @param date 조회할 일자
* @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));
}

/**
* 혈당 가이드를 조회한다.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import com.coniverse.dangjang.domain.analysis.enums.Alert;
import com.coniverse.dangjang.domain.code.enums.CommonCode;
import com.coniverse.dangjang.domain.guide.common.exception.GuideAlreadyExistsException;
import com.coniverse.dangjang.domain.guide.common.exception.GuideNotFoundException;

import jakarta.persistence.Id;
Expand Down Expand Up @@ -54,10 +53,12 @@ private BloodSugarGuide(String oauthId, String createdAt) {
* @since 1.0.0
*/
public void addSubGuide(SubGuide subGuide) {
verifySubGuideNonExistent(subGuide.getType());
if (isDuplicatedSubGuide(subGuide)) {
return;
}
this.subGuides.add(subGuide);
sortSubGuides();
plusAlertCount(subGuide.getAlert());
sortSubGuides();
}

/**
Expand All @@ -80,25 +81,24 @@ public void updateSubGuide(SubGuide updatedSubGuide) {
* @since 1.0.0
*/
public void updateSubGuide(SubGuide updatedSubGuide, CommonCode prevType) {
verifySubGuideNonExistent(updatedSubGuide.getType());
if (isDuplicatedSubGuide(updatedSubGuide)) {
return;
}
SubGuide subGuide = getSubGuide(prevType);
updateAlertCount(subGuide.getAlert(), updatedSubGuide.getAlert());
subGuide.update(updatedSubGuide);
sortSubGuides();
}

/**
* 서브 가이드가 존재하는지 검증한다.
* 서브 가이드가 중복인지 확인한다.
*
* @param type 서브 가이드 타입
* @throws GuideAlreadyExistsException 이미 해당 가이드가 존재할 경우 발생한다.
* @since 1.0.0
* @param subGuide 서브 가이드
* @since 1.6.1
*/
private void verifySubGuideNonExistent(CommonCode type) {
boolean exists = this.subGuides.stream().anyMatch(guide -> guide.isSameType(type));
if (exists) {
throw new GuideAlreadyExistsException();
}
private boolean isDuplicatedSubGuide(SubGuide subGuide) {
return this.subGuides.stream()
.anyMatch(s -> s.equals(subGuide));
}

/**
Expand All @@ -111,7 +111,7 @@ private void verifySubGuideNonExistent(CommonCode type) {
*/
private SubGuide getSubGuide(CommonCode type) {
return this.subGuides.stream()
.filter(guide -> guide.isSameType(type))
.filter(s -> s.isSameType(type))
.findFirst()
.orElseThrow(GuideNotFoundException::new);
}
Expand Down Expand Up @@ -149,7 +149,7 @@ private void updateAlertCount(String prevAlert, String curAlert) {
*/
private void plusAlertCount(String alert) {
this.todayGuides.stream()
.filter(guide -> guide.isSameAlert(alert))
.filter(s -> s.isSameAlert(alert))
.findFirst()
.ifPresent(TodayGuide::plusCount);
}
Expand All @@ -162,7 +162,7 @@ private void plusAlertCount(String alert) {
*/
private void minusAlertCount(String alert) {
this.todayGuides.stream()
.filter(guide -> guide.isSameAlert(alert))
.filter(s -> s.isSameAlert(alert))
.findFirst()
.ifPresent(TodayGuide::minusCount);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,21 @@ protected void update(SubGuide subGuide) {
protected boolean isSameType(CommonCode type) {
return this.type.equals(type);
}

/**
* equals 메서드 overriding
* <p>
* 타입이 같으면 같은 서브 가이드로 취급한다.
*
* @param obj 비교할 객체
* @return 같으면 true, 다르면 false
* @since 1.6.1
*/
@Override
public boolean equals(Object obj) {
if (obj instanceof SubGuide subGuide) {
return this.type.equals(subGuide.getType());
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@
public class GuideController {
private final DayGuideService dayGuideService;

/**
* 하루 요약 가이드를 조회하여 전달한다
*
* @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));
}

/**
* 하루 요약 가이드를 조회하여 전달한다
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,6 @@
public class ExerciseGuideController {
private final ExerciseGuideSearchService exerciseGuideSearchService;

/**
* 운동 조회
*
* @param date 조회하는 날짜
* @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));
}

/**
* 운동 조회
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,6 @@
public class WeightGuideController {
private final WeightGuideSearchService weightGuideSearchService;

/**
* 날짜별 체중 가이드 조회
*
* @param date 조회하는 날짜
* @param principal 유저 정보
* @author EVE
* @since 1.0.0
* @deprecated 1.6.0
*/
@Deprecated(since = "1.6.0")
@GetMapping
public ResponseEntity<SuccessSingleResponse<WeightGuideResponse>> get(@ValidLocalDate @RequestParam String date,
@AuthenticationPrincipal User principal) {
WeightGuideResponse response = weightGuideSearchService.findGuide(principal.getUsername(), date);
return ResponseEntity.ok().body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), response));
}

/**
* 날짜별 체중 가이드 조회
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,6 @@
public class HealthConnectController {
private final HealthConnectService healthConnectService;

/**
* health connect로 받은 건강 지표 데이터를 등록한다.
*
* @param requests 건강 지표 request post dto n개
* @param principal 유저 정보
* @since 1.0.0
* @deprecated 1.6.0
*/
@Deprecated(since = "1.6.0")
@PostMapping
public ResponseEntity<SuccessSingleResponse<?>> postHealthConnect(@Valid @RequestBody HealthConnectPostRequest requests,
@AuthenticationPrincipal User principal) {
String oauthId = principal.getUsername();
healthConnectService.registerHealthConnectData(requests, oauthId);
return ResponseEntity.ok(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null));
}

/**
* health connect로 받은 건강 지표 데이터를 등록한다.
*
Expand All @@ -65,23 +48,6 @@ public ResponseEntity<SuccessSingleResponse<?>> postHealthConnectV1(@Valid @Requ
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null));
}

/**
* health connect 연동 여부를 확인한다.
*
* @param requests health connect 연동 여부 데이터
* @param principal 유저 정보
* @since 1.0.0
* @deprecated 1.6.0
*/
@Deprecated(since = "1.6.0")
@PatchMapping("/interlock")
public ResponseEntity<SuccessSingleResponse<?>> interlockHealthConnect(@Valid @RequestBody HealthConnectRegisterRequest requests,
@AuthenticationPrincipal User principal) {
String oauthId = principal.getUsername();
healthConnectService.interlockHealthConnect(requests, oauthId);
return ResponseEntity.ok(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null));
}

/**
* health connect 연동 여부를 확인한다.
*
Expand Down
Loading
Loading