diff --git a/src/main/java/com/example/demo/app/infra/repository/AllocationRepository.java b/src/main/java/com/example/demo/app/infra/repository/AllocationRepository.java index 56913d8..5dc0ece 100644 --- a/src/main/java/com/example/demo/app/infra/repository/AllocationRepository.java +++ b/src/main/java/com/example/demo/app/infra/repository/AllocationRepository.java @@ -13,19 +13,20 @@ public interface AllocationRepository extends JpaRepository findByCourseEntity_CourseId(Long courseId); - @Query(" SELECT co.course_id, " - + " co.course_name, " - + " ca.category_id, " - + " ca.categpry_name, " - + " a.allocation_ratio " - + " FROM allocation_m a " - + " INNER JOIN course_m co " - + " ON a.course_id = co.course_id " - + " INNER JOIN category_t ca " - + " on a.category_id = ca.category_id " - + " WHERE ca.transaction_type = 0 " - + " ORDER BY a.course_id ASC, " - + " a.category_id ASC ") + @Query(" SELECT new com.example.demo.app.domain.model.CourseInfoModel(" + + "co.courseId, " + + " co.courseName, " + + " ca.categoryId, " + + " ca.categoryName, " + + " a.allocationRatio )" + + " FROM AllocationEntity a" + + " INNER JOIN CourseEntity co " + + " ON a.courseEntity.courseId = co.courseId " + + " INNER JOIN CategoryEntity ca " + + " on a.categoryEntity.categoryId = ca.categoryId " + + " WHERE ca.transactionType = 0 " + + " ORDER BY a.courseEntity.courseId ASC, " + + " a.categoryEntity.categoryId ASC ") List findAllJoinedAllocation(); } diff --git a/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java b/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java index c747917..5fe10a1 100644 --- a/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java +++ b/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java @@ -13,13 +13,13 @@ public interface TransactionRepository extends JpaRepository findByUserIdAndDate(LocalDate todayDate, Long userId); - @Query("select t from TransactionEntity t where (t.transactionDate between :startDate and :endDate) and (t.userId = :userId) order by t.transactionDate asc") + @Query("select t from TransactionEntity t where (t.transactionDate between :startDate and :endDate) and (t.userEntity.userId = :userId) order by t.transactionDate asc") public List findAllByDateAndUserId(LocalDate startDate, LocalDate endDate, Long userId); - @Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryId = c.categoryId where (t.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 0") + @Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryEntity.categoryId = c.categoryId where (t.userEntity.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 0") public Integer findTotalExpense(LocalDate startDate, LocalDate endDate, Long userId); - @Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryId = c.categoryId where (t.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 1") + @Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryEntity.categoryId = c.categoryId where (t.userEntity.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 1") public Integer findTotalIncome(LocalDate startDate, LocalDate endDate, Long userId); @Query("select sum(t.amount) from TransactionEntity t where t.userEntity.userId = :userId and t.categoryEntity.categoryId = :categoryId and t.transactionDate between :startDate and :endDate") diff --git a/src/main/java/com/example/demo/app/presentation/controller/TransactionController.java b/src/main/java/com/example/demo/app/presentation/controller/TransactionController.java index 35fec08..fed0ca7 100644 --- a/src/main/java/com/example/demo/app/presentation/controller/TransactionController.java +++ b/src/main/java/com/example/demo/app/presentation/controller/TransactionController.java @@ -66,7 +66,7 @@ public class TransactionController { } // 詳細画面 - @GetMapping() + @GetMapping("/transaction/detail") public String findOne(@RequestParam(required = false) LocalDate todayDates, Model model, HttpSession session) { LocalDate todayDate = (todayDates == null) ? LocalDate.now() : todayDates; @@ -93,13 +93,13 @@ public class TransactionController { return ""; } - @GetMapping("") + @GetMapping("/transaction/create") public String createOneGet(@ModelAttribute TransactionForm transactionForm) { return ""; } - @PostMapping() + @PostMapping("/transaction/create") public String createOnePost(@ModelAttribute TransactionForm transactionForm, Model model) { if (transactionService.createTransaction(TransactionForm.convertTo(transactionForm)) != 0) { @@ -110,13 +110,13 @@ public class TransactionController { } - @GetMapping("") + @GetMapping("/transaction/update") public String updateOneGet(@ModelAttribute TransactionForm transactionForm) { return ""; } - @PostMapping() + @PostMapping("/transaction/update") public String updateOnePost(@ModelAttribute TransactionForm transactionForm, Model model) { if (transactionService.updateTransaction(TransactionForm.convertTo(transactionForm)) != 0) {