Skip to content

Commit

Permalink
Merge pull request #151 from MADA-UMC/server-blue
Browse files Browse the repository at this point in the history
refactor: 통계 API 수정 & 주소 수정 & 에러 코드 추가
  • Loading branch information
yujiyea authored Oct 17, 2024
2 parents e60aa1e + 84ef4b3 commit cc6deef
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 111 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ dependencies {
testImplementation 'org.springframework.security:spring-security-test'
testImplementation 'org.projectlombok:lombok:1.18.26'

//ssh tunneling
// jsch 라이브러리, for ssh tunneling
implementation 'com.github.mwiede:jsch:0.2.16'
// application.yml의 환경 변수를 class에서 사용하기 위한 라이브러리
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'

//jwt
runtimeOnly("io.jsonwebtoken:jjwt-jackson:0.11.5")
implementation("io.jsonwebtoken:jjwt-api:0.11.5")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,13 @@ public void onAuthenticationSuccess(HttpServletRequest request, HttpServletRespo

private String makeRedirectUrl(String accessToken, boolean newUser){
if(newUser){ //회원가입한 유저라면 닉네임 입력받는 곳으로 리다이렉트
return UriComponentsBuilder.fromUriString("http://www.madaumc.store/user/signup") //"http://localhost:8080/login/oauth2/code/google"
return UriComponentsBuilder.fromUriString("http://www.madaumc.shop/user/signup")
//return UriComponentsBuilder.fromUriString("http://www.madaumc.store/user/signup") //"http://localhost:8080/login/oauth2/code/google"
.queryParam("token", accessToken)
.build().toUriString();
}
return UriComponentsBuilder.fromUriString("http://www.madaumc.store/user/test") //"http://localhost:8080/login/oauth2/code/google"
return UriComponentsBuilder.fromUriString("http://www.madaumc.shop/user/test")
// return UriComponentsBuilder.fromUriString("http://www.madaumc.store/user/test") //"http://localhost:8080/login/oauth2/code/google"
.queryParam("token", accessToken)
.build().toUriString();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/umc/mada/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {

.and()
.logout()
.logoutSuccessUrl("http://localhost:8080/oauth2/authorization/naver")
.logoutSuccessUrl("http://localhost:8080/oauth2/authorization/naver") //TODO: 이거 우리 서버 url로 바꿔야 함

.and()
.oauth2Login(oauth2 -> oauth2
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/umc/mada/exception/ControllerAdvice.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public ResponseEntity<ErrorResponse> testErrorHandler(final ServerInternalExcept
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(errorResponse);
}

@ExceptionHandler(DuplicationItemException.class)
public ResponseEntity<ErrorResponse> duplicateItemHandler(final DuplicationItemException e){
return ResponseEntity.status(HttpStatus.CONFLICT).body(new ErrorResponse(e.getMessage()));
}

// @ExceptionHandler(Exception.class)
// private ResponseEntity<ErrorResponse> unExpectedException(final Exception e){ //TODO: final HttpServletRequest request이거 추가해서 에러로그를 띄우기
// return ResponseEntity.internalServerError().body(new ErrorResponse("예상치 못한 서버 에러가 발생했습니다."));
Expand Down
172 changes: 86 additions & 86 deletions src/main/java/com/umc/mada/todo/dto/StatisticsResponseDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.util.List;
import java.util.stream.Collectors;
import java.util.Collections;

@Builder
@Getter
Expand All @@ -29,99 +28,100 @@ public class StatisticsResponseDto {

public static StatisticsResponseDto ofDay(List<CategoryStatisticsVO> categoryStatisticsVOList, PreviousCategoryStatisticsVO previousCategoryStatisticsVO,
List<TodoBarGraphStatisticsVO> todoBarGraphStatisticsVOList, int totalCount, List<AchievementRateStatisticsVO> achievementRateStatisticsVOList){
if (!categoryStatisticsVOList.isEmpty()) {
//각 list의 index 0은 오늘, 1은 어제이다.
return StatisticsResponseDto.builder()
.categoryStatistics(categoryStatisticsVOList.stream().map(vo -> CategoryStatisticsDto.of(vo.getCategoryName(), vo.getColor(), vo.getRate())).collect(Collectors.toList()))
.mostCategory(categoryStatisticsVOList.get(0).getCategoryName())
.nowCategoryCount(categoryStatisticsVOList.get(0).getCount())
.beforeCategoryCount(previousCategoryStatisticsVO.getCount())
.todoStatistics(todoBarGraphStatisticsVOList.stream().map(vo -> TodoStatisticsDto.of(vo.getTodoDate(), vo.getCount())).collect(Collectors.toList()))
.nowTotalCount(totalCount)
.nowCountCompleted(todoBarGraphStatisticsVOList.get(0).getCount())
.diffCount(todoBarGraphStatisticsVOList.get(0).getCount() - todoBarGraphStatisticsVOList.get(1).getCount())
.achievementStatistics(achievementRateStatisticsVOList.stream().map(vo -> AchievementStatisticsDto.of(vo.getDate(), vo.getRate())).collect(Collectors.toList()))
.nowAchievementRate(achievementRateStatisticsVOList.get(0).getRate() - achievementRateStatisticsVOList.get(1).getRate())
.nowCountCompletedA(achievementRateStatisticsVOList.get(0).getCount())
.build();
} else{
return StatisticsResponseDto.builder()
.categoryStatistics(Collections.emptyList())
.mostCategory("기본 카테고리")
.nowCategoryCount(0)
.beforeCategoryCount(0)
.todoStatistics(Collections.emptyList())
.nowTotalCount(0)
.nowCountCompleted(0)
.diffCount(0)
.achievementStatistics(Collections.emptyList())
.nowAchievementRate(0.0f)
.nowCountCompletedA(0.0f)
.build();
}
float diffCount = calculateDiffCount(todoBarGraphStatisticsVOList);
float nowAchievementRate = calculateNowAchievementRate(achievementRateStatisticsVOList);

return StatisticsResponseDto.builder()
.categoryStatistics(categoryStatisticsVOList.stream().map(vo -> CategoryStatisticsDto.of(vo.getCategoryName(), vo.getColor(), vo.getRate())).collect(Collectors.toList()))
.mostCategory(categoryStatisticsVOList.get(0).getCategoryName())
.nowCategoryCount(categoryStatisticsVOList.get(0).getCount())
.beforeCategoryCount(previousCategoryStatisticsVO.getCount())
.todoStatistics(todoBarGraphStatisticsVOList.stream().map(vo -> TodoStatisticsDto.of(vo.getTodoDate(), vo.getCount())).collect(Collectors.toList()))
.nowTotalCount(totalCount)
.nowCountCompleted(todoBarGraphStatisticsVOList.get(0).getCount())
.diffCount(diffCount)
.achievementStatistics(achievementRateStatisticsVOList.stream().map(vo -> AchievementStatisticsDto.of(vo.getDate(), vo.getRate())).collect(Collectors.toList()))
.nowAchievementRate(nowAchievementRate)
.nowCountCompletedA(achievementRateStatisticsVOList.get(0).getCount())
.build();
}

public static StatisticsResponseDto ofWeek(List<CategoryStatisticsVO> categoryStatisticsVOList, int totalCount, PreviousCategoryStatisticsVO previousCategoryStatisticsVO,
List<WeeklyBarGraphAndRateStatisticsVO> weeklyBarGraphAndRateStatisticsVOList){
if (!categoryStatisticsVOList.isEmpty()) {
return StatisticsResponseDto.builder()
.categoryStatistics(categoryStatisticsVOList.stream().map(vo -> CategoryStatisticsDto.of(vo.getCategoryName(), vo.getColor(), vo.getRate())).collect(Collectors.toList()))
.mostCategory(categoryStatisticsVOList.get(0).getCategoryName())
.nowCategoryCount(categoryStatisticsVOList.get(0).getCount())
.beforeCategoryCount(previousCategoryStatisticsVO.getCount())
.todoStatistics(weeklyBarGraphAndRateStatisticsVOList.stream().map(vo -> TodoStatisticsDto.of(vo.getStartDate(), vo.getEndDate(), vo.getCount())).collect(Collectors.toList()))
.nowTotalCount(totalCount)
.nowCountCompleted(weeklyBarGraphAndRateStatisticsVOList.get(0).getCount())
.diffCount(weeklyBarGraphAndRateStatisticsVOList.get(0).getCount() - weeklyBarGraphAndRateStatisticsVOList.get(1).getCount())
.achievementStatistics(weeklyBarGraphAndRateStatisticsVOList.stream().map(vo -> AchievementStatisticsDto.of(vo.getStartDate(), vo.getEndDate(), vo.getRate())).collect(Collectors.toList()))
.nowAchievementRate(weeklyBarGraphAndRateStatisticsVOList.get(0).getRate() - weeklyBarGraphAndRateStatisticsVOList.get(1).getRate())
.nowCountCompletedA(weeklyBarGraphAndRateStatisticsVOList.get(0).getCount())
.build();
} else{
return StatisticsResponseDto.builder()
.categoryStatistics(Collections.emptyList())
.mostCategory("기본 카테고리")
.nowCategoryCount(0)
.beforeCategoryCount(0)
.todoStatistics(Collections.emptyList())
.nowTotalCount(0)
.nowCountCompleted(0)
.diffCount(0)
.achievementStatistics(Collections.emptyList())
.nowAchievementRate(0.0f)
.nowCountCompletedA(0.0f)
.build();
}
float diffCount = calculateDiffCount(weeklyBarGraphAndRateStatisticsVOList);
float nowAchievementRate = calculateNowAchievementRate(weeklyBarGraphAndRateStatisticsVOList);

return StatisticsResponseDto.builder()
.categoryStatistics(categoryStatisticsVOList.stream().map(vo -> CategoryStatisticsDto.of(vo.getCategoryName(), vo.getColor(), vo.getRate())).collect(Collectors.toList()))
.mostCategory(categoryStatisticsVOList.get(0).getCategoryName())
.nowCategoryCount(categoryStatisticsVOList.get(0).getCount())
.beforeCategoryCount(previousCategoryStatisticsVO.getCount())
.todoStatistics(weeklyBarGraphAndRateStatisticsVOList.stream().map(vo -> TodoStatisticsDto.of(vo.getStartDate(), vo.getEndDate(), vo.getCount())).collect(Collectors.toList()))
.nowTotalCount(totalCount)
.nowCountCompleted(weeklyBarGraphAndRateStatisticsVOList.get(0).getCount())
.diffCount(diffCount)
.achievementStatistics(weeklyBarGraphAndRateStatisticsVOList.stream().map(vo -> AchievementStatisticsDto.of(vo.getStartDate(), vo.getEndDate(), vo.getRate())).collect(Collectors.toList()))
.nowAchievementRate(nowAchievementRate)
.nowCountCompletedA(weeklyBarGraphAndRateStatisticsVOList.get(0).getCount())
.build();
}

public static StatisticsResponseDto ofMonth(List<CategoryStatisticsVO> categoryStatisticsVOList, int totalCount, PreviousCategoryStatisticsVO previousCategoryStatisticsVO,
List<MonthlyBarGraphAndRateStatisticsVO> monthlyBarGraphAndRateStatisticsVOList){
if (!categoryStatisticsVOList.isEmpty()){
return StatisticsResponseDto.builder()
.categoryStatistics(categoryStatisticsVOList.stream().map(vo -> CategoryStatisticsDto.of(vo.getCategoryName(), vo.getColor(), vo.getRate())).collect(Collectors.toList()))
.mostCategory(categoryStatisticsVOList.get(0).getCategoryName())
.nowCategoryCount(categoryStatisticsVOList.get(0).getCount())
.beforeCategoryCount(previousCategoryStatisticsVO.getCount())
.todoStatistics(monthlyBarGraphAndRateStatisticsVOList.stream().map(vo -> TodoStatisticsDto.of(vo.getMonthDate(), vo.getCount())).collect(Collectors.toList()))
.nowTotalCount(totalCount)
.nowCountCompleted(monthlyBarGraphAndRateStatisticsVOList.get(0).getCount())
.diffCount(monthlyBarGraphAndRateStatisticsVOList.get(0).getCount() - monthlyBarGraphAndRateStatisticsVOList.get(1).getCount())
.achievementStatistics(monthlyBarGraphAndRateStatisticsVOList.stream().map(vo-> AchievementStatisticsDto.of(vo.getMonthDate(), vo.getRate())).collect(Collectors.toList()))
.nowAchievementRate(monthlyBarGraphAndRateStatisticsVOList.get(0).getRate() - monthlyBarGraphAndRateStatisticsVOList.get(1).getRate())
.build();
} else{
return StatisticsResponseDto.builder()
.categoryStatistics(Collections.emptyList())
.mostCategory("기본 카테고리")
.nowCategoryCount(0)
.beforeCategoryCount(0)
.todoStatistics(Collections.emptyList())
.nowTotalCount(0)
.nowCountCompleted(0)
.diffCount(0)
.achievementStatistics(Collections.emptyList())
.nowAchievementRate(0.0f)
.build();
float diffCount = calculateDiffCount(monthlyBarGraphAndRateStatisticsVOList);
float nowAchievementRate = calculateNowAchievementRate(monthlyBarGraphAndRateStatisticsVOList);

return StatisticsResponseDto.builder()
.categoryStatistics(categoryStatisticsVOList.stream().map(vo -> CategoryStatisticsDto.of(vo.getCategoryName(), vo.getColor(), vo.getRate())).collect(Collectors.toList()))
.mostCategory(categoryStatisticsVOList.get(0).getCategoryName())
.nowCategoryCount(categoryStatisticsVOList.get(0).getCount())
.beforeCategoryCount(previousCategoryStatisticsVO.getCount())
.todoStatistics(monthlyBarGraphAndRateStatisticsVOList.stream().map(vo -> TodoStatisticsDto.of(vo.getMonthDate(), vo.getCount())).collect(Collectors.toList()))
.nowTotalCount(totalCount)
.nowCountCompleted(monthlyBarGraphAndRateStatisticsVOList.get(0).getCount())
.diffCount(diffCount)
.achievementStatistics(monthlyBarGraphAndRateStatisticsVOList.stream().map(vo-> AchievementStatisticsDto.of(vo.getMonthDate(), vo.getRate())).collect(Collectors.toList()))
.nowAchievementRate(nowAchievementRate)
.build();
}

private static <T> float calculateNowAchievementRate(List<T> statisticsVOList) {
if (statisticsVOList.size() > 1) {
if (statisticsVOList.get(0) instanceof AchievementRateStatisticsVO) {
return ((AchievementRateStatisticsVO) statisticsVOList.get(0)).getRate() - ((AchievementRateStatisticsVO) statisticsVOList.get(1)).getRate();
} else if (statisticsVOList.get(0) instanceof WeeklyBarGraphAndRateStatisticsVO) {
return ((WeeklyBarGraphAndRateStatisticsVO) statisticsVOList.get(0)).getRate() - ((WeeklyBarGraphAndRateStatisticsVO) statisticsVOList.get(1)).getRate();
} else if (statisticsVOList.get(0) instanceof MonthlyBarGraphAndRateStatisticsVO) {
return ((MonthlyBarGraphAndRateStatisticsVO) statisticsVOList.get(0)).getRate() - ((MonthlyBarGraphAndRateStatisticsVO) statisticsVOList.get(1)).getRate();
}
}
if (statisticsVOList.get(0) instanceof AchievementRateStatisticsVO) {
return ((AchievementRateStatisticsVO) statisticsVOList.get(0)).getRate();
} else if (statisticsVOList.get(0) instanceof WeeklyBarGraphAndRateStatisticsVO) {
return ((WeeklyBarGraphAndRateStatisticsVO) statisticsVOList.get(0)).getRate();
} else if (statisticsVOList.get(0) instanceof MonthlyBarGraphAndRateStatisticsVO) {
return ((MonthlyBarGraphAndRateStatisticsVO) statisticsVOList.get(0)).getRate();
}
return 0;
}

private static <T> float calculateDiffCount(List<T> statisticsVOList) {
if (statisticsVOList.size() > 1) {
if (statisticsVOList.get(0) instanceof TodoBarGraphStatisticsVO) {
return ((TodoBarGraphStatisticsVO) statisticsVOList.get(0)).getCount() - ((TodoBarGraphStatisticsVO) statisticsVOList.get(1)).getCount();
} else if (statisticsVOList.get(0) instanceof WeeklyBarGraphAndRateStatisticsVO) {
return ((WeeklyBarGraphAndRateStatisticsVO) statisticsVOList.get(0)).getCount() - ((WeeklyBarGraphAndRateStatisticsVO) statisticsVOList.get(1)).getCount();
} else if (statisticsVOList.get(0) instanceof MonthlyBarGraphAndRateStatisticsVO) {
return ((MonthlyBarGraphAndRateStatisticsVO) statisticsVOList.get(0)).getCount() - ((MonthlyBarGraphAndRateStatisticsVO) statisticsVOList.get(1)).getCount();
}
}
if (statisticsVOList.get(0) instanceof TodoBarGraphStatisticsVO) {
return ((TodoBarGraphStatisticsVO) statisticsVOList.get(0)).getCount();
} else if (statisticsVOList.get(0) instanceof WeeklyBarGraphAndRateStatisticsVO) {
return ((WeeklyBarGraphAndRateStatisticsVO) statisticsVOList.get(0)).getCount();
} else if (statisticsVOList.get(0) instanceof MonthlyBarGraphAndRateStatisticsVO) {
return ((MonthlyBarGraphAndRateStatisticsVO) statisticsVOList.get(0)).getCount();
}
return 0;
}
}
Loading

0 comments on commit cc6deef

Please sign in to comment.