diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 3df82ec4..54e8902d 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -25,8 +25,8 @@ jobs: - name: Ensure resource directory exists run: mkdir -p ./src/main/resources - - name : injection-yml - run : echo -E "${{ secrets.YML }}" > ./src/main/resources/application.yml + - name: injection-yml + run: echo -E "${{ secrets.YML }}" > ./src/main/resources/application.yml - name: Log in to Docker Hub uses: docker/login-action@v3 @@ -43,4 +43,4 @@ jobs: key: ${{ secrets.PRIVATE_KEY }} host: ${{ secrets.HOST_DEV }} username: ${{ secrets.USERNAME }} - script: ${{ secrets.SCRIPT }} + script: ${{ secrets.DEPLOY_SCRIPT }} diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/category/converter/CategoryConverter.java b/src/main/java/com/bbteam/budgetbuddies/domain/category/converter/CategoryConverter.java index 69069b9d..17ab7c4d 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/category/converter/CategoryConverter.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/category/converter/CategoryConverter.java @@ -14,6 +14,7 @@ public Category toCategoryEntity(CategoryRequestDTO categoryRequestDTO, User use .name(categoryRequestDTO.getName()) .isDefault(categoryRequestDTO.getIsDefault()) .user(user) + .deleted(false) .build(); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java index 4785623b..70ddae63 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseApi.java @@ -32,7 +32,9 @@ public interface ExpenseApi { @ApiResponse(responseCode = "AUTH004", description = "access 토큰 만료", content = @Content(schema = @Schema(implementation = ApiResponse.class))), @ApiResponse(responseCode = "AUTH006", description = "access 토큰 모양이 이상함", content = @Content(schema = @Schema(implementation = ApiResponse.class)))}) ResponseEntity createExpense( - @Parameter(description = "user_id, category_id, amount, description, expenseDate") ExpenseRequestDto expenseRequestDto); + @Parameter(description = "user_id") @PathVariable Long userId, + @Parameter(description = "category_id, amount, description, expenseDate") @RequestBody ExpenseRequestDto expenseRequestDto + ); @Operation(summary = "월별 소비 조회", description = "무한 스크롤을 통한 조회로 예상하여 Slice를 통해서 조회") @ApiResponses({ diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java index 7ab52043..d2762713 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/controller/ExpenseController.java @@ -30,11 +30,11 @@ public class ExpenseController implements ExpenseApi { private final ExpenseService expenseService; @Override - @PostMapping("/add") + @PostMapping("/add/{userId}") public ResponseEntity createExpense( - @Parameter(description = "user_id, category_id, amount, description, expenseDate") - @RequestBody ExpenseRequestDto expenseRequestDto) { - ExpenseResponseDto response = expenseService.createExpense(expenseRequestDto); + @Parameter(description = "user_id") @PathVariable Long userId, + @Parameter(description = "category_id, amount, description, expenseDate") @RequestBody ExpenseRequestDto expenseRequestDto) { + ExpenseResponseDto response = expenseService.createExpense(userId, expenseRequestDto); return ResponseEntity.ok(response); } diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseRequestDto.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseRequestDto.java index b5ca5bdc..3b3fe854 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseRequestDto.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/dto/ExpenseRequestDto.java @@ -14,7 +14,6 @@ @NoArgsConstructor @AllArgsConstructor public class ExpenseRequestDto { - private Long userId; private Long categoryId; private Long amount; private String description; diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseService.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseService.java index 1ca3e6cb..4374284e 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseService.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseService.java @@ -8,7 +8,7 @@ import com.bbteam.budgetbuddies.domain.expense.dto.MonthlyExpenseCompactResponseDto; public interface ExpenseService { - ExpenseResponseDto createExpense(ExpenseRequestDto expenseRequestDto); + ExpenseResponseDto createExpense(Long userId, ExpenseRequestDto expenseRequestDto); MonthlyExpenseCompactResponseDto getMonthlyExpense(Long userId, LocalDate localDate); diff --git a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java index ccc35448..40390a76 100644 --- a/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java +++ b/src/main/java/com/bbteam/budgetbuddies/domain/expense/service/ExpenseServiceImpl.java @@ -34,8 +34,8 @@ public class ExpenseServiceImpl implements ExpenseService { private final ConsumptionGoalService consumptionGoalService; @Override - public ExpenseResponseDto createExpense(ExpenseRequestDto expenseRequestDto) { - User user = userRepository.findById(expenseRequestDto.getUserId()) + public ExpenseResponseDto createExpense(Long userId, ExpenseRequestDto expenseRequestDto) { + User user = userRepository.findById(userId) .orElseThrow(() -> new IllegalArgumentException("Invalid user ID")); Category category = categoryRepository.findById(expenseRequestDto.getCategoryId()) .orElseThrow(() -> new IllegalArgumentException("Invalid category ID")); @@ -54,27 +54,7 @@ public ExpenseResponseDto createExpense(ExpenseRequestDto expenseRequestDto) { Case 2) !default && 키테고리 테이블의 UserId 컬럼의 값이 나와 맞으면 (= custom category) */ - else if (!category.getIsDefault() && category.getUser().getId().equals(expenseRequestDto.getUserId())) { - // custom category - } else { - throw new IllegalArgumentException("User and category are not matched properly."); - } - - /* - case 1) - - 카테고리 ID가 1~10 사이 && default => DB의 immutable 필드인 default category - - DB 관리 이슈로 category에 default 카테고리의 중복이 발생할 경우, 이를 대비하기 위해 1<= id <= 10 조건도 추가 - */ - if (expenseRequestDto.getCategoryId() >= 1 && expenseRequestDto.getCategoryId() <= 10 - && category.getIsDefault()) { - // category.setUser(user); - // default category - } - /* - Case 2) - !default && 키테고리 테이블의 UserId 컬럼의 값이 나와 맞으면 (= custom cateogory) - */ - else if (!category.getIsDefault() && category.getUser().getId().equals(expenseRequestDto.getUserId())) { + else if (!category.getIsDefault() && category.getUser().getId().equals(userId)) { // custom category } else { throw new IllegalArgumentException("User and category are not matched properly."); @@ -84,7 +64,7 @@ else if (!category.getIsDefault() && category.getUser().getId().equals(expenseRe expenseRepository.save(expense); // 소비 목표 업데이트 - consumptionGoalService.updateConsumeAmount(expenseRequestDto.getUserId(), expenseRequestDto.getCategoryId(), + consumptionGoalService.updateConsumeAmount(userId, expenseRequestDto.getCategoryId(), expenseRequestDto.getAmount()); return expenseConverter.toExpenseResponseDto(expense);