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

재배포 "hotfix v1.3.0" #77

Merged
merged 1 commit into from
Nov 3, 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
1 change: 1 addition & 0 deletions src/lombok.config
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Value
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.web.bind.annotation.RestController;

import com.coniverse.dangjang.domain.auth.dto.request.KakaoLoginRequest;
import com.coniverse.dangjang.domain.auth.dto.request.LogoutFcmTokenRequest;
import com.coniverse.dangjang.domain.auth.dto.request.NaverLoginRequest;
import com.coniverse.dangjang.domain.auth.dto.response.LoginResponse;
import com.coniverse.dangjang.domain.auth.service.OauthLoginService;
Expand All @@ -34,29 +35,27 @@ public class LoginController {
private static String headerKeyAuthorization = "Authorization";

/**
* @param params 카카오 accessToken
* @param request request에서 fcmToken header가 필요
* @param params 카카오 accessToken
* @return ResponseEntity 로그인을 성공하면, JWT TOKEN과 사용자 정보(nickname, auth id)를 전달한다.
* @since 1.0.0
*/
@PostMapping("/kakao")
public ResponseEntity<SuccessSingleResponse<LoginResponse>> loginKakao(@Valid @RequestBody KakaoLoginRequest params, HttpServletRequest request) {
LoginResponse loginResponse = oauthLoginService.login(params, request.getHeader(headerKeyFcmToken));
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)
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), loginResponse));
}

