From 918b7f7218c219a88c42f59643d840cf17dd3d60 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 14:09:22 +0900 Subject: [PATCH 1/9] =?UTF-8?q?[EDIT]=20=E7=9B=AE=E6=A8=99=E3=81=AE?= =?UTF-8?q?=E4=B8=80=E8=A6=A7=E3=82=92=E5=8F=97=E3=81=91=E5=8F=96=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3=E3=83=BB=E4=BD=9C?= =?UTF-8?q?=E6=88=90=E3=81=A8=E5=89=8A=E9=99=A4=E6=A9=9F=E8=83=BD=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/app/domain/service/GoalService.java | 2 + .../domain/service/impl/GoalServiceImpl.java | 4 ++ .../controller/GoalController.java | 57 +++++++++++++++---- 3 files changed, 51 insertions(+), 12 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 500c990..9272331 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 @@ -13,6 +13,8 @@ public interface GoalService { public GoalModel createGoal(GoalModel goalModel, Long userId); GoalModel updateGoal(GoalModel goalModel, Long userId); + + public void delete(Long goalId); // 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 0d4d75a..0708ec9 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 @@ -78,5 +78,9 @@ public class GoalServiceImpl implements GoalService { return GoalModel.convertFrom(updatedGoalEntity, 0, 0); } + + public void delete(Long goalId) { + goalRepository.deleteById(goalId); + } } \ 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 3657719..abb05a4 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 @@ -1,5 +1,7 @@ package com.example.demo.app.presentation.controller; +import java.util.List; + import jakarta.servlet.http.HttpSession; import org.springframework.stereotype.Controller; @@ -32,22 +34,21 @@ public class GoalController { Long userId = loginUser.getUserId(); - GoalModel goalModel = goalService.getGoalByUserId(userId); - GoalForm goalForm = GoalForm.convertFrom(goalModel); + List goalModelList = goalService.getGoalByUserId(userId); + List goalFormList = GoalForm.convertFrom(goalModelList); - model.addAttribute("goalForm", goalForm); + model.addAttribute("goalFormList", goalFormList); return "goal_view"; } @SessionCheck @GetMapping("/edit") - public String editGoal(Model model, HttpSession session) { + public String editGoal(Model model, HttpSession session, Long goalId) { LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); Long userId = loginUser.getUserId(); - GoalModel goalModel = goalService.getGoalByUserId(userId); - GoalForm goalForm = GoalForm.convertFrom(goalModel); + GoalForm goalForm = GoalForm.convertFrom(goalService.getGoalById(goalId)); model.addAttribute("goalForm", goalForm); return "goal_edit"; @@ -61,17 +62,49 @@ public class GoalController { Long userId = loginUser.getUserId(); - // 本人の目標かどうかを確認してから更新する - GoalModel currentGoal = goalService.getGoalByUserId(userId); - - if (!currentGoal.getGoalId().equals(goalForm.getGoalId())) { - return "redirect:/goal"; // 他人のデータを更新しようとしたら弾く - } +// // 本人の目標かどうかを確認してから更新する +// GoalModel currentGoal = goalService.getGoalByUserId(userId); +// +// if (!currentGoal.getGoalId().equals(goalForm.getGoalId())) { +// return "redirect:/goal"; // 他人のデータを更新しようとしたら弾く +// } GoalModel goalModel = GoalModel.convertFrom(goalForm); goalService.updateGoal(goalModel, userId); return "redirect:/goal"; } + + + @SessionCheck + @GetMapping("/create") + public String createGoalGet(@ModelAttribute GoalForm goalForm, HttpSession session) { + + return "goal_create"; + } + + @SessionCheck + @PostMapping("/create") + public String createGoalPost(@ModelAttribute GoalForm goalForm, HttpSession session) { + + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + + Long userId = loginUser.getUserId(); + + goalService.createGoal(GoalModel.convertFrom(goalForm), userId); + + return "redirect:/goal"; + } + + @SessionCheck + @PostMapping("/delete") // フラグ考慮してないため、今度修正必要 + public String deleteGoal(Long goalId) { + + goalService.delete(goalId); + + return "redirect:/goal"; + } + + } \ No newline at end of file From ec862f8271eb9410bd6e6a71fe075b0dc14144aa Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 14:09:52 +0900 Subject: [PATCH 2/9] =?UTF-8?q?[FIX]=20=E3=83=87=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AB=E3=83=88=E3=81=A7=E7=9B=AE=E6=A8=99=E9=81=94=E6=88=90?= =?UTF-8?q?=E7=8F=BE=E7=8A=B6=E3=82=920=E3=81=AB=E6=98=8E=E7=A4=BA?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/example/demo/app/domain/model/GoalModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1d7be1f..497c5b4 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 @@ -51,7 +51,7 @@ public class GoalModel { goalModel.getGoalSubtitle(), goalModel.getTargetAmount(), goalModel.getDeadline(), - goalModel.getGoalComplete(), + 0, userEntity, 0); } From 58da1fcbfc341b13fa9509750c88dba32d2dc711 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 14:10:12 +0900 Subject: [PATCH 3/9] =?UTF-8?q?[ADD]=20=E7=9B=AE=E6=A8=99=E4=BD=9C?= =?UTF-8?q?=E6=88=90=E7=94=BB=E9=9D=A2=E3=81=AE=E8=BF=BD=E5=8A=A0=E5=8F=8A?= =?UTF-8?q?=E3=81=B3=E9=81=B7=E7=A7=BB=E3=83=9C=E3=82=BF=E3=83=B3=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/templates/goal_create.html | 46 +++++++ src/main/resources/templates/goal_view.html | 113 ++++++++++-------- 2 files changed, 112 insertions(+), 47 deletions(-) create mode 100644 src/main/resources/templates/goal_create.html diff --git a/src/main/resources/templates/goal_create.html b/src/main/resources/templates/goal_create.html new file mode 100644 index 0000000..fe201e4 --- /dev/null +++ b/src/main/resources/templates/goal_create.html @@ -0,0 +1,46 @@ + + + + + 目標作成 + + + + + + +
+ +

目標作成

+ +
+ + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + +
+ +
+ + + + \ No newline at end of file diff --git a/src/main/resources/templates/goal_view.html b/src/main/resources/templates/goal_view.html index 71daf84..38506cd 100644 --- a/src/main/resources/templates/goal_view.html +++ b/src/main/resources/templates/goal_view.html @@ -1,48 +1,67 @@ - - - - - 目標詳細 - - - - - -
- - -

目標詳細

- - - - - - - - - - - - - - - - - - - - - - - - - - -
目標名
目標説明
目標金額
目標達成期限
達成率
- - 編集する - -
- - + + + + + + 目標詳細 + + + + + + +
+ + +

目標詳細

+ +
+
    +
  • + +
    +

    + 目標名: + +
    + 目標説明: + +
    + 目標金額: + +
    + 目標達成期限: + +
    + 達成率: + +
    +

    +
    + +
    + +
    + + +
    +
    + + +
    + +
    + +
  • +
+
+ +
+ +
+ +
+ + + \ No newline at end of file From c44a6792135909f2df44ed6fdf8c2d3c71996f51 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 15:32:34 +0900 Subject: [PATCH 4/9] =?UTF-8?q?[EDIT]=20category=E3=83=86=E3=83=BC?= =?UTF-8?q?=E3=83=96=E3=83=AB=E3=81=ABUser=E3=83=BB=E5=89=8A=E9=99=A4?= =?UTF-8?q?=E3=83=95=E3=83=A9=E3=82=B0=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97?= =?UTF-8?q?=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../example/demo/app/domain/model/CategoryModel.java | 12 ++++++++++++ .../demo/app/infra/entity/CategoryEntity.java | 10 ++++++++++ .../demo/app/presentation/form/CategoryForm.java | 7 +++++++ 3 files changed, 29 insertions(+) diff --git a/src/main/java/com/example/demo/app/domain/model/CategoryModel.java b/src/main/java/com/example/demo/app/domain/model/CategoryModel.java index 7f270aa..1857f5e 100644 --- a/src/main/java/com/example/demo/app/domain/model/CategoryModel.java +++ b/src/main/java/com/example/demo/app/domain/model/CategoryModel.java @@ -3,6 +3,7 @@ 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.UserEntity; import lombok.AllArgsConstructor; import lombok.Getter; @@ -27,4 +28,15 @@ public class CategoryModel { return categoryEntityList.stream().map(CategoryModel::convertFrom).toList(); } + public static CategoryEntity convertTo(CategoryModel categoryModel, UserEntity userEntity) { + return new CategoryEntity( + categoryModel.getCategoryId(), + categoryModel.getCategoryName(), + categoryModel.getTransactionType(), + userEntity, + 0, + null, + null); + } + } diff --git a/src/main/java/com/example/demo/app/infra/entity/CategoryEntity.java b/src/main/java/com/example/demo/app/infra/entity/CategoryEntity.java index d6a9fc3..17d3ca7 100644 --- a/src/main/java/com/example/demo/app/infra/entity/CategoryEntity.java +++ b/src/main/java/com/example/demo/app/infra/entity/CategoryEntity.java @@ -4,9 +4,12 @@ import java.util.List; 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.OneToMany; import jakarta.persistence.Table; @@ -32,6 +35,13 @@ public class CategoryEntity { @Column(name = "transaction_type", nullable = false) private Integer transactionType; + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id") + private UserEntity userEntity; + + @Column(name = "delete_flag") + private Integer deleteFlag; + @OneToMany(mappedBy = "categoryEntity") private List transactionEntity; diff --git a/src/main/java/com/example/demo/app/presentation/form/CategoryForm.java b/src/main/java/com/example/demo/app/presentation/form/CategoryForm.java index 56172c3..76ac65f 100644 --- a/src/main/java/com/example/demo/app/presentation/form/CategoryForm.java +++ b/src/main/java/com/example/demo/app/presentation/form/CategoryForm.java @@ -25,4 +25,11 @@ public class CategoryForm { return categoryModelList.stream().map(CategoryForm::convertFrom).toList(); } + public static CategoryModel convertTo(CategoryForm categoryForm) { + return new CategoryModel( + categoryForm.getCategoryId(), + categoryForm.getCategoryName(), + categoryForm.getTransactionType()); + } + } From b8886fe47b5d76e0d4465f37937cf10b0f949036 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 15:32:57 +0900 Subject: [PATCH 5/9] =?UTF-8?q?[EDIT]=20Category=E4=B8=80=E8=A6=A7?= =?UTF-8?q?=E3=81=B8=E3=81=AE=E9=81=B7=E7=A7=BB=E3=83=9C=E3=82=BF=E3=83=B3?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=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 --- 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 03afea0..03a51c0 100644 --- a/src/main/resources/templates/transaction_detail.html +++ b/src/main/resources/templates/transaction_detail.html @@ -60,6 +60,10 @@ +
+ + +
From 4a574294b75f6060c3d1782519556966e4711a91 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 15:33:37 +0900 Subject: [PATCH 6/9] =?UTF-8?q?[EDIT]=20=E3=83=87=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AB=E3=83=88=E3=82=AB=E3=83=86=E3=82=B4=E3=83=AA=E3=83=BB?= =?UTF-8?q?=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E3=82=AB=E3=83=86=E3=82=B4?= =?UTF-8?q?=E3=83=AA=E4=B8=A1=E6=96=B9=E5=8F=96=E5=BE=97=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4=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 --- .../controller/TransactionController.java | 47 ++++++++++++++----- 1 file changed, 35 insertions(+), 12 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 5b4b753..8643554 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 @@ -3,6 +3,7 @@ package com.example.demo.app.presentation.controller; import java.time.LocalDate; import java.time.YearMonth; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -185,8 +186,9 @@ public class TransactionController { @GetMapping("/transaction/create") public String createOneGet(@RequestParam(defaultValue = "") LocalDate today, Long fixedCostId, - Model model) { + Model model, HttpSession session) { + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); if (today == null) { today = LocalDate.now(); } @@ -196,11 +198,21 @@ public class TransactionController { FixedCostForm fixedCostForm = FixedCostForm.convertFrom(fixedCostService.findById(fixedCostId)); transactionForm.setCategoryId(fixedCostForm.getCategoryId()); transactionForm.setAmount(fixedCostForm.getAmount()); - transactionForm.setTransactionType(CategoryForm.convertFrom(categoryService.findOne(fixedCostForm.getCategoryId())).getTransactionType()); + transactionForm.setTransactionType(CategoryForm + .convertFrom(categoryService.findOne(fixedCostForm.getCategoryId())).getTransactionType()); } - List categoryFormList = CategoryForm.convertFrom(categoryService.findAll()); + List categoryFormList = new ArrayList<>( + CategoryForm.convertFrom(categoryService.findAllExceptCustom())); + List categoryFormCustomList = CategoryForm + .convertFrom(categoryService.findAllByuserId(loginUser.getUserId())); + + if (!categoryFormCustomList.isEmpty()) { + for (CategoryForm form : categoryFormCustomList) { + categoryFormList.add(form); + } + } System.out.println(transactionForm.getCategoryName() + " " + transactionForm.getAmount()); @@ -232,13 +244,24 @@ public class TransactionController { @SessionCheck @GetMapping("/transaction/update") 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) { today = LocalDate.now(); } - List categoryFormList = CategoryForm.convertFrom(categoryService.findAll()); + List categoryFormList = new ArrayList<>( + CategoryForm.convertFrom(categoryService.findAllExceptCustom())); + + List categoryFormCustomList = CategoryForm + .convertFrom(categoryService.findAllByuserId(loginUser.getUserId())); + + if (!categoryFormCustomList.isEmpty()) { + for (CategoryForm form : categoryFormCustomList) { + categoryFormList.add(form); + } + } TransactionForm transactionForm = TransactionForm.convertFrom( transactionService.findByTransactionId(transactionId), @@ -348,19 +371,19 @@ public class TransactionController { model.addAttribute("totalIncome", totalIncome); model.addAttribute("totalExpense", totalExpense); -// List 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"; } From 3e6a7f5a7466500cee0accc3fae1160f287d99b2 Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 15:34:18 +0900 Subject: [PATCH 7/9] =?UTF-8?q?[EDIT]=20Category=E3=81=AECRUD=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0=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 --- .../app/domain/service/CategoryService.java | 8 ++ .../service/impl/CategoryServiceImpl.java | 30 ++++++- .../infra/repository/CategoryRepository.java | 8 ++ .../controller/CategoryController.java | 87 +++++++++++++++++++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/example/demo/app/presentation/controller/CategoryController.java diff --git a/src/main/java/com/example/demo/app/domain/service/CategoryService.java b/src/main/java/com/example/demo/app/domain/service/CategoryService.java index 2f61d9d..dac11e0 100644 --- a/src/main/java/com/example/demo/app/domain/service/CategoryService.java +++ b/src/main/java/com/example/demo/app/domain/service/CategoryService.java @@ -13,4 +13,12 @@ public interface CategoryService { public CategoryModel findOneByCategoryName(String categoryName); public CategoryModel findByTransactionId(Long transactionId); + + public List findAllByuserId(Long userId); + + public void delete(Long categoryId); + + public CategoryModel save(CategoryModel categoryModel, Long userId); + + public List findAllExceptCustom(); } diff --git a/src/main/java/com/example/demo/app/domain/service/impl/CategoryServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/CategoryServiceImpl.java index b48188b..0a1842d 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/CategoryServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/CategoryServiceImpl.java @@ -9,6 +9,7 @@ import com.example.demo.app.domain.model.CategoryModel; import com.example.demo.app.domain.service.CategoryService; import com.example.demo.app.infra.entity.CategoryEntity; import com.example.demo.app.infra.repository.CategoryRepository; +import com.example.demo.app.infra.repository.UserRepository; import lombok.RequiredArgsConstructor; @@ -17,6 +18,7 @@ import lombok.RequiredArgsConstructor; public class CategoryServiceImpl implements CategoryService { private final CategoryRepository categoryRepository; + private final UserRepository userRepository; public List findAll() { @@ -51,6 +53,30 @@ public class CategoryServiceImpl implements CategoryService { public CategoryModel findByTransactionId(Long transactionId) { return CategoryModel.convertFrom(categoryRepository.findByTransactionId(transactionId)); } - - + + public List findAllByuserId(Long userId) { + + return CategoryModel.convertFrom(categoryRepository.findByUserId(userId)); + + } + + public void delete(Long categoryId) { + + categoryRepository.deleteById(categoryId); + + } + + public CategoryModel save(CategoryModel categoryModel, Long userId) { + + return CategoryModel.convertFrom( + categoryRepository.save(CategoryModel.convertTo(categoryModel, userRepository.findById(userId).get()))); + + } + + public List findAllExceptCustom() { + + return CategoryModel.convertFrom(categoryRepository.findAllExceptCustom()); + + } + } diff --git a/src/main/java/com/example/demo/app/infra/repository/CategoryRepository.java b/src/main/java/com/example/demo/app/infra/repository/CategoryRepository.java index c6d1a47..b7fa795 100644 --- a/src/main/java/com/example/demo/app/infra/repository/CategoryRepository.java +++ b/src/main/java/com/example/demo/app/infra/repository/CategoryRepository.java @@ -1,5 +1,7 @@ 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.data.repository.query.Param; @@ -15,4 +17,10 @@ public interface CategoryRepository extends JpaRepository @Query("select c from CategoryEntity c inner join TransactionEntity t on c.categoryId = t.categoryEntity.categoryId where t.transactionId = :transactionId") public CategoryEntity findByTransactionId(Long transactionId); + @Query("select c from CategoryEntity c where c.userEntity.userId = :userId") + public List findByUserId(Long userId); + + @Query("select c from CategoryEntity c where c.userEntity.userId is null") + public List findAllExceptCustom(); + } diff --git a/src/main/java/com/example/demo/app/presentation/controller/CategoryController.java b/src/main/java/com/example/demo/app/presentation/controller/CategoryController.java new file mode 100644 index 0000000..5576a9e --- /dev/null +++ b/src/main/java/com/example/demo/app/presentation/controller/CategoryController.java @@ -0,0 +1,87 @@ +package com.example.demo.app.presentation.controller; + +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.app.domain.model.LoginModel; +import com.example.demo.app.domain.service.CategoryService; +import com.example.demo.app.presentation.form.CategoryForm; + +import lombok.RequiredArgsConstructor; + +@Controller +@RequiredArgsConstructor +public class CategoryController { + + private final CategoryService categoryService; + + + @GetMapping("/category/list") + public String categoryListGet(Model model, HttpSession session) { + + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + + List categoryFormList = CategoryForm.convertFrom(categoryService.findAllByuserId(loginUser.getUserId())); + + model.addAttribute("categoryFormList", categoryFormList); + + return "category-list"; + } + + @GetMapping("/category/create") + public String categoryCreateGet(@ModelAttribute CategoryForm categoryForm) { + + return "category-create"; + } + + @PostMapping("/category/create") + public String categoryCreatePost(@ModelAttribute CategoryForm categoryForm, HttpSession session) { + + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + + + categoryService.save(CategoryForm.convertTo(categoryForm), loginUser.getUserId()); + + return "redirect:/category/list"; + } + + @GetMapping("/category/update") + public String categoryUpdateGet(Model model, Long categoryId) { + + CategoryForm categoryForm = CategoryForm.convertFrom(categoryService.findOne(categoryId)); + + model.addAttribute("categoryId", categoryId); + model.addAttribute("categoryForm", categoryForm); + + return "category-update"; + } + + @PostMapping("/category/update") + public String categoryUpdatePost(@ModelAttribute CategoryForm categoryForm, HttpSession session, Long categoryId) { + + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + + categoryForm.setCategoryId(categoryId); + + categoryService.save(CategoryForm.convertTo(categoryForm), loginUser.getUserId()); + + return "redirect:/category/list"; + } + + @PostMapping("/category/delete") + public String categoryDeletePost(Long categoryId) { + + categoryService.delete(categoryId); + + return "redirect:/category/list"; + } + + +} From 95bfd4ed0efa29bc940b4a450eb977379a3b5a9f Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 24 Sep 2026 15:34:43 +0900 Subject: [PATCH 8/9] =?UTF-8?q?[ADD]=20=E3=82=AB=E3=83=86=E3=82=B4?= =?UTF-8?q?=E3=83=AA=E3=81=AE=E4=B8=80=E8=A6=A7=E3=83=BB=E4=BD=9C=E6=88=90?= =?UTF-8?q?=E3=83=BB=E4=BF=AE=E6=AD=A3=E7=94=BB=E9=9D=A2=E3=82=92=E4=BD=9C?= =?UTF-8?q?=E6=88=90=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 --- .../resources/templates/category-create.html | 52 +++++++++++++++ .../resources/templates/category-list.html | 63 +++++++++++++++++++ .../resources/templates/category-update.html | 54 ++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 src/main/resources/templates/category-create.html create mode 100644 src/main/resources/templates/category-list.html create mode 100644 src/main/resources/templates/category-update.html diff --git a/src/main/resources/templates/category-create.html b/src/main/resources/templates/category-create.html new file mode 100644 index 0000000..1b5721d --- /dev/null +++ b/src/main/resources/templates/category-create.html @@ -0,0 +1,52 @@ + + + + + + Insert title here + + + + + + + +
+ +

カテゴリ登録

+ +
+ + +
+ + + +
+ +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + + + \ No newline at end of file diff --git a/src/main/resources/templates/category-list.html b/src/main/resources/templates/category-list.html new file mode 100644 index 0000000..3b84106 --- /dev/null +++ b/src/main/resources/templates/category-list.html @@ -0,0 +1,63 @@ + + + + + + カテゴリ一覧 + + + + + + + +
+ +
+
    +
  • + +
    +

    + カテゴリ名: + +
    + 収支区分: + + +

    +
    + +
    + +
    + + + +
    + +
    + + + +
    + +
    + +
    +
    +
  • +
+
+ + + +
+ + +
+ +
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/category-update.html b/src/main/resources/templates/category-update.html new file mode 100644 index 0000000..75d817b --- /dev/null +++ b/src/main/resources/templates/category-update.html @@ -0,0 +1,54 @@ + + + + + + Insert title here + + + + + + + +
+ +

カテゴリ編集

+ +
+ + +
+ + + +
+ +
+ +
+ + + +
+ +
+ + + + + +
+ +
+ + + + + \ No newline at end of file From 29d93d54539d727c27e4af6eb57e332ae8acb091 Mon Sep 17 00:00:00 2001 From: s-choi Date: Fri, 25 Sep 2026 12:41:52 +0900 Subject: [PATCH 9/9] =?UTF-8?q?[UPDATE]=202=E6=AC=A1=E6=A9=9F=E8=83=BD?= =?UTF-8?q?=E3=82=92=E5=AE=9F=E8=A3=85=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 --- .../app/domain/model/AllocationModel.java | 28 ++ .../demo/app/domain/model/CourseModel.java | 9 + .../demo/app/domain/model/GoalModel.java | 10 +- .../app/domain/service/AllocationService.java | 2 + .../app/domain/service/CourseService.java | 2 + .../demo/app/domain/service/GoalService.java | 2 + .../service/impl/AllocationServiceImpl.java | 35 ++- .../service/impl/CourseServiceImpl.java | 13 + .../domain/service/impl/GoalServiceImpl.java | 27 +- .../service/impl/TransactionServiceImpl.java | 2 +- .../app/infra/repository/GoalRepository.java | 5 + .../controller/CourseController.java | 122 +++++--- .../controller/GoalController.java | 265 ++++++++++++++++-- .../app/presentation/form/AllocationForm.java | 2 +- .../presentation/form/AllocationFormList.java | 45 +++ .../app/presentation/form/CourseForm.java | 8 + .../form/MonthlyAchievementForm.java | 17 ++ .../presentation/form/MonthlySavingForm.java | 19 ++ .../resources/templates/course_create.html | 48 ++++ .../templates/course_create_ratio.html | 109 +++++++ src/main/resources/templates/goal_record.html | 89 ++++++ src/main/resources/templates/goal_view.html | 182 ++++++++++-- .../resources/templates/select_course.html | 81 +++--- 23 files changed, 990 insertions(+), 132 deletions(-) create mode 100644 src/main/java/com/example/demo/app/presentation/form/AllocationFormList.java create mode 100644 src/main/java/com/example/demo/app/presentation/form/MonthlyAchievementForm.java create mode 100644 src/main/java/com/example/demo/app/presentation/form/MonthlySavingForm.java create mode 100644 src/main/resources/templates/course_create.html create mode 100644 src/main/resources/templates/course_create_ratio.html create mode 100644 src/main/resources/templates/goal_record.html diff --git a/src/main/java/com/example/demo/app/domain/model/AllocationModel.java b/src/main/java/com/example/demo/app/domain/model/AllocationModel.java index 1f6a9c1..c01af97 100644 --- a/src/main/java/com/example/demo/app/domain/model/AllocationModel.java +++ b/src/main/java/com/example/demo/app/domain/model/AllocationModel.java @@ -1,5 +1,12 @@ package com.example.demo.app.domain.model; +import java.util.List; + +import com.example.demo.app.infra.entity.AllocationEntity; +import com.example.demo.app.infra.entity.CategoryEntity; +import com.example.demo.app.infra.entity.CourseEntity; +import com.example.demo.app.presentation.form.AllocationForm; + import lombok.AllArgsConstructor; import lombok.Getter; @@ -11,4 +18,25 @@ public class AllocationModel { private Long courseId; private Integer allocationRatio; + public static AllocationModel convertFrom(AllocationEntity allocationEntity) { + return new AllocationModel(allocationEntity.getCategoryEntity().getCategoryId(), allocationEntity.getCourseEntity().getCourseId(), allocationEntity.getAllocationRatio()); + } + + public static List convertFrom(List allocationEntityList){ + return allocationEntityList.stream().map(AllocationModel::convertFrom).toList(); + } + + public static AllocationModel convertFrom1(AllocationForm allocationForm) { + return new AllocationModel(allocationForm.getCategoryId(), allocationForm.getCourseId(), allocationForm.getAllocationRatio()); + } + + public static List convertFrom1(List allocationFormList){ + return allocationFormList.stream().map(AllocationModel::convertFrom1).toList(); + } + + public static AllocationEntity convertTo(CategoryEntity categoryEntity, CourseEntity courseEntity, Integer allocationRatio) { + return new AllocationEntity(categoryEntity, courseEntity, allocationRatio); + } + + } diff --git a/src/main/java/com/example/demo/app/domain/model/CourseModel.java b/src/main/java/com/example/demo/app/domain/model/CourseModel.java index e9e8014..43303eb 100644 --- a/src/main/java/com/example/demo/app/domain/model/CourseModel.java +++ b/src/main/java/com/example/demo/app/domain/model/CourseModel.java @@ -3,6 +3,7 @@ package com.example.demo.app.domain.model; import java.util.List; import com.example.demo.app.infra.entity.CourseEntity; +import com.example.demo.app.infra.entity.UserEntity; import lombok.AllArgsConstructor; import lombok.Getter; @@ -25,4 +26,12 @@ public class CourseModel { public static List convertFrom(List courseEntityList) { return courseEntityList.stream().map(CourseModel::convertFrom).toList(); } + + public static CourseEntity convertTo(CourseModel courseModel, List userEntityList) { + return new CourseEntity( + courseModel.getCourseId(), + courseModel.getCourseName(), + courseModel.getDescription(), + userEntityList); + } } 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 497c5b4..b5a7214 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 @@ -1,6 +1,8 @@ package com.example.demo.app.domain.model; import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; import com.example.demo.app.infra.entity.GoalEntity; import com.example.demo.app.infra.entity.UserEntity; @@ -30,6 +32,8 @@ public class GoalModel { private Integer currentAmount; // 現在の資産 private Long userId; + + private List savingList; public static GoalModel convertFrom(GoalEntity goalEntity, int achievementRate, int currentAmount) { return new GoalModel( @@ -41,7 +45,8 @@ public class GoalModel { goalEntity.getGoalComplete(), achievementRate, currentAmount, - goalEntity.getUserEntity().getUserId()); + goalEntity.getUserEntity().getUserId(), + new ArrayList<>()); } public static GoalEntity convertTo(GoalModel goalModel, UserEntity userEntity) { @@ -64,7 +69,8 @@ public class GoalModel { goalForm.getDeadline(), goalForm.getGoalComplete() ,null,null, - goalForm.getUserId()); + goalForm.getUserId(), + new ArrayList<>()); } } \ No newline at end of file diff --git a/src/main/java/com/example/demo/app/domain/service/AllocationService.java b/src/main/java/com/example/demo/app/domain/service/AllocationService.java index 240c1fd..753a356 100644 --- a/src/main/java/com/example/demo/app/domain/service/AllocationService.java +++ b/src/main/java/com/example/demo/app/domain/service/AllocationService.java @@ -7,5 +7,7 @@ import com.example.demo.app.domain.model.AllocationModel; public interface AllocationService { public List findAll(); + + public List save(List allocationModelList); } diff --git a/src/main/java/com/example/demo/app/domain/service/CourseService.java b/src/main/java/com/example/demo/app/domain/service/CourseService.java index 406916f..4e583ee 100644 --- a/src/main/java/com/example/demo/app/domain/service/CourseService.java +++ b/src/main/java/com/example/demo/app/domain/service/CourseService.java @@ -11,4 +11,6 @@ public interface CourseService { public CourseModel findById(Long courseId); public Long findByName(String courName); + + public CourseModel save(CourseModel courseModel, Long userId); } 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 9272331..05e9e89 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 @@ -15,6 +15,8 @@ public interface GoalService { GoalModel updateGoal(GoalModel goalModel, Long userId); public void delete(Long goalId); + + public void updateGoalComplete(Long userId); // void deleteGoal(Long goalId); diff --git a/src/main/java/com/example/demo/app/domain/service/impl/AllocationServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/AllocationServiceImpl.java index fa287d4..5f18d33 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/AllocationServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/AllocationServiceImpl.java @@ -1,5 +1,6 @@ package com.example.demo.app.domain.service.impl; +import java.util.ArrayList; import java.util.List; import org.springframework.stereotype.Service; @@ -8,6 +9,8 @@ import com.example.demo.app.domain.model.AllocationModel; import com.example.demo.app.domain.service.AllocationService; import com.example.demo.app.infra.entity.AllocationEntity; import com.example.demo.app.infra.repository.AllocationRepository; +import com.example.demo.app.infra.repository.CategoryRepository; +import com.example.demo.app.infra.repository.CourseRepository; import lombok.RequiredArgsConstructor; @@ -15,10 +18,34 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class AllocationServiceImpl implements AllocationService { - AllocationRepository allocationRepository; - - public List findAll(){ + private final AllocationRepository allocationRepository; + private final CategoryRepository categoryRepository; + private final CourseRepository courseRepository; + + public List findAll() { return AllocationEntity.createAllocationModelList(allocationRepository.findAll()); } - + + public List save(List allocationModelList) { + + List allocationEntityList = new ArrayList<>(); + + allocationModelList.forEach(allocationModel -> { + allocationEntityList.add( + AllocationModel.convertTo( + categoryRepository.findById(allocationModel.getCategoryId()).get(), + courseRepository.findById(allocationModel.getCourseId()).get(), + allocationModel.getAllocationRatio())); + + }); + + List result = new ArrayList<>(); + for (AllocationEntity allocationEntity : allocationEntityList) { + result.add(AllocationModel.convertFrom(allocationRepository.save(allocationEntity))); + } + + + return result; + } + } diff --git a/src/main/java/com/example/demo/app/domain/service/impl/CourseServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/CourseServiceImpl.java index cc2f776..046c6dc 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/CourseServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/CourseServiceImpl.java @@ -1,5 +1,6 @@ package com.example.demo.app.domain.service.impl; +import java.util.ArrayList; import java.util.List; import org.springframework.stereotype.Service; @@ -7,7 +8,9 @@ import org.springframework.stereotype.Service; import com.example.demo.app.domain.model.CourseModel; import com.example.demo.app.domain.service.CourseService; import com.example.demo.app.infra.entity.CourseEntity; +import com.example.demo.app.infra.entity.UserEntity; import com.example.demo.app.infra.repository.CourseRepository; +import com.example.demo.app.infra.repository.UserRepository; import lombok.RequiredArgsConstructor; @@ -16,6 +19,7 @@ import lombok.RequiredArgsConstructor; public class CourseServiceImpl implements CourseService { private final CourseRepository courseRepository; + private final UserRepository userRepository; public List findAll(){ @@ -29,4 +33,13 @@ public class CourseServiceImpl implements CourseService { public Long findByName(String courseName) { return courseRepository.findByCourseName(courseName).getCourseId(); } + + public CourseModel save(CourseModel courseModel, Long userId) { + + List userEntityList = new ArrayList<>(); + userEntityList.add(userRepository.findById(userId).get()); + + return CourseModel.convertFrom( courseRepository.save( CourseModel.convertTo(courseModel, userEntityList))); + + } } 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 0708ec9..5e30fed 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 @@ -3,6 +3,8 @@ package com.example.demo.app.domain.service.impl; import java.util.ArrayList; import java.util.List; +import jakarta.transaction.Transactional; + import org.springframework.stereotype.Service; import com.example.demo.app.domain.model.GoalModel; @@ -10,6 +12,7 @@ import com.example.demo.app.domain.service.GoalService; import com.example.demo.app.infra.entity.GoalEntity; import com.example.demo.app.infra.entity.UserEntity; import com.example.demo.app.infra.repository.GoalRepository; +import com.example.demo.app.infra.repository.TransactionRepository; import com.example.demo.app.infra.repository.UserRepository; import lombok.RequiredArgsConstructor; @@ -20,6 +23,7 @@ public class GoalServiceImpl implements GoalService { private final GoalRepository goalRepository; private final UserRepository userRepository; + private final TransactionRepository transactionRepository; @Override public GoalModel getGoalById(Long goalId) { @@ -43,7 +47,7 @@ public class GoalServiceImpl implements GoalService { // 現在の資産 = 貯蓄金 + 収支合計 int currentAmount = userEntity.getSaving() + transactionTotal; - + // 達成率(%) = 現在の資産 ÷ 目標金額 × 100 List goalModelList = new ArrayList(); @@ -83,4 +87,25 @@ public class GoalServiceImpl implements GoalService { goalRepository.deleteById(goalId); } + @Transactional + public void updateGoalComplete(Long userId) { + UserEntity userEntity = userRepository.findById(userId).orElseThrow(); + List goalEntityList = goalRepository.findAllByUserId(userId); + + int transactionTotal = userEntity.getTransactionEntityList().stream() + .mapToInt(t -> { + int sign = t.getCategoryEntity().getTransactionType() == 1 ? 1 : -1; + return sign * t.getAmount(); + }) + .sum(); + + int currentAmount = userEntity.getSaving() + transactionTotal; + + goalEntityList.stream().forEach(goalEntity -> { + if (goalEntity.getTargetAmount() <= currentAmount) { + goalRepository.updateCompleteByGoalId(goalEntity.getGoalId()); + } + }); + } + } \ No newline at end of file diff --git a/src/main/java/com/example/demo/app/domain/service/impl/TransactionServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/TransactionServiceImpl.java index cf4e496..cb243cc 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/TransactionServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/TransactionServiceImpl.java @@ -164,5 +164,5 @@ public class TransactionServiceImpl implements TransactionService { public void deleteTransaction(Long transactionId) { transactionRepository.deleteById(transactionId); } - + } 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 1de888e..b65bb51 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 @@ -3,6 +3,7 @@ package com.example.demo.app.infra.repository; import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; @@ -14,4 +15,8 @@ public interface GoalRepository extends JpaRepository { @Query("select g from GoalEntity g where g.userEntity.userId = :userId") public List findAllByUserId(Long userId); + @Modifying(clearAutomatically = true, flushAutomatically = true) + @Query("update GoalEntity g set g.goalComplete = 1 where g.goalId = :goalId") + public int updateCompleteByGoalId(Long goalId); + } \ No newline at end of file diff --git a/src/main/java/com/example/demo/app/presentation/controller/CourseController.java b/src/main/java/com/example/demo/app/presentation/controller/CourseController.java index b4e34f8..7628b09 100644 --- a/src/main/java/com/example/demo/app/presentation/controller/CourseController.java +++ b/src/main/java/com/example/demo/app/presentation/controller/CourseController.java @@ -1,5 +1,8 @@ package com.example.demo.app.presentation.controller; +import java.util.ArrayList; +import java.util.List; + import jakarta.servlet.http.HttpSession; import org.springframework.stereotype.Controller; @@ -10,72 +13,113 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; import com.example.demo.aop.aspect.SessionCheck; +import com.example.demo.app.domain.model.AllocationModel; import com.example.demo.app.domain.model.LoginModel; +import com.example.demo.app.domain.service.AllocationService; import com.example.demo.app.domain.service.CourseInfoService; import com.example.demo.app.domain.service.CourseService; import com.example.demo.app.domain.service.UserService; +import com.example.demo.app.presentation.form.AllocationFormList; import com.example.demo.app.presentation.form.CourseForm; import com.example.demo.app.presentation.form.CourseInfoForm; import com.example.demo.app.presentation.form.UserForm; import lombok.RequiredArgsConstructor; - @Controller @RequiredArgsConstructor public class CourseController { - private final CourseService courseService; - private final CourseInfoService courseInfoService; - private final UserService userService; - - - @PostMapping("/user/register/course") - public String showSelectCourse(@ModelAttribute UserForm userForm, Model model, HttpSession session) { - - - + private final CourseService courseService; + private final CourseInfoService courseInfoService; + private final UserService userService; + private final AllocationService allocationService; + + + @PostMapping("/user/register/course") + public String showSelectCourse(@ModelAttribute UserForm userForm, Model model, HttpSession session) { + session.setAttribute("userForm", userForm); model.addAttribute("mode", "regist"); model.addAttribute("currentCourseId", 4); model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll())); model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll())); - - return "select_course"; - - - } - - @SessionCheck - @GetMapping("/course") - public String showChangeCourse(Model model, HttpSession session) { - - + + return "select_course"; + + } + + @SessionCheck + @GetMapping("/course") + public String showChangeCourse(Model model, HttpSession session) { + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); Long userId = loginUser.getUserId(); - + Long currentCourseId = userService.findByUserId(userId).getCourseId(); model.addAttribute("mode", "change"); model.addAttribute("currentCourseId", currentCourseId); model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll())); model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll())); - return "select_course"; - - - } - - @SessionCheck - @PostMapping("/change") - public String changeCourse(@RequestParam Long courseId, HttpSession httpSession) { - - LoginModel loginUser = (LoginModel) httpSession.getAttribute("loginUser"); - userService.updateCourse(loginUser.getUserId(), courseId); - - return "redirect:/menu"; - } - - + } + + @SessionCheck + @PostMapping("/change") + public String changeCourse(@RequestParam Long courseId, HttpSession httpSession) { + + LoginModel loginUser = (LoginModel) httpSession.getAttribute("loginUser"); + + userService.updateCourse(loginUser.getUserId(), courseId); + + return "redirect:/menu"; + } + + @SessionCheck + @GetMapping("/course/create") + public String createCourseGet(@ModelAttribute CourseForm courseForm, HttpSession session) { + + return "course_create"; + } + + @SessionCheck + @PostMapping("/course/create/ratio") + public String createCourse(@ModelAttribute CourseForm courseForm, @ModelAttribute AllocationFormList allocationFormList, + HttpSession session, Model model) { + + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + + CourseForm form = CourseForm.convertFrom(courseService.save(CourseForm.convertTo(courseForm), loginUser.getUserId())); + + session.setAttribute("courseId", form.getCourseId()); + + return "course_create_ratio"; + } + + @SessionCheck + @PostMapping("/course/create") + public String createCoursePost(@ModelAttribute AllocationFormList allocationFormList, HttpSession session) { + + + List allocationModelList = new ArrayList<>(); + + allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId1(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio1())); + allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId2(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio2())); + allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId3(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio3())); + allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId4(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio4())); + allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId5(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio5())); + allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId6(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio6())); + allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId7(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio7())); + allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId8(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio8())); + allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId9(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio9())); + allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId10(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio10())); + allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId11(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio11())); + + allocationService.save(allocationModelList); + + return "redirect:/course"; + } + } 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 abb05a4..a29e1a1 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 @@ -1,6 +1,13 @@ package com.example.demo.app.presentation.controller; +import java.time.LocalDate; +import java.time.YearMonth; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import jakarta.servlet.http.HttpSession; @@ -14,8 +21,15 @@ import org.springframework.web.bind.annotation.RequestMapping; import com.example.demo.aop.aspect.SessionCheck; import com.example.demo.app.domain.model.GoalModel; import com.example.demo.app.domain.model.LoginModel; +import com.example.demo.app.domain.service.CategoryService; 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.GoalForm; +import com.example.demo.app.presentation.form.MonthlyAchievementForm; +import com.example.demo.app.presentation.form.MonthlySavingForm; +import com.example.demo.app.presentation.form.TransactionForm; import lombok.RequiredArgsConstructor; @@ -25,19 +39,183 @@ import lombok.RequiredArgsConstructor; public class GoalController { private final GoalService goalService; + private final TransactionService transactionService; + private final UserService userService; + private final CategoryService categoryService; @SessionCheck @GetMapping("") - public String getGoal(Model model, HttpSession session) { - - LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + public String getGoal( + Model model, + HttpSession session, + Long goalId) { - Long userId = loginUser.getUserId(); - - List goalModelList = goalService.getGoalByUserId(userId); - List goalFormList = GoalForm.convertFrom(goalModelList); + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + + Long userId = loginUser.getUserId(); + goalService.updateGoalComplete(userId); + List goalModelList = goalService.getGoalByUserId(userId); + + List goalFormList1 = GoalForm.convertFrom(goalModelList); + + List goalFormList = goalFormList1.stream() + .filter(goalForm -> goalForm.getGoalComplete() == 0) + .collect(Collectors.toList()); + + model.addAttribute( + "goalFormList", + goalFormList); + + if (goalFormList.isEmpty()) { + return "goal_view"; + } + + GoalForm graphGoal; + + if (goalId == null) { + + graphGoal = goalFormList.getFirst(); + + } else { + + graphGoal = goalFormList.stream() + .filter(goal -> goal.getGoalId().equals(goalId)) + .findFirst() + .orElse( + goalFormList.getFirst()); + } + + model.addAttribute( + "graphGoal", + graphGoal); + + int currentAmount = graphGoal.getCurrentAmount(); + + int targetAmount = graphGoal.getTargetAmount(); + + LocalDate startDate = LocalDate.of( + LocalDate.now().getYear(), + 1, + 1); + + LocalDate today = LocalDate.now(); + + Map> transactionFormMap = new HashMap<>(); + + transactionService + .findAllByDate( + startDate, + today, + userId) + .forEach((date, list) -> { + + List transactionFormList = list.stream() + .map(transaction -> { + + CategoryForm categoryForm = CategoryForm.convertFrom( + categoryService.findOne( + transaction.getCategoryId())); + + return TransactionForm.convertFrom( + transaction, + categoryForm.getCategoryName(), + transactionService.findTotalExpense( + startDate, + today, + loginUser.getUserId()), + transactionService.findTotalIncome( + startDate, + today, + loginUser.getUserId()), + categoryForm.getTransactionType()); + }) + .collect(Collectors.toList()); + + transactionFormMap.put( + date, + transactionFormList); + }); + + List monthlySavingList = new ArrayList<>(); + + YearMonth startMonth = YearMonth.from(startDate); + + YearMonth currentMonth = YearMonth.now(); + + YearMonth month = currentMonth; + + while (!month.isBefore(startMonth)) { + + int income = 0; + int expense = 0; + + for (Map.Entry> entry : transactionFormMap.entrySet()) { + + YearMonth transactionMonth = YearMonth.from(entry.getKey()); + + if (!transactionMonth.equals(month)) { + continue; + } + + for (TransactionForm transaction : entry.getValue()) { + + if (transaction.getAmount() == null) { + continue; + } + + if (transaction.getTransactionType() == 1) { + + income += transaction.getAmount(); + + } else if (transaction.getTransactionType() == 0) { + + expense += transaction.getAmount(); + } + } + } + + monthlySavingList.add( + new MonthlySavingForm( + month, + income, + expense, + currentAmount)); + + currentAmount = currentAmount + - income + + expense; + + month = month.minusMonths(1); + } + + Collections.reverse(monthlySavingList); + + List achievementList = new ArrayList<>(); + + for (MonthlySavingForm monthlySaving : monthlySavingList) { + + int savingAmount = monthlySaving.getSaving(); + + int achievementRate = 0; + + if (targetAmount > 0) { + + achievementRate = (int) ((double) savingAmount + / targetAmount + * 100); + } + + achievementList.add( + new MonthlyAchievementForm( + monthlySaving.getMonth(), + savingAmount, + achievementRate)); + } + + model.addAttribute( + "achievementList", + achievementList); - model.addAttribute("goalFormList", goalFormList); return "goal_view"; } @@ -61,50 +239,79 @@ public class GoalController { LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); Long userId = loginUser.getUserId(); - -// // 本人の目標かどうかを確認してから更新する -// GoalModel currentGoal = goalService.getGoalByUserId(userId); -// -// if (!currentGoal.getGoalId().equals(goalForm.getGoalId())) { -// return "redirect:/goal"; // 他人のデータを更新しようとしたら弾く -// } + + // // 本人の目標かどうかを確認してから更新する + // GoalModel currentGoal = goalService.getGoalByUserId(userId); + // + // if (!currentGoal.getGoalId().equals(goalForm.getGoalId())) { + // return "redirect:/goal"; // 他人のデータを更新しようとしたら弾く + // } GoalModel goalModel = GoalModel.convertFrom(goalForm); goalService.updateGoal(goalModel, userId); return "redirect:/goal"; } - - + @SessionCheck @GetMapping("/create") public String createGoalGet(@ModelAttribute GoalForm goalForm, HttpSession session) { - + return "goal_create"; } - + @SessionCheck @PostMapping("/create") public String createGoalPost(@ModelAttribute GoalForm goalForm, HttpSession session) { - + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); Long userId = loginUser.getUserId(); - + goalService.createGoal(GoalModel.convertFrom(goalForm), userId); - + return "redirect:/goal"; } - + @SessionCheck - @PostMapping("/delete") // フラグ考慮してないため、今度修正必要 - public String deleteGoal(Long goalId) { - + @PostMapping("/delete") // フラグ考慮してないため、今度修正必要 + public String deleteGoal(Long goalId, Long record) { + goalService.delete(goalId); + + if (record == null) { + return "redirect:/goal"; + } else { + return "redirect:/goal/record"; + } - return "redirect:/goal"; } - - + + @SessionCheck + @GetMapping("/record") + public String getRecord(HttpSession session, Model model) { + + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + + Long userId = loginUser.getUserId(); + goalService.updateGoalComplete(userId); + List goalModelList = goalService.getGoalByUserId(userId); + + List goalFormList = GoalForm.convertFrom(goalModelList); + + List goalCompleteFormList = new ArrayList<>(); + + goalFormList.stream().forEach(goalForm -> { + if (goalForm.getGoalComplete() == 1) { + goalCompleteFormList.add(goalForm); + } + }); + + model.addAttribute( + "goalCompleteFormList", + goalCompleteFormList); + + return "goal_record"; + } } \ No newline at end of file diff --git a/src/main/java/com/example/demo/app/presentation/form/AllocationForm.java b/src/main/java/com/example/demo/app/presentation/form/AllocationForm.java index 6c28c9b..57e2ea8 100644 --- a/src/main/java/com/example/demo/app/presentation/form/AllocationForm.java +++ b/src/main/java/com/example/demo/app/presentation/form/AllocationForm.java @@ -15,7 +15,7 @@ public class AllocationForm { private Long categoryId; private Long courseId; - private Integer allocationRatio; + private Integer allocationRatio; public static AllocationForm convertFrom(AllocationModel allocationModel) { return new AllocationForm(allocationModel.getCategoryId(), allocationModel.getCourseId(), allocationModel.getAllocationRatio()); diff --git a/src/main/java/com/example/demo/app/presentation/form/AllocationFormList.java b/src/main/java/com/example/demo/app/presentation/form/AllocationFormList.java new file mode 100644 index 0000000..d90ece4 --- /dev/null +++ b/src/main/java/com/example/demo/app/presentation/form/AllocationFormList.java @@ -0,0 +1,45 @@ +package com.example.demo.app.presentation.form; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class AllocationFormList { + + private Long categoryId1 = 1L; + private Integer allocationRatio1; + + private Long categoryId2 = 2L; + private Integer allocationRatio2; + + private Long categoryId3 = 3L; + private Integer allocationRatio3; + + private Long categoryId4 = 4L; + private Integer allocationRatio4; + + private Long categoryId5 = 5L; + private Integer allocationRatio5; + + private Long categoryId6 = 6L; + private Integer allocationRatio6; + + private Long categoryId7 = 7L; + private Integer allocationRatio7; + + private Long categoryId8 = 8L; + private Integer allocationRatio8; + + private Long categoryId9 = 9L; + private Integer allocationRatio9; + + private Long categoryId10 = 10L; + private Integer allocationRatio10; + + private Long categoryId11 = 11L; + private Integer allocationRatio11; + +} diff --git a/src/main/java/com/example/demo/app/presentation/form/CourseForm.java b/src/main/java/com/example/demo/app/presentation/form/CourseForm.java index 57ba52e..559f32d 100644 --- a/src/main/java/com/example/demo/app/presentation/form/CourseForm.java +++ b/src/main/java/com/example/demo/app/presentation/form/CourseForm.java @@ -30,4 +30,12 @@ public class CourseForm { return courseModelList.stream().map(CourseForm::convertFrom).toList(); } + public static CourseModel convertTo(CourseForm courseForm) { + return new CourseModel( + courseForm.getCourseId(), + courseForm.getCourseName(), + courseForm.getDescription() + ); + } + } diff --git a/src/main/java/com/example/demo/app/presentation/form/MonthlyAchievementForm.java b/src/main/java/com/example/demo/app/presentation/form/MonthlyAchievementForm.java new file mode 100644 index 0000000..cdac29a --- /dev/null +++ b/src/main/java/com/example/demo/app/presentation/form/MonthlyAchievementForm.java @@ -0,0 +1,17 @@ +package com.example.demo.app.presentation.form; + +import java.time.YearMonth; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class MonthlyAchievementForm { + + private YearMonth month; + + private Integer saving; + + private Integer achievementRate; +} diff --git a/src/main/java/com/example/demo/app/presentation/form/MonthlySavingForm.java b/src/main/java/com/example/demo/app/presentation/form/MonthlySavingForm.java new file mode 100644 index 0000000..8d4b9bf --- /dev/null +++ b/src/main/java/com/example/demo/app/presentation/form/MonthlySavingForm.java @@ -0,0 +1,19 @@ +package com.example.demo.app.presentation.form; + +import java.time.YearMonth; + +import lombok.AllArgsConstructor; +import lombok.Data; + +@Data +@AllArgsConstructor +public class MonthlySavingForm { + + private YearMonth month; + + private Integer income; + + private Integer expense; + + private Integer saving; +} diff --git a/src/main/resources/templates/course_create.html b/src/main/resources/templates/course_create.html new file mode 100644 index 0000000..d34bf5f --- /dev/null +++ b/src/main/resources/templates/course_create.html @@ -0,0 +1,48 @@ + + + + + + Insert title here + + + + + + + +
+ +

コース登録

+ +
+ + +
+ + + +
+ +
+ +
+ + + +
+ +
+ + + + +
+ +
+ + + + + \ No newline at end of file diff --git a/src/main/resources/templates/course_create_ratio.html b/src/main/resources/templates/course_create_ratio.html new file mode 100644 index 0000000..dbbc5e0 --- /dev/null +++ b/src/main/resources/templates/course_create_ratio.html @@ -0,0 +1,109 @@ + + + + + + Insert title here + + + + + + + +
+ +

コース登録

+ +
+ + +
+ + +
+ +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ +
+ + +
+ +
+ + + + +
+ + +
+ + + + + \ No newline at end of file diff --git a/src/main/resources/templates/goal_record.html b/src/main/resources/templates/goal_record.html new file mode 100644 index 0000000..c0cf630 --- /dev/null +++ b/src/main/resources/templates/goal_record.html @@ -0,0 +1,89 @@ + + + + + + 目標履歴 + + + + + + +
+ +

目標履歴

+ + +
+
    +
  • +
    +

    + 目標名: + + + +
    + + 目標説明: + + + +
    + + 目標金額: + + + +
    + + 目標達成期限: + + + +
    + +

    + + + +
    + + +
    + +
    + + + + + + +
    + +
    + +
  • + +
+ +
+ +
+ + + +
+ + +
+ + + + + \ No newline at end of file diff --git a/src/main/resources/templates/goal_view.html b/src/main/resources/templates/goal_view.html index 38506cd..dfccdf1 100644 --- a/src/main/resources/templates/goal_view.html +++ b/src/main/resources/templates/goal_view.html @@ -6,62 +6,200 @@ 目標詳細 - + -
+

目標詳細

+ +
+ +

+ +

+ 目標金額: + +

+ +
+ + +
+ +
+ + + + +
+
    +
  • -

    - 目標名: - -
    - 目標説明: - -
    - 目標金額: - -
    - 目標達成期限: - -
    - 達成率: - -
    -

    + +
    + + + +

    + + 目標名: + + + +
    + + 目標説明: + + + +
    + + 目標金額: + + + +
    + + 目標達成期限: + + + +
    + + 達成率: + + + +

    + +
    +
    +
    + - + + +
    + +
    + - + + +
  • +
+
+
- + + +
+
+ + + +
+
+ \ No newline at end of file diff --git a/src/main/resources/templates/select_course.html b/src/main/resources/templates/select_course.html index 6f3aa5c..3a0a78b 100644 --- a/src/main/resources/templates/select_course.html +++ b/src/main/resources/templates/select_course.html @@ -1,50 +1,65 @@ + - - - -コース選択 + + + + コース選択 +
- +

コース選択

- - -
+ + + + + + + +
+
- +
-
-

- - -

-
-
- - - - - - - - - -
カテゴリ名配分(%)
-
-
-
+
+

+ + +

+
+
+ + + + + + + + + + +
カテゴリ名配分(%)
+
+
+
- +
- + + \ No newline at end of file