From 11a8fbf665be4c53a5bff3a3c88df9283b6f654e Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 12:41:31 +0900 Subject: [PATCH 01/12] =?UTF-8?q?[ADD]=20=E3=82=B7=E3=83=A7=E3=83=BC?= =?UTF-8?q?=E3=83=88=E3=82=AB=E3=83=83=E3=83=88=E6=A9=9F=E8=83=BD=E3=81=AE?= =?UTF-8?q?=E3=81=9F=E3=82=81=E3=81=AEEntity/Model/Form=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/app/domain/model/FixedCostModel.java | 49 +++++++++++++++++ .../app/infra/entity/FixedCostEntity.java | 42 ++++++++++++++ .../app/presentation/form/FixedCostForm.java | 55 +++++++++++++++++++ 3 files changed, 146 insertions(+) create mode 100644 src/main/java/com/example/demo/app/domain/model/FixedCostModel.java create mode 100644 src/main/java/com/example/demo/app/infra/entity/FixedCostEntity.java create mode 100644 src/main/java/com/example/demo/app/presentation/form/FixedCostForm.java diff --git a/src/main/java/com/example/demo/app/domain/model/FixedCostModel.java b/src/main/java/com/example/demo/app/domain/model/FixedCostModel.java new file mode 100644 index 0000000..45d57be --- /dev/null +++ b/src/main/java/com/example/demo/app/domain/model/FixedCostModel.java @@ -0,0 +1,49 @@ +package com.example.demo.app.domain.model; + +import java.util.List; + +import com.example.demo.app.infra.entity.CategoryEntity; +import com.example.demo.app.infra.entity.FixedCostEntity; +import com.example.demo.app.infra.entity.UserEntity; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class FixedCostModel { + + private Long fixedCostId; + + private Long userId; + + private Long categoryId; + + private String fixedCostName; + + private Integer amount; + + + public static FixedCostModel convertFrom(FixedCostEntity fixedCostEntity) { + return new FixedCostModel( + fixedCostEntity.getFixedCostId(), + fixedCostEntity.getUserEntity().getUserId(), + fixedCostEntity.getCategoryEntity().getCategoryId(), + fixedCostEntity.getFixedCostName(), + fixedCostEntity.getAmount()); + } + + public static List convertFrom(List fixedCostEntityList) { + return fixedCostEntityList.stream().map(FixedCostModel::convertFrom).toList(); + } + + public static FixedCostEntity convertTo(FixedCostModel fixedCostModel, UserEntity userEntity, CategoryEntity categoryEntity) { + return new FixedCostEntity( + fixedCostModel.getFixedCostId(), + userEntity, + categoryEntity, + fixedCostModel.getFixedCostName(), + fixedCostModel.getAmount()); + } + +} diff --git a/src/main/java/com/example/demo/app/infra/entity/FixedCostEntity.java b/src/main/java/com/example/demo/app/infra/entity/FixedCostEntity.java new file mode 100644 index 0000000..ef131b2 --- /dev/null +++ b/src/main/java/com/example/demo/app/infra/entity/FixedCostEntity.java @@ -0,0 +1,42 @@ +package com.example.demo.app.infra.entity; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Entity +@Table(name = "fixed_cost_t") +@Data +@NoArgsConstructor +@AllArgsConstructor +public class FixedCostEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "fixed_cost_id") + private Long fixedCostId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private UserEntity userEntity; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "category_id") + private CategoryEntity categoryEntity; + + @Column(name = "fixed_cost_name", nullable = false) + private String fixedCostName; + + @Column(name = "amount", nullable = false) + private Integer amount; +} diff --git a/src/main/java/com/example/demo/app/presentation/form/FixedCostForm.java b/src/main/java/com/example/demo/app/presentation/form/FixedCostForm.java new file mode 100644 index 0000000..8c12754 --- /dev/null +++ b/src/main/java/com/example/demo/app/presentation/form/FixedCostForm.java @@ -0,0 +1,55 @@ +package com.example.demo.app.presentation.form; + +import java.util.List; + +import com.example.demo.app.domain.model.FixedCostModel; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class FixedCostForm { + + private Long fixedCostId; + + private Long userId; + + private Long categoryId; + + private String fixedCostName; + + private Integer amount; + + private String categoryName; + + + public static FixedCostForm convertFrom(FixedCostModel fixedCostModel) { + return new FixedCostForm( + fixedCostModel.getFixedCostId(), + fixedCostModel.getUserId(), + fixedCostModel.getCategoryId(), + fixedCostModel.getFixedCostName(), + fixedCostModel.getAmount(), + ""); + } + + + public static List convertFrom(List fixedCostModelList) { + return fixedCostModelList.stream().map(fixedCostModel -> FixedCostForm.convertFrom(fixedCostModel)).toList(); + } + + public static FixedCostModel convertTo(FixedCostForm fixedCostForm) { + return new FixedCostModel( + fixedCostForm.getFixedCostId(), + fixedCostForm.getUserId(), + fixedCostForm.getCategoryId(), + fixedCostForm.getFixedCostName(), + fixedCostForm.getAmount()); + } + + + +} From 68bfbc195d8bd317e1901ac63d0d60d756afba73 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 12:42:02 +0900 Subject: [PATCH 02/12] =?UTF-8?q?[EDIT]=20=E5=9B=BA=E5=AE=9A=E8=B2=BB?= =?UTF-8?q?=E4=B8=80=E8=A6=A7=E3=81=B8=E3=81=AE=E9=81=B7=E7=A7=BB=E3=83=9C?= =?UTF-8?q?=E3=82=BF=E3=83=B3=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/transaction_detail.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/resources/templates/transaction_detail.html b/src/main/resources/templates/transaction_detail.html index 5fa195c..03afea0 100644 --- a/src/main/resources/templates/transaction_detail.html +++ b/src/main/resources/templates/transaction_detail.html @@ -56,6 +56,10 @@ +
+ + +
From f5b88de9e6bc58b03eb3e24a491326e601105b6a Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 12:42:14 +0900 Subject: [PATCH 03/12] =?UTF-8?q?[ADD]=20=E5=9B=BA=E5=AE=9A=E8=B2=BB?= =?UTF-8?q?=E4=B8=80=E8=A6=A7=E7=94=BB=E9=9D=A2=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/fixed_cost.html | 66 ++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/main/resources/templates/fixed_cost.html diff --git a/src/main/resources/templates/fixed_cost.html b/src/main/resources/templates/fixed_cost.html new file mode 100644 index 0000000..e961f40 --- /dev/null +++ b/src/main/resources/templates/fixed_cost.html @@ -0,0 +1,66 @@ + + + + + + 固定費詳細 + + + + + + + +
+

