diff --git a/src/main/kotlin/com/wbrawner/budgetserver/category/CategoryController.kt b/src/main/kotlin/com/wbrawner/budgetserver/category/CategoryController.kt index 90406bc..1236123 100644 --- a/src/main/kotlin/com/wbrawner/budgetserver/category/CategoryController.kt +++ b/src/main/kotlin/com/wbrawner/budgetserver/category/CategoryController.kt @@ -31,6 +31,7 @@ class CategoryController @Autowired constructor( @GetMapping("", produces = [MediaType.APPLICATION_JSON_VALUE]) @ApiOperation(value = "getCategories", nickname = "getCategories", tags = ["Categories"]) fun getCategories(budgetId: Long? = null, + isExpense: Boolean? = null, count: Int?, page: Int?, sortBy: String?, @@ -46,7 +47,12 @@ class CategoryController @Autowired constructor( count?: 1000, Sort(sortOrder?: Sort.Direction.ASC, sortBy?: "title") ) - return ResponseEntity.ok(categoryRepository.findAllByBudgetIn(budgets, pageRequest).map { CategoryResponse(it) }) + val categories = if (isExpense == null) { + categoryRepository.findAllByBudgetIn(budgets, pageRequest) + } else { + categoryRepository.findAllByBudgetInAndExpense(budgets, isExpense, pageRequest) + } + return ResponseEntity.ok(categories.map { CategoryResponse(it) }) } @GetMapping("/{id}", produces = [MediaType.APPLICATION_JSON_VALUE]) diff --git a/src/main/kotlin/com/wbrawner/budgetserver/category/CategoryRepository.kt b/src/main/kotlin/com/wbrawner/budgetserver/category/CategoryRepository.kt index ccc3756..5068e22 100644 --- a/src/main/kotlin/com/wbrawner/budgetserver/category/CategoryRepository.kt +++ b/src/main/kotlin/com/wbrawner/budgetserver/category/CategoryRepository.kt @@ -8,6 +8,7 @@ import java.util.* interface CategoryRepository: PagingAndSortingRepository { fun findAllByBudget(budget: Budget, pageable: Pageable): List fun findAllByBudgetIn(budgets: List, pageable: Pageable? = null): List + fun findAllByBudgetInAndExpense(budgets: List, isExpense: Boolean, pageable: Pageable? = null): List fun findByBudgetAndId(budget: Budget, id: Long): Optional fun findAllByBudgetInAndIdIn(budgets: List, ids: List, pageable: Pageable? = null): List } \ No newline at end of file