/**
* @param params 네이버 accessToken
* @param request request에서 fcmToken header가 필요
* @param params 네이버 accessToken
* @return ResponseEntity 로그인을 성공하면, JWT TOKEN과 사용자 정보(nickname, auth id)를 전달한다.
* @since 1.0.0
*/
@PostMapping("/naver")
public ResponseEntity<SuccessSingleResponse<LoginResponse>> loginNaver(@Valid @RequestBody NaverLoginRequest params, HttpServletRequest request) {
LoginResponse loginResponse = oauthLoginService.login(params, request.getHeader(headerKeyFcmToken));
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)
Expand All @@ -81,12 +80,13 @@ public ResponseEntity<SuccessSingleResponse<?>> reissue(HttpServletRequest reque
/**
* 로그아웃
*
* @param request 요청
* @param request HttpServletRequest oauthId
* @param logoutFcmTokenRequest fcmToken
* @since 1.1.0
*/
@PostMapping("/logout")
public ResponseEntity<SuccessSingleResponse> logout(HttpServletRequest request) {
oauthLoginService.logout(request.getHeader(headerKeyAuthorization), request.getHeader(headerKeyFcmToken));
public ResponseEntity<SuccessSingleResponse> logout(HttpServletRequest request, @RequestBody LogoutFcmTokenRequest logoutFcmTokenRequest) {
oauthLoginService.logout(request.getHeader(headerKeyAuthorization), logoutFcmTokenRequest.fcmToken());
return ResponseEntity.ok()
.body(new SuccessSingleResponse<>(HttpStatus.OK.getReasonPhrase(), null));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.coniverse.dangjang.domain.auth.dto.request;

/**
* fcmToken을 받아오는 DTO
*
* @author EVE
* @since 1.3.0
*/
public record LogoutFcmTokenRequest(String fcmToken) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,14 @@ public DefaultOauthLoginService(AuthTokenGenerator authTokenGenerator, UserSearc
}

/**
* @param params 카카오,네이버 accessToken
* @param fcmToken notifiaction 디바이스 토큰
* @param params 카카오,네이버 accessToken
* @return Content 로그인을 성공하면, JWT TOKEN과 사용자 정보(nickname, authID)를 전달한다.
* @since 1.0.0
*/
@Override
public LoginResponse login(OauthLoginRequest params, String fcmToken) {
public LoginResponse login(OauthLoginRequest params) {
OAuthInfoResponse oAuthInfoResponse = request(params);
User user = userSearchService.findUserByOauthId(oAuthInfoResponse.getOauthId());
notificationService.saveFcmToken(fcmToken, user.getOauthId());
HealthConnect healthConnect = userSearchService.findInterlockHealthConnect(user.getOauthId());
user.verifyActiveUser();
return new LoginResponse(user.getNickname(), false, healthConnect.isConnecting());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @since 1.0.0
*/
public interface OauthLoginService {
LoginResponse login(OauthLoginRequest params, String fcmToken);
LoginResponse login(OauthLoginRequest params);

String getAuthToken(String nickname);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,26 @@ private void minusAlertCount(String alert) {
.findFirst()
.ifPresent(TodayGuide::minusCount);
}

/**
* 서브 가이드를 삭제한다.
*
* @param type 서브 가이드 타입
* @since 1.3.0
*/
public void removeSubGuide(CommonCode type) {
SubGuide subGuide = getSubGuide(type);
this.subGuides.remove(subGuide);
minusAlertCount(subGuide.getAlert());
}

/**
* 서브 가이드가 존재하는지 확인한다.
*
* @return 서브 가이드가 존재하면 true, 존재하지 않으면 false
* @since 1.3.0
*/
public boolean existsSubGuide() {
return !this.subGuides.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.coniverse.dangjang.domain.guide.bloodsugar.service;

import java.time.LocalDate;

import org.springframework.stereotype.Service;

import com.coniverse.dangjang.domain.analysis.dto.AnalysisData;
Expand Down Expand Up @@ -34,8 +36,6 @@ public class BloodSugarGuideGenerateService implements GuideGenerateService {

/**
* 서브 가이드를 생성해서 혈당 가이드에 저장한다.
* <p>
* 혈당 가이드가 존재하면 새로운 서브 가이드를 추가하고, 존재하지 않으면 혈당 가이드를 생성하여 서브 가이드를 추가한다.
*
* @param analysisData 혈당 분석 데이터
* @return 서브 가이드 응답
Expand All @@ -44,19 +44,29 @@ public class BloodSugarGuideGenerateService implements GuideGenerateService {
@Override
public GuideResponse createGuide(AnalysisData analysisData) {
BloodSugarAnalysisData data = (BloodSugarAnalysisData)analysisData;
BloodSugarGuide guide;
try {
guide = bloodSugarGuideSearchService.findByUserIdAndCreatedAt(data.getOauthId(), data.getCreatedAt());
} catch (GuideNotFoundException e) {
guide = mapper.toDocument(data);
}
BloodSugarGuide guide = getGuide(data);
GuideFormat guideFormat = bloodSugarGuideFormatFactory.createGuideFormat(data);
SubGuide subGuide = mapper.toSubGuide(data, guideFormat);
guide.addSubGuide(subGuide);
bloodSugarGuideRepository.save(guide);
return mapper.toSubGuideResponse(subGuide, guide.getTodayGuides());
}

/**
* 혈당 가이드가 존재하면 그대로 반환하고, 존재하지 않으면 새로 생성해서 반환한다.
*
* @param data 혈당 분석 데이터
* @return 혈당 가이드
* @since 1.3.0
*/
private BloodSugarGuide getGuide(BloodSugarAnalysisData data) {
try {
return bloodSugarGuideSearchService.findByUserIdAndCreatedAt(data.getOauthId(), data.getCreatedAt());
} catch (GuideNotFoundException e) {
return mapper.toDocument(data);
}
}

/**
* 단위가 변경된 서브 가이드를 업데이트해서 혈당 가이드에 저장한다.
*
Expand Down Expand Up @@ -97,6 +107,25 @@ public GuideResponse updateGuideWithType(AnalysisData analysisData, CommonCode p
return mapper.toSubGuideResponse(subGuide, guide.getTodayGuides());
}

/**
* 서브 가이드를 삭제한다. 서브 가이드가 존재하지 않으면 혈당 가이드를 삭제한다.
*
* @param oauthId 유저 PK
* @param createdAt 생성일자
* @param type 타입
* @since 1.3.0
*/
@Override
public void removeGuide(String oauthId, LocalDate createdAt, CommonCode type) {
BloodSugarGuide guide = bloodSugarGuideSearchService.findByUserIdAndCreatedAt(oauthId, createdAt);
guide.removeSubGuide(type);
if (guide.existsSubGuide()) {
bloodSugarGuideRepository.save(guide);
return;
}
bloodSugarGuideRepository.delete(guide);
}

@Override
public GroupCode getGroupCode() {
return GroupCode.BLOOD_SUGAR;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.coniverse.dangjang.domain.guide.common.service;

import java.time.LocalDate;

import com.coniverse.dangjang.domain.analysis.dto.AnalysisData;
import com.coniverse.dangjang.domain.code.enums.CommonCode;
import com.coniverse.dangjang.domain.code.enums.GroupCode;
Expand All @@ -20,5 +22,7 @@ default GuideResponse updateGuideWithType(AnalysisData analysisData, CommonCode
throw new UnsupportedOperationException("잘못된 메서드 호출입니다.");
}

void removeGuide(String oauthId, LocalDate createdAt, CommonCode type);

GroupCode getGroupCode();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.coniverse.dangjang.domain.guide.common.service;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
Expand Down Expand Up @@ -34,8 +35,7 @@ public GuideService(List<GuideGenerateService> guideGenerateServiceMap) {
* @since 1.0.0
*/
public GuideResponse createGuide(AnalysisData analysisData) {
GroupCode groupCode = GroupCode.findByCode(analysisData.getType());
GuideGenerateService guideGenerateService = findGuideGenerateService(groupCode);
GuideGenerateService guideGenerateService = findGuideGenerateService(analysisData.getType());
return guideGenerateService.createGuide(analysisData);
}

Expand All @@ -45,8 +45,7 @@ public GuideResponse createGuide(AnalysisData analysisData) {
* @since 1.0.0
*/
public GuideResponse updateGuide(AnalysisData analysisData) {
GroupCode groupCode = GroupCode.findByCode(analysisData.getType());
GuideGenerateService guideGenerateService = findGuideGenerateService(groupCode);
GuideGenerateService guideGenerateService = findGuideGenerateService(analysisData.getType());
return guideGenerateService.updateGuide(analysisData);
}

Expand All @@ -56,18 +55,28 @@ public GuideResponse updateGuide(AnalysisData analysisData) {
* @since 1.0.0
*/
public GuideResponse updateGuideWithType(AnalysisData analysisData, CommonCode prevType) {
GroupCode groupCode = GroupCode.findByCode(analysisData.getType());
GuideGenerateService guideGenerateService = findGuideGenerateService(groupCode);
GuideGenerateService guideGenerateService = findGuideGenerateService(analysisData.getType());
return guideGenerateService.updateGuideWithType(analysisData, prevType);
}

/**
* 가이드를 삭제한다.
*
* @since 1.3.0
*/
public void removeGuide(String oauthId, LocalDate createdAt, CommonCode type) {
GuideGenerateService guideGenerateService = findGuideGenerateService(type);
guideGenerateService.removeGuide(oauthId, createdAt, type);
}

/**
* 그룹코드로 가이드 생성 서비스를 찾는다.
*
* @see GroupCode
* @since 1.0.0
*/
private GuideGenerateService findGuideGenerateService(GroupCode groupCode) {
private GuideGenerateService findGuideGenerateService(CommonCode type) {
GroupCode groupCode = GroupCode.findByCode(type);
return guideGenerateServiceMap.get(groupCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@

import org.springframework.data.mongodb.core.mapping.Document;

import com.coniverse.dangjang.domain.code.enums.CommonCode;

import jakarta.persistence.Id;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
* 운동 가이드 Document
*
* @author EVE
* @since 1.0.0
*/
@Setter
@Getter
@Document
@NoArgsConstructor
public class ExerciseGuide {
public class ExerciseGuide { // TODO 걸음 가이드, 칼로리 가이드로 분리해서 리팩토링
@Id
private String id;
private String oauthId;
private int needStepByTTS;
private int needStepByTTS; // TODO 걸음 수 관련 필드 -> 객체로 묶기
private int needStepByLastWeek;
private LocalDate createdAt;
private String content;
Expand Down Expand Up @@ -69,14 +69,24 @@ public void changeAboutWalk(int needStepByTTS, int needStepByLastWeek, String co
* <p>
* 기존에 존재하는 운동 칼로리를 삭제하고, 새로운 운동 칼로리를 추가한다.
*
* @param updateExerciseCalorie 운동칼로리 객체
* @param updatedExerciseCalorie 운동칼로리 객체
* @since 1.0.0
*/
public void changeExerciseCalories(ExerciseCalorie updateExerciseCalorie) {
public void changeExerciseCalories(ExerciseCalorie updatedExerciseCalorie) {
removeExerciseCalorie(updatedExerciseCalorie.type());
exerciseCalories.add(updatedExerciseCalorie);
}

/**
* 운동 칼로리를 삭제한다.
*
* @param type 운동 타입
* @since 1.3.0
*/
public void removeExerciseCalorie(CommonCode type) {
exerciseCalories.stream()
.filter(existExerciseCalorie -> existExerciseCalorie.type().equals(updateExerciseCalorie.type()))
.filter(exerciseCalorie -> exerciseCalorie.type().equals(type))
.findFirst()
.ifPresent(existExerciseCalorie -> exerciseCalories.remove(existExerciseCalorie));
exerciseCalories.add(updateExerciseCalorie);
.ifPresent(exerciseCalorie -> exerciseCalories.remove(exerciseCalorie));
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.coniverse.dangjang.domain.guide.exercise.service;

import java.time.LocalDate;
import java.util.List;

import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -27,7 +28,7 @@
*/
@Service
@RequiredArgsConstructor
public class ExerciseGuideGenerateService implements GuideGenerateService {
public class ExerciseGuideGenerateService implements GuideGenerateService { // TODO 리팩토링 필수
private final ExerciseGuideSearchService exerciseGuideSearchService;
private final ExerciseGuideMapper exerciseGuideMapper;
private final ExerciseGuideRepository exerciseGuideRepository;
Expand Down Expand Up @@ -106,6 +107,36 @@ public GuideResponse updateGuide(AnalysisData analysisData) {
return exerciseGuideMapper.toResponse(exerciseGuideRepository.save(updateExerciseGuide));
}

/**
* 걸음 수 가이드 또는 칼로리 가이드를 삭제한다.
*
* @since 1.3.0
*/
@Override
public void removeGuide(String oauthId, LocalDate createdAt, CommonCode type) {
ExerciseGuide exerciseGuide = exerciseGuideSearchService.findByOauthIdAndCreatedAt(oauthId, createdAt);
if (type.equals(CommonCode.STEP_COUNT)) {
exerciseGuide.changeAboutWalk(0, 0, null, null, 0);
removeEmptyExerciseGuide(exerciseGuide);
return;
}
exerciseGuide.removeExerciseCalorie(type);
removeEmptyExerciseGuide(exerciseGuide);
}

/**
* 운동 가이드가 비어있으면 삭제한다.
*
* @since 1.3.0
*/
private void removeEmptyExerciseGuide(ExerciseGuide exerciseGuide) {
if (exerciseGuide.getContent() == null && exerciseGuide.getExerciseCalories().isEmpty()) {
exerciseGuideRepository.delete(exerciseGuide);
return;
}
exerciseGuideRepository.save(exerciseGuide);
}

@Override
public GroupCode getGroupCode() {
return GroupCode.EXERCISE;
Expand Down
Loading