+ +
+
    +
  • + +
    +

    + カテゴリ名: + +
    + 固定費名: + +
    + 金額: + +

    +
    + +
    + +
    + + + +
    + +
    + + + +
    + +
    + +
    +
    +
  • +
+
+ + + +
+ + +
+ +
+ + + \ No newline at end of file From 060102d2b164ba9d6c2a6c55197ce062c43ad847 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 12:42:22 +0900 Subject: [PATCH 04/12] =?UTF-8?q?[ADD]=20=E5=9B=BA=E5=AE=9A=E8=B2=BB?= =?UTF-8?q?=E7=99=BB=E9=8C=B2=E7=94=BB=E9=9D=A2=E3=82=92=E8=BF=BD=E5=8A=A0?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/fixed_cost_create.html | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/main/resources/templates/fixed_cost_create.html diff --git a/src/main/resources/templates/fixed_cost_create.html b/src/main/resources/templates/fixed_cost_create.html new file mode 100644 index 0000000..03e780b --- /dev/null +++ b/src/main/resources/templates/fixed_cost_create.html @@ -0,0 +1,129 @@ + + + + + + Insert title here + + + + + + + + +
+ +

取引登録

+ +
+ + +
+ + + +
+ +
+ + + +
+ + + +
+ +
+ +
+ + + + +
+ +
+ +
+ + + +
+ +
+ + + + +
+ +
+ + + + + + + + + \ No newline at end of file From 003e03c0c18a0235d249529e51a82d8a24c0fbc3 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 12:42:50 +0900 Subject: [PATCH 05/12] =?UTF-8?q?[ADD]=20=E3=82=B7=E3=83=A7=E3=83=BC?= =?UTF-8?q?=E3=83=88=E3=82=AB=E3=83=83=E3=83=88=E3=81=AE=E3=81=9F=E3=82=81?= =?UTF-8?q?=E3=81=AE=E3=82=B5=E3=83=BC=E3=83=93=E3=82=B9=E3=81=A8=E3=83=AC?= =?UTF-8?q?=E3=83=9D=E3=82=B8=E3=83=88=E3=83=AA=E3=82=92=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/domain/service/FixedCostService.java | 16 +++++++ .../service/impl/FixedCostServiceImpl.java | 48 +++++++++++++++++++ .../infra/repository/FixedCostRepository.java | 15 ++++++ 3 files changed, 79 insertions(+) create mode 100644 src/main/java/com/example/demo/app/domain/service/FixedCostService.java create mode 100644 src/main/java/com/example/demo/app/domain/service/impl/FixedCostServiceImpl.java create mode 100644 src/main/java/com/example/demo/app/infra/repository/FixedCostRepository.java diff --git a/src/main/java/com/example/demo/app/domain/service/FixedCostService.java b/src/main/java/com/example/demo/app/domain/service/FixedCostService.java new file mode 100644 index 0000000..52ba6fd --- /dev/null +++ b/src/main/java/com/example/demo/app/domain/service/FixedCostService.java @@ -0,0 +1,16 @@ +package com.example.demo.app.domain.service; + +import java.util.List; + +import com.example.demo.app.domain.model.FixedCostModel; + +public interface FixedCostService { + + public List findAllByUserId(Long userId); + + public FixedCostModel save(FixedCostModel fixedCostModel); + + public void delete(Long fixedCostId); + + public FixedCostModel findById(Long fixedCostId); +} diff --git a/src/main/java/com/example/demo/app/domain/service/impl/FixedCostServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/FixedCostServiceImpl.java new file mode 100644 index 0000000..e79597d --- /dev/null +++ b/src/main/java/com/example/demo/app/domain/service/impl/FixedCostServiceImpl.java @@ -0,0 +1,48 @@ +package com.example.demo.app.domain.service.impl; + +import java.util.List; + +import org.springframework.stereotype.Service; + +import com.example.demo.app.domain.model.FixedCostModel; +import com.example.demo.app.domain.service.FixedCostService; +import com.example.demo.app.infra.repository.CategoryRepository; +import com.example.demo.app.infra.repository.FixedCostRepository; +import com.example.demo.app.infra.repository.UserRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class FixedCostServiceImpl implements FixedCostService{ + + + private final FixedCostRepository fixedCostRepository; + private final UserRepository userRepository; + private final CategoryRepository categoryRepository; + + + public List findAllByUserId(Long userId) { + + return FixedCostModel.convertFrom(fixedCostRepository.findByUserId(userId)); + + } + + public FixedCostModel save(FixedCostModel fixedCostModel) { + + return FixedCostModel.convertFrom(fixedCostRepository.save( FixedCostModel.convertTo(fixedCostModel, userRepository.findById(fixedCostModel.getUserId()).get(), categoryRepository.findById(fixedCostModel.getCategoryId()).get()))); + + } + + public void delete(Long fixedCostId) { + + fixedCostRepository.deleteById(fixedCostId); + + } + + public FixedCostModel findById(Long fixedCostId) { + return FixedCostModel.convertFrom(fixedCostRepository.findById(fixedCostId).get()); + } + + +} diff --git a/src/main/java/com/example/demo/app/infra/repository/FixedCostRepository.java b/src/main/java/com/example/demo/app/infra/repository/FixedCostRepository.java new file mode 100644 index 0000000..fe7279d --- /dev/null +++ b/src/main/java/com/example/demo/app/infra/repository/FixedCostRepository.java @@ -0,0 +1,15 @@ +package com.example.demo.app.infra.repository; + +import java.util.List; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import com.example.demo.app.infra.entity.FixedCostEntity; + +public interface FixedCostRepository extends JpaRepository { + + @Query("select f from FixedCostEntity f where f.userEntity.userId = :userId") + public List findByUserId(Long userId); + +} From 430f456866ce52c0833d90eef80cd64086fc20ff Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 12:43:19 +0900 Subject: [PATCH 06/12] =?UTF-8?q?[ADD]=20=E3=82=B7=E3=83=A7=E3=83=BC?= =?UTF-8?q?=E3=83=88=E3=82=AB=E3=83=83=E3=83=88=E6=A9=9F=E8=83=BD=E3=81=AE?= =?UTF-8?q?CRD=E3=82=92=E4=BD=9C=E6=88=90=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/FixedCostController.java | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/main/java/com/example/demo/app/presentation/controller/FixedCostController.java diff --git a/src/main/java/com/example/demo/app/presentation/controller/FixedCostController.java b/src/main/java/com/example/demo/app/presentation/controller/FixedCostController.java new file mode 100644 index 0000000..5a0809b --- /dev/null +++ b/src/main/java/com/example/demo/app/presentation/controller/FixedCostController.java @@ -0,0 +1,120 @@ +package com.example.demo.app.presentation.controller; + +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +import jakarta.servlet.http.HttpSession; + +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PostMapping; + +import com.example.demo.aop.aspect.SessionCheck; +import com.example.demo.app.domain.model.LoginModel; +import com.example.demo.app.domain.service.CategoryService; +import com.example.demo.app.domain.service.FixedCostService; +import com.example.demo.app.presentation.form.CategoryForm; +import com.example.demo.app.presentation.form.FixedCostForm; + +import lombok.RequiredArgsConstructor; + +@Controller +@RequiredArgsConstructor +public class FixedCostController { + + private final FixedCostService fixedCostService; + private final CategoryService categoryService; + + @SessionCheck + @GetMapping("/fixed-cost/list") + public String getFixedCostList( + HttpSession session, Model model, LocalDate today) { + + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + + if (today == null) { + today = (LocalDate) session.getAttribute("today"); + } + + List fixedCostFormList = FixedCostForm.convertFrom(fixedCostService.findAllByUserId(loginUser.getUserId())); + + fixedCostFormList.forEach(fixedCostForm -> fixedCostForm.setCategoryName(categoryService.findOne(fixedCostForm.getCategoryId()).getCategoryName())); + + model.addAttribute("fixedCostFormList", fixedCostFormList); + + model.addAttribute("today", today); + + return "fixed_cost"; + } + + + @SessionCheck + @GetMapping("/fixed-cost/create") + public String getFixedCostCreate( + HttpSession session, @ModelAttribute FixedCostForm fixedCostForm, Model model, LocalDate today) { + + List categoryFormList = CategoryForm.convertFrom(categoryService.findAll()); + + List expenseList = new ArrayList(); + + List incomeList = new ArrayList(); + + for (CategoryForm categoryForm : categoryFormList) { + + if (categoryForm.getTransactionType() == 0) { + expenseList.add(categoryForm); + } else { + incomeList.add(categoryForm); + } + + } + + model.addAttribute("expenseList", expenseList); + model.addAttribute("incomeList", incomeList); + model.addAttribute("today", today); + + + return "fixed_cost_create"; + } + + + + @SessionCheck + @PostMapping("/fixed-cost/create") + public String postFixedCostCreate( + HttpSession session, @ModelAttribute FixedCostForm fixedCostForm, Model model, LocalDate today) { + + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + + fixedCostForm.setUserId(loginUser.getUserId()); + + fixedCostService.save(FixedCostForm.convertTo(fixedCostForm)); + + session.setAttribute("today", today); + + return "redirect:/fixed-cost/list"; + } + + + @SessionCheck + @PostMapping("/fixed-cost/delete") + public String postFixedCostDelete(Long fixedCostId, LocalDate today, HttpSession session) { + + fixedCostService.delete(fixedCostId); + + session.setAttribute("today", today); + + return "redirect:/fixed-cost/list"; + } + + + + + + + + +} From 714ffba31fa9d2dcdd6fc72c5936fa0324b4faf6 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 12:43:45 +0900 Subject: [PATCH 07/12] =?UTF-8?q?[EDIT]=20=E3=82=B7=E3=83=A7=E3=83=BC?= =?UTF-8?q?=E3=83=88=E3=82=AB=E3=83=83=E3=83=88=E6=A9=9F=E8=83=BD=E3=82=92?= =?UTF-8?q?=E9=81=A9=E7=94=A8=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TransactionController.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 4897ccb..6af43fa 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 @@ -20,11 +20,13 @@ import org.springframework.web.bind.annotation.RequestParam; import com.example.demo.aop.aspect.SessionCheck; import com.example.demo.app.domain.model.LoginModel; import com.example.demo.app.domain.service.CategoryService; +import com.example.demo.app.domain.service.FixedCostService; import com.example.demo.app.domain.service.GoalService; import com.example.demo.app.domain.service.TransactionService; import com.example.demo.app.domain.service.UserService; import com.example.demo.app.presentation.form.CategoryForm; import com.example.demo.app.presentation.form.Expense; +import com.example.demo.app.presentation.form.FixedCostForm; import com.example.demo.app.presentation.form.GoalForm; import com.example.demo.app.presentation.form.Income; import com.example.demo.app.presentation.form.TransactionForm; @@ -40,6 +42,7 @@ public class TransactionController { private final CategoryService categoryService; private final GoalService goalService; private final UserService userService; + private final FixedCostService fixedCostService; // 一覧画面 @SessionCheck @@ -182,16 +185,23 @@ public class TransactionController { @SessionCheck @GetMapping("/transaction/create") public String createOneGet(@RequestParam(defaultValue = "") LocalDate today, + Long fixedCostId, Model model) { if (today == null) { today = LocalDate.now(); } + TransactionForm transactionForm = new TransactionForm(); + transactionForm.setTransactionDate(today); + if (fixedCostId != null) { + FixedCostForm fixedCostForm = FixedCostForm.convertFrom(fixedCostService.findById(fixedCostId)); + transactionForm.setCategoryId(fixedCostForm.getCategoryId()); + transactionForm.setAmount(fixedCostForm.getAmount()); + transactionForm.setTransactionType(CategoryForm.convertFrom(categoryService.findOne(fixedCostForm.getCategoryId())).getTransactionType()); + } List categoryFormList = CategoryForm.convertFrom(categoryService.findAll()); - TransactionForm transactionForm = new TransactionForm(); - transactionForm.setTransactionDate(today); System.out.println(transactionForm.getCategoryName() + " " + transactionForm.getAmount()); From 1debde25f2add2098a2507aa3b2c3ea48f7586bb Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 13:19:04 +0900 Subject: [PATCH 08/12] =?UTF-8?q?[EDIT]=20menu=E7=94=BB=E9=9D=A2=E3=81=A7?= =?UTF-8?q?=E3=81=AE=E7=9B=AE=E6=A8=99=E8=A1=A8=E7=A4=BA=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/TransactionController.java | 15 ++++--- src/main/resources/templates/menu.html | 40 +++++++++---------- 2 files changed, 27 insertions(+), 28 deletions(-) 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 6af43fa..5b4b753 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 @@ -27,7 +27,6 @@ import com.example.demo.app.domain.service.UserService; import com.example.demo.app.presentation.form.CategoryForm; import com.example.demo.app.presentation.form.Expense; import com.example.demo.app.presentation.form.FixedCostForm; -import com.example.demo.app.presentation.form.GoalForm; import com.example.demo.app.presentation.form.Income; import com.example.demo.app.presentation.form.TransactionForm; import com.example.demo.app.presentation.form.UserForm; @@ -349,19 +348,19 @@ public class TransactionController { model.addAttribute("totalIncome", totalIncome); model.addAttribute("totalExpense", totalExpense); - GoalForm goalForm = GoalForm.convertFrom(goalService.getGoalByUserId(loginUser.getUserId())); +// List goalForm = GoalForm.convertFrom(goalService.getGoalByUserId(loginUser.getUserId())); UserForm userForm = UserForm.convertFrom(userService.findByUserId(loginUser.getUserId())); - model.addAttribute("achievementRate", goalForm.getAchievementRate()); - - model.addAttribute("currentAmount", goalForm.getCurrentAmount()); - - model.addAttribute("targetAmount", goalForm.getTargetAmount()); +// model.addAttribute("achievementRate", goalForm.getAchievementRate()); +// +// model.addAttribute("currentAmount", goalForm.getCurrentAmount()); +// +// model.addAttribute("targetAmount", goalForm.getTargetAmount()); model.addAttribute("saving", userForm.getSaving()); - model.addAttribute("deadline", goalForm.getDeadline()); +// model.addAttribute("deadline", goalForm.getDeadline()); return "menu"; } diff --git a/src/main/resources/templates/menu.html b/src/main/resources/templates/menu.html index 4470464..02cc0e7 100644 --- a/src/main/resources/templates/menu.html +++ b/src/main/resources/templates/menu.html @@ -113,17 +113,17 @@ -
- 目標貯金 - - 円 -
+ + + + + -
- 現在高 - - 円 -
+ + + + +
貯金額 @@ -133,16 +133,16 @@
-
- 達成率 - - % -
-
- 達成期限 - - 円 -
+ + + + + + + + + +
From b2b290a9987a97389c236b0719f557d17dcd577c Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 13:19:23 +0900 Subject: [PATCH 09/12] =?UTF-8?q?[EDIT]=20=E7=9B=AE=E6=A8=99=E3=83=86?= =?UTF-8?q?=E3=83=BC=E3=83=96=E3=83=AB=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=97?= =?UTF-8?q?=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/demo/app/domain/model/GoalModel.java | 16 +++++++++++----- .../demo/app/infra/entity/GoalEntity.java | 9 +++++++-- .../demo/app/presentation/form/GoalForm.java | 12 ++++++++---- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/example/demo/app/domain/model/GoalModel.java b/src/main/java/com/example/demo/app/domain/model/GoalModel.java index d128209..1d7be1f 100644 --- a/src/main/java/com/example/demo/app/domain/model/GoalModel.java +++ b/src/main/java/com/example/demo/app/domain/model/GoalModel.java @@ -3,6 +3,7 @@ package com.example.demo.app.domain.model; import java.time.LocalDate; import com.example.demo.app.infra.entity.GoalEntity; +import com.example.demo.app.infra.entity.UserEntity; import com.example.demo.app.presentation.form.GoalForm; import lombok.AllArgsConstructor; @@ -27,8 +28,10 @@ public class GoalModel { private Integer achievementRate; // 達成率 private Integer currentAmount; // 現在の資産 + + private Long userId; - public static GoalModel convertFrom(GoalEntity goalEntity) { + public static GoalModel convertFrom(GoalEntity goalEntity, int achievementRate, int currentAmount) { return new GoalModel( goalEntity.getGoalId(), goalEntity.getGoalTitle(), @@ -36,10 +39,12 @@ public class GoalModel { goalEntity.getTargetAmount(), goalEntity.getDeadline(), goalEntity.getGoalComplete(), - null,null); + achievementRate, + currentAmount, + goalEntity.getUserEntity().getUserId()); } - public static GoalEntity convertTo(GoalModel goalModel) { + public static GoalEntity convertTo(GoalModel goalModel, UserEntity userEntity) { return new GoalEntity( goalModel.getGoalId(), goalModel.getGoalTitle(), @@ -47,7 +52,7 @@ public class GoalModel { goalModel.getTargetAmount(), goalModel.getDeadline(), goalModel.getGoalComplete(), - null); + userEntity, 0); } public static GoalModel convertFrom(GoalForm goalForm) { @@ -58,7 +63,8 @@ public class GoalModel { goalForm.getTargetAmount(), goalForm.getDeadline(), goalForm.getGoalComplete() - ,null,null); + ,null,null, + goalForm.getUserId()); } } \ No newline at end of file diff --git a/src/main/java/com/example/demo/app/infra/entity/GoalEntity.java b/src/main/java/com/example/demo/app/infra/entity/GoalEntity.java index e37c562..a7bc3f4 100644 --- a/src/main/java/com/example/demo/app/infra/entity/GoalEntity.java +++ b/src/main/java/com/example/demo/app/infra/entity/GoalEntity.java @@ -4,10 +4,12 @@ import java.time.LocalDate; import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.OneToOne; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import lombok.AllArgsConstructor; @@ -41,7 +43,10 @@ public class GoalEntity { @Column(name = "goal_complete", nullable = false) private Integer goalComplete = 0; - @OneToOne(mappedBy = "goalEntity") + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") private UserEntity userEntity; + + private Integer deleteFlag; } diff --git a/src/main/java/com/example/demo/app/presentation/form/GoalForm.java b/src/main/java/com/example/demo/app/presentation/form/GoalForm.java index 5956fd6..30bad09 100644 --- a/src/main/java/com/example/demo/app/presentation/form/GoalForm.java +++ b/src/main/java/com/example/demo/app/presentation/form/GoalForm.java @@ -1,6 +1,7 @@ package com.example.demo.app.presentation.form; import java.time.LocalDate; +import java.util.List; import org.springframework.format.annotation.DateTimeFormat; @@ -31,6 +32,8 @@ public class GoalForm { private Integer achievementRate; // 達成率 private Integer currentAmount; // 現在の資産 + + private Long userId; public static GoalForm convertFrom(GoalModel goalModel) { return new GoalForm( @@ -41,11 +44,12 @@ public class GoalForm { goalModel.getDeadline(), goalModel.getGoalComplete(), goalModel.getAchievementRate(), - goalModel.getCurrentAmount()); + goalModel.getCurrentAmount(), + goalModel.getUserId()); } -// public static List convertFrom(List goalModelList) { -// return goalModelList.stream().map(GoalForm::convertFrom).toList(); -// } + public static List convertFrom(List goalModelList) { + return goalModelList.stream().map(GoalForm::convertFrom).toList(); + } } \ No newline at end of file From 70ad3678a51a340f4c12544acff93c601e655908 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 13:19:53 +0900 Subject: [PATCH 10/12] =?UTF-8?q?[EDIT]=20User=E3=83=86=E3=83=BC=E3=83=96?= =?UTF-8?q?=E3=83=AB=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/demo/app/infra/entity/UserEntity.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/demo/app/infra/entity/UserEntity.java b/src/main/java/com/example/demo/app/infra/entity/UserEntity.java index 332fb61..f6d52fd 100644 --- a/src/main/java/com/example/demo/app/infra/entity/UserEntity.java +++ b/src/main/java/com/example/demo/app/infra/entity/UserEntity.java @@ -12,7 +12,6 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; -import jakarta.persistence.OneToOne; import jakarta.persistence.Table; import lombok.AllArgsConstructor; @@ -65,9 +64,8 @@ public class UserEntity { @JoinColumn(name = "secret_question_id") private QuestionEntity questionEntity; - @OneToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "goal_id") - private GoalEntity goalEntity; + @OneToMany(mappedBy = "userEntity") + private List goalEntityList; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "course_id") From e9d3e1615768dc44ca0c4de456f02c7cabda4621 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 13:20:14 +0900 Subject: [PATCH 11/12] =?UTF-8?q?[EDIT]=20=E5=A4=89=E6=9B=B4=E3=81=97?= =?UTF-8?q?=E3=81=9F=E3=83=86=E3=83=BC=E3=83=96=E3=83=AB=E3=81=AB=E5=90=88?= =?UTF-8?q?=E3=82=8F=E3=81=9B=E3=81=A6=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/app/domain/service/GoalService.java | 8 +-- .../domain/service/impl/GoalServiceImpl.java | 49 +++++++++---------- .../app/infra/repository/GoalRepository.java | 6 +++ .../controller/GoalController.java | 2 +- 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/example/demo/app/domain/service/GoalService.java b/src/main/java/com/example/demo/app/domain/service/GoalService.java index 294f7ac..500c990 100644 --- a/src/main/java/com/example/demo/app/domain/service/GoalService.java +++ b/src/main/java/com/example/demo/app/domain/service/GoalService.java @@ -1,16 +1,18 @@ package com.example.demo.app.domain.service; +import java.util.List; + import com.example.demo.app.domain.model.GoalModel; public interface GoalService { GoalModel getGoalById(Long goalId); - GoalModel getGoalByUserId(Long userId); + public List getGoalByUserId(Long userId); - GoalModel createGoal(GoalModel goalModel); + public GoalModel createGoal(GoalModel goalModel, Long userId); - GoalModel updateGoal(GoalModel goalModel); + GoalModel updateGoal(GoalModel goalModel, Long userId); // void deleteGoal(Long goalId); diff --git a/src/main/java/com/example/demo/app/domain/service/impl/GoalServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/GoalServiceImpl.java index a1d31e8..0d4d75a 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/GoalServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/GoalServiceImpl.java @@ -1,5 +1,8 @@ package com.example.demo.app.domain.service.impl; +import java.util.ArrayList; +import java.util.List; + import org.springframework.stereotype.Service; import com.example.demo.app.domain.model.GoalModel; @@ -21,14 +24,14 @@ public class GoalServiceImpl implements GoalService { @Override public GoalModel getGoalById(Long goalId) { GoalEntity goalEntity = goalRepository.findById(goalId).orElse(null); - return GoalModel.convertFrom(goalEntity); + return GoalModel.convertFrom(goalEntity, 0, 0); } @Override - public GoalModel getGoalByUserId(Long userId) { + public List getGoalByUserId(Long userId) { UserEntity userEntity = userRepository.findById(userId).orElseThrow(); - GoalEntity goalEntity = userEntity.getGoalEntity(); + List goalEntityList = goalRepository.findAllByUserId(userId); // 収支の合計を計算(収入はプラス、支出はマイナス) int transactionTotal = userEntity.getTransactionEntityList().stream() @@ -42,42 +45,38 @@ public class GoalServiceImpl implements GoalService { int currentAmount = userEntity.getSaving() + transactionTotal; // 達成率(%) = 現在の資産 ÷ 目標金額 × 100 - int achievementRate = - (goalEntity.getTargetAmount() == null) - ? 0 : - (int) ((currentAmount * 100.0) / goalEntity.getTargetAmount()); - GoalModel goalModel = GoalModel.convertFrom(goalEntity); + List goalModelList = new ArrayList(); - return new GoalModel( - goalModel.getGoalId(), - goalModel.getGoalTitle(), - goalModel.getGoalSubtitle(), - goalModel.getTargetAmount(), - goalModel.getDeadline(), - goalModel.getGoalComplete(), - achievementRate, - currentAmount); + goalEntityList.stream() + .forEach(goalEntity -> goalModelList.add(GoalModel.convertFrom(goalEntity, + (goalEntity.getTargetAmount() == null) + ? 0 + : (int) ((currentAmount * 100.0) / goalEntity.getTargetAmount()), + currentAmount))); + + + return goalModelList; } - - @Override - public GoalModel createGoal(GoalModel goalModel) { - GoalEntity goalEntity = GoalModel.convertTo(goalModel); + @Override + public GoalModel createGoal(GoalModel goalModel, Long userId) { + + GoalEntity goalEntity = GoalModel.convertTo(goalModel, userRepository.findById(userId).get()); GoalEntity savedGoalEntity = goalRepository.save(goalEntity); - return GoalModel.convertFrom(savedGoalEntity); + return GoalModel.convertFrom(savedGoalEntity, 0, 0); } @Override - public GoalModel updateGoal(GoalModel goalModel) { + public GoalModel updateGoal(GoalModel goalModel, Long userId) { - GoalEntity goalEntity = GoalModel.convertTo(goalModel); + GoalEntity goalEntity = GoalModel.convertTo(goalModel, userRepository.findById(userId).get()); GoalEntity updatedGoalEntity = goalRepository.save(goalEntity); - return GoalModel.convertFrom(updatedGoalEntity); + return GoalModel.convertFrom(updatedGoalEntity, 0, 0); } } \ No newline at end of file diff --git a/src/main/java/com/example/demo/app/infra/repository/GoalRepository.java b/src/main/java/com/example/demo/app/infra/repository/GoalRepository.java index c66aa15..1de888e 100644 --- a/src/main/java/com/example/demo/app/infra/repository/GoalRepository.java +++ b/src/main/java/com/example/demo/app/infra/repository/GoalRepository.java @@ -1,6 +1,9 @@ package com.example.demo.app.infra.repository; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; import com.example.demo.app.infra.entity.GoalEntity; @@ -8,4 +11,7 @@ import com.example.demo.app.infra.entity.GoalEntity; @Repository public interface GoalRepository extends JpaRepository { + @Query("select g from GoalEntity g where g.userEntity.userId = :userId") + public List findAllByUserId(Long userId); + } \ No newline at end of file diff --git a/src/main/java/com/example/demo/app/presentation/controller/GoalController.java b/src/main/java/com/example/demo/app/presentation/controller/GoalController.java index 856d77b..3657719 100644 --- a/src/main/java/com/example/demo/app/presentation/controller/GoalController.java +++ b/src/main/java/com/example/demo/app/presentation/controller/GoalController.java @@ -69,7 +69,7 @@ public class GoalController { } GoalModel goalModel = GoalModel.convertFrom(goalForm); - goalService.updateGoal(goalModel); + goalService.updateGoal(goalModel, userId); return "redirect:/goal"; } From 76e3fc2345f159bfe7ccd5456caaf7e489d024ec Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 13:32:23 +0900 Subject: [PATCH 12/12] =?UTF-8?q?[FIX]=20Goal=E3=83=86=E3=83=BC=E3=83=96?= =?UTF-8?q?=E3=83=AB=E3=81=AE=E5=A4=89=E6=9B=B4=E3=81=AB=E5=90=88=E3=82=8F?= =?UTF-8?q?=E3=81=9B=E3=81=A6User=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=81=AE=E4=BF=AE=E6=AD=A3=E3=82=92=E3=81=8A=E3=81=93=E3=81=AA?= =?UTF-8?q?=E3=81=84=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/demo/app/domain/model/UserModel.java | 2 -- .../com/example/demo/app/domain/service/UserService.java | 2 +- .../demo/app/domain/service/impl/UserServiceImpl.java | 5 ++--- .../demo/app/presentation/controller/UserController.java | 5 ++++- .../com/example/demo/app/presentation/form/UserForm.java | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/example/demo/app/domain/model/UserModel.java b/src/main/java/com/example/demo/app/domain/model/UserModel.java index 05cb388..c251035 100644 --- a/src/main/java/com/example/demo/app/domain/model/UserModel.java +++ b/src/main/java/com/example/demo/app/domain/model/UserModel.java @@ -20,7 +20,6 @@ public class UserModel { private Integer saving; private Integer annualIncome; private Integer monthlyBudget; - private Long goalId; private Long courseId; private Integer deleteFlag; @@ -36,7 +35,6 @@ public class UserModel { userEntity.getSaving(), userEntity.getAnnualIncome(), userEntity.getMonthlyBudget(), - userEntity.getGoalEntity().getGoalId(), userEntity.getCourseEntity().getCourseId(), userEntity.getDeleteFlag() ); diff --git a/src/main/java/com/example/demo/app/domain/service/UserService.java b/src/main/java/com/example/demo/app/domain/service/UserService.java index 070681d..fa63458 100644 --- a/src/main/java/com/example/demo/app/domain/service/UserService.java +++ b/src/main/java/com/example/demo/app/domain/service/UserService.java @@ -5,7 +5,7 @@ import com.example.demo.app.presentation.form.UserForm; public interface UserService { - void register(UserForm userForm, Long courseId); + public void register(UserForm userForm, Long courseId, Long userId); public void updateCourse(Long userId, Long courseId); diff --git a/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java index bba298a..9cc6639 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java @@ -25,7 +25,7 @@ public class UserServiceImpl implements UserService { private final CourseRepository courseRepository; @Override - public void register(UserForm userForm, Long courseId) { + public void register(UserForm userForm, Long courseId, Long userId) { UserEntity userEntity = new UserEntity(); @@ -44,12 +44,11 @@ public class UserServiceImpl implements UserService { GoalEntity goalEntity = new GoalEntity(); goalEntity.setTargetAmount(Integer.parseInt(String.valueOf(userForm.getGoalId()))); + goalEntity.setUserEntity(userRepository.findById(userId).get()); CourseEntity courseEntity = courseRepository.findById(courseId).orElse(null); userEntity.setQuestionEntity(questionEntity); - userEntity.setGoalEntity(goalRepository.save( - goalEntity)); userEntity.setCourseEntity(courseEntity); userEntity.setDeleteFlag(0); diff --git a/src/main/java/com/example/demo/app/presentation/controller/UserController.java b/src/main/java/com/example/demo/app/presentation/controller/UserController.java index d009d29..a4ac2cb 100644 --- a/src/main/java/com/example/demo/app/presentation/controller/UserController.java +++ b/src/main/java/com/example/demo/app/presentation/controller/UserController.java @@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; +import com.example.demo.app.domain.model.LoginModel; import com.example.demo.app.domain.service.CourseService; import com.example.demo.app.domain.service.QuestionService; import com.example.demo.app.domain.service.UserService; @@ -83,9 +84,11 @@ public class UserController { Model model, HttpSession session) { + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + Long courseId = courseService.findByName((String) session.getAttribute("selectedCourseName")); - userService.register(userForm, courseId); + userService.register(userForm, courseId, loginUser.getUserId()); return "redirect:/login"; } diff --git a/src/main/java/com/example/demo/app/presentation/form/UserForm.java b/src/main/java/com/example/demo/app/presentation/form/UserForm.java index f145059..23fa0da 100644 --- a/src/main/java/com/example/demo/app/presentation/form/UserForm.java +++ b/src/main/java/com/example/demo/app/presentation/form/UserForm.java @@ -36,7 +36,7 @@ public class UserForm { userModel.getSaving(), userModel.getAnnualIncome(), userModel.getMonthlyBudget(), - userModel.getGoalId(), + 0L, userModel.getCourseId() ); }