[EDIT] デフォルトカテゴリ・カスタムカテゴリ両方取得できるように変更しました。

This commit is contained in:
s-choi
2026-09-24 15:33:37 +09:00
parent b8886fe47b
commit 4a574294b7

View File

@@ -3,6 +3,7 @@ package com.example.demo.app.presentation.controller;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.YearMonth; import java.time.YearMonth;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -185,8 +186,9 @@ public class TransactionController {
@GetMapping("/transaction/create") @GetMapping("/transaction/create")
public String createOneGet(@RequestParam(defaultValue = "") LocalDate today, public String createOneGet(@RequestParam(defaultValue = "") LocalDate today,
Long fixedCostId, Long fixedCostId,
Model model) { Model model, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
if (today == null) { if (today == null) {
today = LocalDate.now(); today = LocalDate.now();
} }
@@ -196,11 +198,21 @@ public class TransactionController {
FixedCostForm fixedCostForm = FixedCostForm.convertFrom(fixedCostService.findById(fixedCostId)); FixedCostForm fixedCostForm = FixedCostForm.convertFrom(fixedCostService.findById(fixedCostId));
transactionForm.setCategoryId(fixedCostForm.getCategoryId()); transactionForm.setCategoryId(fixedCostForm.getCategoryId());
transactionForm.setAmount(fixedCostForm.getAmount()); transactionForm.setAmount(fixedCostForm.getAmount());
transactionForm.setTransactionType(CategoryForm.convertFrom(categoryService.findOne(fixedCostForm.getCategoryId())).getTransactionType()); transactionForm.setTransactionType(CategoryForm
.convertFrom(categoryService.findOne(fixedCostForm.getCategoryId())).getTransactionType());
} }
List<CategoryForm> categoryFormList = CategoryForm.convertFrom(categoryService.findAll()); List<CategoryForm> categoryFormList = new ArrayList<>(
CategoryForm.convertFrom(categoryService.findAllExceptCustom()));
List<CategoryForm> categoryFormCustomList = CategoryForm
.convertFrom(categoryService.findAllByuserId(loginUser.getUserId()));
if (!categoryFormCustomList.isEmpty()) {
for (CategoryForm form : categoryFormCustomList) {
categoryFormList.add(form);
}
}
System.out.println(transactionForm.getCategoryName() + " " + transactionForm.getAmount()); System.out.println(transactionForm.getCategoryName() + " " + transactionForm.getAmount());
@@ -232,13 +244,24 @@ public class TransactionController {
@SessionCheck @SessionCheck
@GetMapping("/transaction/update") @GetMapping("/transaction/update")
public String updateOneGet(@RequestParam Long transactionId, @RequestParam(defaultValue = "") LocalDate today, public String updateOneGet(@RequestParam Long transactionId, @RequestParam(defaultValue = "") LocalDate today,
Model model) { Model model, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
if (today == null) { if (today == null) {
today = LocalDate.now(); today = LocalDate.now();
} }
List<CategoryForm> categoryFormList = CategoryForm.convertFrom(categoryService.findAll()); List<CategoryForm> categoryFormList = new ArrayList<>(
CategoryForm.convertFrom(categoryService.findAllExceptCustom()));
List<CategoryForm> categoryFormCustomList = CategoryForm
.convertFrom(categoryService.findAllByuserId(loginUser.getUserId()));
if (!categoryFormCustomList.isEmpty()) {
for (CategoryForm form : categoryFormCustomList) {
categoryFormList.add(form);
}
}
TransactionForm transactionForm = TransactionForm.convertFrom( TransactionForm transactionForm = TransactionForm.convertFrom(
transactionService.findByTransactionId(transactionId), transactionService.findByTransactionId(transactionId),