Skip to content

Commit

Permalink
[hotfix] ConsumptionGoal Error 핫픽스
Browse files Browse the repository at this point in the history
[hotfix] ConsumptionGoal Error 핫픽스
  • Loading branch information
SoulTree-Lovers authored Aug 14, 2024
2 parents 89022f9 + 4741ecd commit 088aa46
Show file tree
Hide file tree
Showing 24 changed files with 851 additions and 547 deletions.
Original file line number Diff line number Diff line change
@@ -1,34 +1,41 @@
package com.bbteam.budgetbuddies.domain.category.controller;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bbteam.budgetbuddies.domain.category.dto.CategoryRequestDTO;
import com.bbteam.budgetbuddies.domain.category.dto.CategoryResponseDTO;
import com.bbteam.budgetbuddies.domain.category.service.CategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/categories")
public class CategoryController implements CategoryApi {

private final CategoryService categoryService;

@Override
@PostMapping("/add/{userId}")
public ResponseEntity<CategoryResponseDTO> createCategory(
@PathVariable Long userId,
@RequestBody CategoryRequestDTO categoryRequestDTO) {
CategoryResponseDTO response = categoryService.createCategory(userId, categoryRequestDTO);
return ResponseEntity.ok(response);
}

@Override
@GetMapping("/get/{userId}")
public ResponseEntity<List<CategoryResponseDTO>> getUserCategories(@PathVariable Long userId) {
List<CategoryResponseDTO> response = categoryService.getUserCategories(userId);
return ResponseEntity.ok(response);
}
private final CategoryService categoryService;

@Override
@PostMapping("/add/{userId}")
public ResponseEntity<CategoryResponseDTO> createCategory(
@PathVariable Long userId,
@RequestBody CategoryRequestDTO categoryRequestDTO) {
CategoryResponseDTO response = categoryService.createCategory(userId, categoryRequestDTO);
return ResponseEntity.ok(response);
}

@Override
@GetMapping("/get/{userId}")
public ResponseEntity<List<CategoryResponseDTO>> getUserCategories(@PathVariable Long userId) {
List<CategoryResponseDTO> response = categoryService.getUserCategories(userId);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.time.LocalDate;

import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;

import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalListRequestDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto;
Expand All @@ -18,27 +18,19 @@ public interface ConsumptionGoalApi {

@Operation(summary = "또래들이 가장 큰 계획을 세운 카테고리 조회 Top4 API", description = "특정 사용자의 소비 목표 카테고리별 소비 목표 금액을 조회하는 API 입니다.")
@ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")})
@Parameters({@Parameter(name = "top", description = "가장 큰 목표를 세운 카테고리의 개수를 지정합니다."),
@Parameter(name = "userId", description = "로그인 한 유저 아이디"),
@Parameters({@Parameter(name = "userId", description = "로그인 한 유저 아이디"),
@Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"),
@Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"),
@Parameter(name = "peerGender", description = "또래 성별")})
ResponseEntity<?> getTopGoalCategoriesList(int top, Long userId,
int peerAgeStart, int peerAgeEnd, String peerGender);
ResponseEntity<?> getTopConsumptionGoalCategories(Long userId, int peerAgeStart, int peerAgeEnd, String peerGender);

@Operation(summary = "또래들이 가장 큰 계획을 세운 카테고리 조회 API", description = "특정 사용자의 소비 목표 카테고리별 소비 목표 금액을 전체 조회하는 API 입니다.")
@Operation(summary = "또래들이 가장 많이 계획한 카테고리와 평균 금액 및 내 목표금액 차이 조회 API", description = "특정 사용자의 또래 소비 카테고리별 평균 목표 금액을 조회하는 API 입니다.")
@ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")})
@Parameters({@Parameter(name = "userId", description = "로그인 한 유저 아이디"),
@Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"),
@Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"),
@Parameter(name = "peerGender", description = "또래 성별")})
ResponseEntity<?> getTopGoalCategoriesPage(Long userId,
int peerAgeStart, int peerAgeEnd, String peerGender, Pageable pageable);

@Operation(summary = "또래가 가장 큰 계획을 세운 카테고리와 이번 주 사용한 금액 조회 API", description = "로그인 한 유저의 또래 중 가장 큰 소비 목표 금액을 가진 카테고리와 이번 주 사용한 금액을 조회하는 API 입니다")
@ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")})
@Parameters({@Parameter(name = "userId", description = "로그인 한 유저 아이디")})
ResponseEntity<?> getTopGoalCategory(Long userId);
ResponseEntity<?> getAllConsumptionGoalCategories(Long userId, int peerAgeStart, int peerAgeEnd, String peerGender);

@Operation(summary = "또래나이와 성별 조회 API", description = "또래나이와 성별을 조회하는 API 입니다.")
@ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")})
Expand All @@ -56,22 +48,23 @@ ResponseEntity<?> getTopGoalCategoriesPage(Long userId,
ResponseEntity<ConsumptionGoalResponseListDto> updateOrElseGenerateConsumptionGoal(Long userId,
ConsumptionGoalListRequestDto consumptionGoalListRequestDto);

@Operation(summary = "또래들이 가장 많이한 소비 카테고리 조회 Top4 API", description = "특정 사용자의 소비 카테고리별 소비 금액을 조회하는 API 입니다.")
@Operation(summary = "또래들이 가장 많이한 소비 카테고리 조회 Top3 API", description = "특정 사용자의 또래 소비 카테고리별 소비 건 수을 조회하는 API 입니다.")
@ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")})
@Parameters({@Parameter(name = "top", description = "가장 큰 소비 카테고리의 개수를 지정합니다."),
@Parameter(name = "userId", description = "로그인 한 유저 아이디"),
@Parameters({@Parameter(name = "userId", description = "로그인 한 유저 아이디"),
@Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"),
@Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"),
@Parameter(name = "peerGender", description = "또래 성별")})
ResponseEntity<?> getConsumptionGoalList(int top, Long userId, int peerAgeStart, int peerAgeEnd,
String peerGender);
ResponseEntity<?> getTopConsumptionCategories(Long userId, int peerAgeStart, int peerAgeEnd, String peerGender);

@Operation(summary = "또래들이 가장 많이한 소비 카테고리 조회 API", description = "특정 사용자의 소비 카테고리별 소비 금액을 전체 조회하는 API 입니다.")
@Operation(summary = "또래들이 가장 많이한 소비 카테고리와 평균 금액 및 내 소비금액 차이 조회 API", description = "특정 사용자의 또래 소비 카테고리별 평균 소비 금액을 조회하는 API 입니다.")
@ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")})
@Parameters({@Parameter(name = "userId", description = "로그인 한 유저 아이디"),
@Parameter(name = "peerAgeStart", description = "또래나이 시작 범위"),
@Parameter(name = "peerAgeEnd", description = "또래나이 끝 범위"),
@Parameter(name = "peerGender", description = "또래 성별")})
ResponseEntity<?> getConsumptionGoalPage(Long userId, int peerAgeStart, int peerAgeEnd, String peerGender,
Pageable pageable);
ResponseEntity<?> getAllConsumptionCategories(Long userId, int peerAgeStart, int peerAgeEnd, String peerGender);

@Operation(summary = "또래들이 가장 큰 목표로 세운 카테고리와 그 카테고리에서 이번주 사용한 금액 조회 API", description = "특정 사용자의 또래 소비 카테고리별 이번주 소비 금액을 조회하는 API 입니다.")
@ApiResponses(value = {@ApiResponse(responseCode = "COMMON200", description = "OK, 성공")})
ResponseEntity<?> getTopCategoryAndConsumptionAmount(@PathVariable Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.time.LocalDate;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -15,12 +13,12 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionAnalysisResponseDTO;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.AllConsumptionCategoryResponseDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalListRequestDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.PeerInfoResponseDTO;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopConsumptionResponseDTO;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDTO;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.PeerInfoResponseDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopCategoryConsumptionDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.TopGoalCategoryResponseDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.service.ConsumptionGoalService;

import lombok.RequiredArgsConstructor;
Expand All @@ -33,32 +31,24 @@ public class ConsumptionGoalController implements ConsumptionGoalApi {
private final ConsumptionGoalService consumptionGoalService;

@Override
@GetMapping("/top-categories/top-goal/{top}")
public ResponseEntity<?> getTopGoalCategoriesList(@PathVariable(name = "top") int top,
@RequestParam(name = "userId") Long userId,
@GetMapping("/top-categories/top-goal/4")
public ResponseEntity<?> getTopConsumptionGoalCategories(@RequestParam(name = "userId") Long userId,
@RequestParam(name = "peerAgeStart", defaultValue = "0") int peerAgeStart,
@RequestParam(name = "peerAgeEnd", defaultValue = "0") int peerAgeEnd,
@RequestParam(name = "peerGender", defaultValue = "none") String peerGender) {
List<TopGoalCategoryResponseDTO> topCategoriesList = consumptionGoalService.getTopGoalCategoriesLimit(top,
userId,
peerAgeStart, peerAgeEnd, peerGender);
List<TopGoalCategoryResponseDto> topCategoriesList = consumptionGoalService.getTopConsumptionGoalCategories(
userId, peerAgeStart, peerAgeEnd, peerGender);
return ResponseEntity.ok(topCategoriesList);
}

@GetMapping("/top-categories/top-goal")
public ResponseEntity<?> getTopGoalCategoriesPage(@RequestParam(name = "userId") Long userId,
public ResponseEntity<?> getAllConsumptionGoalCategories(@RequestParam(name = "userId") Long userId,
@RequestParam(name = "peerAgeStart", defaultValue = "0") int peerAgeStart,
@RequestParam(name = "peerAgeEnd", defaultValue = "0") int peerAgeEnd,
@RequestParam(name = "peerGender", defaultValue = "none") String peerGender, Pageable pageable) {
Page<TopGoalCategoryResponseDTO> topCategoriesPage = consumptionGoalService.getTopGoalCategories(userId,
peerAgeStart, peerAgeEnd, peerGender, pageable);
return ResponseEntity.ok(topCategoriesPage.getContent());
}

@Override
@GetMapping("/top-category/top-goal")
public ResponseEntity<?> getTopGoalCategory(@RequestParam(name = "userId") Long userId) {
ConsumptionAnalysisResponseDTO response = consumptionGoalService.getTopCategoryAndConsumptionAmount(userId);
@RequestParam(name = "peerGender", defaultValue = "none") String peerGender) {
List<AllConsumptionCategoryResponseDto> response = consumptionGoalService.getAllConsumptionGoalCategories(
userId,
peerAgeStart, peerAgeEnd, peerGender);
return ResponseEntity.ok(response);
}

Expand All @@ -68,7 +58,7 @@ public ResponseEntity<?> getPeerInfo(@RequestParam(name = "userId") Long userId,
@RequestParam(name = "peerAgeStart", defaultValue = "0") int peerAgeStart,
@RequestParam(name = "peerAgeEnd", defaultValue = "0") int peerAgeEnd,
@RequestParam(name = "peerGender", defaultValue = "none") String peerGender) {
PeerInfoResponseDTO response = consumptionGoalService.getPeerInfo(userId, peerAgeStart, peerAgeEnd, peerGender);
PeerInfoResponseDto response = consumptionGoalService.getPeerInfo(userId, peerAgeStart, peerAgeEnd, peerGender);
return ResponseEntity.ok(response);
}

Expand All @@ -90,24 +80,29 @@ public ResponseEntity<ConsumptionGoalResponseListDto> updateOrElseGenerateConsum
.body(consumptionGoalService.updateConsumptionGoals(userId, consumptionGoalListRequestDto));
}

@GetMapping("/top-categories/top-consumption/{top}")
public ResponseEntity<?> getConsumptionGoalList(@PathVariable(name = "top") int top,
@RequestParam(name = "userId") Long userId,
@GetMapping("/top-categories/top-consumption/3")
public ResponseEntity<?> getTopConsumptionCategories(@RequestParam(name = "userId") Long userId,
@RequestParam(name = "peerAgeStart", defaultValue = "0") int peerAgeStart,
@RequestParam(name = "peerAgeEnd", defaultValue = "0") int peerAgeEnd,
@RequestParam(name = "peerGender", defaultValue = "none") String peerGender) {
List<TopConsumptionResponseDTO> response = consumptionGoalService.getTopConsumptionsLimit(top, userId,
List<TopCategoryConsumptionDto> topCategoriesList = consumptionGoalService.getTopConsumptionCategories(userId,
peerAgeStart, peerAgeEnd, peerGender);
return ResponseEntity.ok(response);
return ResponseEntity.ok(topCategoriesList);
}

@GetMapping("/top-categories/top-consumption")
public ResponseEntity<?> getConsumptionGoalPage(@RequestParam(name = "userId") Long userId,
public ResponseEntity<?> getAllConsumptionCategories(@RequestParam(name = "userId") Long userId,
@RequestParam(name = "peerAgeStart", defaultValue = "0") int peerAgeStart,
@RequestParam(name = "peerAgeEnd", defaultValue = "0") int peerAgeEnd,
@RequestParam(name = "peerGender", defaultValue = "none") String peerGender, Pageable pageable) {
Page<TopConsumptionResponseDTO> response = consumptionGoalService.getTopConsumptions(userId,
peerAgeStart, peerAgeEnd, peerGender, pageable);
return ResponseEntity.ok(response.getContent());
@RequestParam(name = "peerGender", defaultValue = "none") String peerGender) {
List<AllConsumptionCategoryResponseDto> response = consumptionGoalService.getAllConsumptionCategories(userId,
peerAgeStart, peerAgeEnd, peerGender);
return ResponseEntity.ok(response);
}

@GetMapping("/top-categories/top-consumption/{userId}")
public ResponseEntity<?> getTopCategoryAndConsumptionAmount(@PathVariable Long userId) {
return ResponseEntity.ok(consumptionGoalService.getTopCategoryAndConsumptionAmount(userId));
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import java.time.LocalDate;
import java.util.List;

import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.UserConsumptionGoalResponse;
import org.springframework.stereotype.Component;

import com.bbteam.budgetbuddies.domain.category.entity.Category;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionAnalysisResponseDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.ConsumptionGoalResponseListDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.PeerInfoResponseDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.UserConsumptionGoalResponse;
import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal;
import com.bbteam.budgetbuddies.enums.Gender;

@Component
public class ConsumptionGoalConverter {
Expand Down Expand Up @@ -52,10 +55,28 @@ private Long sumTotalGoalAmount(List<ConsumptionGoalResponseDto> consumptionGoal

public UserConsumptionGoalResponse toUserConsumptionGoalResponse(ConsumptionGoal consumptionGoal) {
return UserConsumptionGoalResponse.builder()
.categoryId(consumptionGoal.getCategory().getId())
.goalMonth(consumptionGoal.getGoalMonth())
.consumeAmount(consumptionGoal.getConsumeAmount())
.goalAmount(consumptionGoal.getGoalAmount())
.build();
.categoryId(consumptionGoal.getCategory().getId())
.goalMonth(consumptionGoal.getGoalMonth())
.consumeAmount(consumptionGoal.getConsumeAmount())
.goalAmount(consumptionGoal.getGoalAmount())
.build();
}

public ConsumptionAnalysisResponseDto toTopCategoryAndConsumptionAmount(String categoryName,
Long topAmount) {

return ConsumptionAnalysisResponseDto.builder()
.goalCategory(categoryName)
.currentWeekConsumptionAmount(topAmount)
.build();
}

public PeerInfoResponseDto toPeerInfo(int peerAgeStart, int peerAgeEnd, Gender peerGender) {

return PeerInfoResponseDto.builder()
.peerAgeStart(peerAgeStart)
.peerAgeEnd(peerAgeEnd)
.peerGender(peerGender.name())
.build();
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 088aa46

Please sign in to comment.