From 662e3433d23341ce5bf3089c4c06bb86c3e3cd41 Mon Sep 17 00:00:00 2001 From: k-oshita Date: Thu, 17 Sep 2026 16:12:15 +0900 Subject: [PATCH 1/6] =?UTF-8?q?[EDIT]=E7=9B=AE=E6=A8=99=E3=81=AEModel?= =?UTF-8?q?=E3=81=AE=E5=A4=89=E6=8F=9B=E9=83=A8=E5=88=86=E3=81=AE=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/app/domain/model/GoalModel.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) 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 7764281..94a57d2 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 @@ -2,6 +2,9 @@ package com.example.demo.app.domain.model; import java.time.LocalDate; +import com.example.demo.app.infra.entity.GoalEntity; +import com.example.demo.app.presentation.form.GoalForm; + import lombok.AllArgsConstructor; import lombok.Getter; @@ -21,4 +24,35 @@ public class GoalModel { private Integer goalComplete; + public static GoalModel convertFrom(GoalEntity goalEntity) { + return new GoalModel( + goalEntity.getGoalId(), + goalEntity.getGoalTitle(), + goalEntity.getGoalSubtitle(), + goalEntity.getTargetAmount(), + goalEntity.getDeadline(), + goalEntity.getGoalComplete()); + } + + public static GoalEntity convertTo(GoalModel goalModel) { + return new GoalEntity( + goalModel.getGoalId(), + goalModel.getGoalTitle(), + goalModel.getGoalSubtitle(), + goalModel.getTargetAmount(), + goalModel.getDeadline(), + goalModel.getGoalComplete(), + null); + } + + public static GoalModel convertFrom(GoalForm goalForm) { + return new GoalModel( + goalForm.getGoalId(), + goalForm.getGoalTitle(), + goalForm.getGoalSubtitle(), + goalForm.getTargetAmount(), + goalForm.getDeadline(), + goalForm.getGoalComplete()); + } + } \ No newline at end of file From 3833689759a2edb91693212137341091a2584366 Mon Sep 17 00:00:00 2001 From: k-oshita Date: Fri, 18 Sep 2026 10:05:15 +0900 Subject: [PATCH 2/6] =?UTF-8?q?[ADD]=E7=9B=AE=E6=A8=99=E3=82=92=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E3=81=99=E3=82=8B=E3=81=9F=E3=82=81=E6=A9=9F=E8=83=BD?= =?UTF-8?q?=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/app/domain/model/GoalModel.java | 58 ++++++++++++++++++ .../demo/app/domain/service/GoalService.java | 15 +++++ .../domain/service/impl/GoalServiceImpl.java | 49 +++++++++++++++ .../controller/GoalController.java | 61 +++++++++++++++++++ .../demo/app/presentation/form/GoalForm.java | 42 +++++++++++++ src/main/resources/templates/goal_edit.html | 41 +++++++++++++ src/main/resources/templates/goal_view.html | 33 ++++++++++ 7 files changed, 299 insertions(+) create mode 100644 src/main/java/com/example/demo/app/domain/model/GoalModel.java create mode 100644 src/main/java/com/example/demo/app/domain/service/GoalService.java create mode 100644 src/main/java/com/example/demo/app/domain/service/impl/GoalServiceImpl.java create mode 100644 src/main/java/com/example/demo/app/presentation/controller/GoalController.java create mode 100644 src/main/java/com/example/demo/app/presentation/form/GoalForm.java create mode 100644 src/main/resources/templates/goal_edit.html create mode 100644 src/main/resources/templates/goal_view.html 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 new file mode 100644 index 0000000..94a57d2 --- /dev/null +++ b/src/main/java/com/example/demo/app/domain/model/GoalModel.java @@ -0,0 +1,58 @@ +package com.example.demo.app.domain.model; + +import java.time.LocalDate; + +import com.example.demo.app.infra.entity.GoalEntity; +import com.example.demo.app.presentation.form.GoalForm; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class GoalModel { + + private Long goalId; + + private String goalTitle; + + private String goalSubtitle; + + private Integer targetAmount; + + private LocalDate deadline; + + private Integer goalComplete; + + public static GoalModel convertFrom(GoalEntity goalEntity) { + return new GoalModel( + goalEntity.getGoalId(), + goalEntity.getGoalTitle(), + goalEntity.getGoalSubtitle(), + goalEntity.getTargetAmount(), + goalEntity.getDeadline(), + goalEntity.getGoalComplete()); + } + + public static GoalEntity convertTo(GoalModel goalModel) { + return new GoalEntity( + goalModel.getGoalId(), + goalModel.getGoalTitle(), + goalModel.getGoalSubtitle(), + goalModel.getTargetAmount(), + goalModel.getDeadline(), + goalModel.getGoalComplete(), + null); + } + + public static GoalModel convertFrom(GoalForm goalForm) { + return new GoalModel( + goalForm.getGoalId(), + goalForm.getGoalTitle(), + goalForm.getGoalSubtitle(), + goalForm.getTargetAmount(), + goalForm.getDeadline(), + goalForm.getGoalComplete()); + } + +} \ No newline at end of file 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 new file mode 100644 index 0000000..ea2c3b7 --- /dev/null +++ b/src/main/java/com/example/demo/app/domain/service/GoalService.java @@ -0,0 +1,15 @@ +package com.example.demo.app.domain.service; + +import com.example.demo.app.domain.model.GoalModel; + +public interface GoalService { + + GoalModel getGoalById(Long goalId); + + GoalModel createGoal(GoalModel goalModel); + + GoalModel updateGoal(GoalModel goalModel); + +// void deleteGoal(Long goalId); + +} \ No newline at end of file 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 new file mode 100644 index 0000000..c7063f3 --- /dev/null +++ b/src/main/java/com/example/demo/app/domain/service/impl/GoalServiceImpl.java @@ -0,0 +1,49 @@ +package com.example.demo.app.domain.service.impl; + +import org.springframework.stereotype.Service; + +import com.example.demo.app.domain.model.GoalModel; +import com.example.demo.app.domain.service.GoalService; +import com.example.demo.app.infra.entity.GoalEntity; +import com.example.demo.app.infra.repository.GoalRepository; + +import lombok.RequiredArgsConstructor; + +@Service +@RequiredArgsConstructor +public class GoalServiceImpl implements GoalService { + + private final GoalRepository goalRepository; + + @Override + public GoalModel getGoalById(Long goalId) { + + GoalEntity goalEntity = goalRepository.findById(goalId).orElse(null); + + return GoalModel.convertFrom(goalEntity); + + } + + @Override + public GoalModel createGoal(GoalModel goalModel) { + + GoalEntity goalEntity = GoalModel.convertTo(goalModel); + + GoalEntity savedGoalEntity = goalRepository.save(goalEntity); + + return GoalModel.convertFrom(savedGoalEntity); + + } + + @Override + public GoalModel updateGoal(GoalModel goalModel) { + + GoalEntity goalEntity = GoalModel.convertTo(goalModel); + + GoalEntity updatedGoalEntity = goalRepository.save(goalEntity); + + return GoalModel.convertFrom(updatedGoalEntity); + + } + +} \ 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 new file mode 100644 index 0000000..96fe4ac --- /dev/null +++ b/src/main/java/com/example/demo/app/presentation/controller/GoalController.java @@ -0,0 +1,61 @@ +package com.example.demo.app.presentation.controller; + +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.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +import com.example.demo.app.domain.model.GoalModel; +import com.example.demo.app.domain.service.GoalService; +import com.example.demo.app.presentation.form.GoalForm; + +import lombok.RequiredArgsConstructor; + +@Controller +@RequiredArgsConstructor +@RequestMapping("/goal") +public class GoalController { + + private final GoalService goalService; + + @GetMapping("/{goalId}") + public String getGoal(@PathVariable Long goalId, Model model) { + + GoalModel goalModel = goalService.getGoalById(goalId); + + GoalForm goalForm = GoalForm.convertFrom(goalModel); + + model.addAttribute("goalForm", goalForm); + + return "goal_view"; + + } + + @GetMapping("/{goalId}/edit") + public String editGoal(@PathVariable Long goalId, Model model) { + + GoalModel goalModel = goalService.getGoalById(goalId); + + GoalForm goalForm = GoalForm.convertFrom(goalModel); + + model.addAttribute("goalForm", goalForm); + + return "goal_edit"; + + } + + @PostMapping("/update") + public String updateGoal(@ModelAttribute GoalForm goalForm) { + + GoalModel goalModel = GoalModel.convertFrom(goalForm); + + goalService.updateGoal(goalModel); + + return "redirect:/goal/" + goalForm.getGoalId(); + + } + +} \ No newline at end of file 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 new file mode 100644 index 0000000..42e5368 --- /dev/null +++ b/src/main/java/com/example/demo/app/presentation/form/GoalForm.java @@ -0,0 +1,42 @@ +package com.example.demo.app.presentation.form; + +import java.time.LocalDate; + +import com.example.demo.app.domain.model.GoalModel; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class GoalForm { + + private Long goalId; + + private String goalTitle; + + private String goalSubtitle; + + private Integer targetAmount; + + private LocalDate deadline; + + private Integer goalComplete; + + public static GoalForm convertFrom(GoalModel goalModel) { + return new GoalForm( + goalModel.getGoalId(), + goalModel.getGoalTitle(), + goalModel.getGoalSubtitle(), + goalModel.getTargetAmount(), + goalModel.getDeadline(), + goalModel.getGoalComplete()); + } + +// public static List convertFrom(List goalModelList) { +// return goalModelList.stream().map(GoalForm::convertFrom).toList(); +// } + +} \ No newline at end of file diff --git a/src/main/resources/templates/goal_edit.html b/src/main/resources/templates/goal_edit.html new file mode 100644 index 0000000..bfe55db --- /dev/null +++ b/src/main/resources/templates/goal_edit.html @@ -0,0 +1,41 @@ + + + + + 目標編集 + + + +

目標編集

+ +
+ + + +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ + + + +
+ + + \ No newline at end of file diff --git a/src/main/resources/templates/goal_view.html b/src/main/resources/templates/goal_view.html new file mode 100644 index 0000000..78bf40b --- /dev/null +++ b/src/main/resources/templates/goal_view.html @@ -0,0 +1,33 @@ + + + + + 目標詳細 + + + +

目標詳細

+ + + + + + + + + + + + + + + + + + +
目標名
目標補足説明
目標金額
目標達成期限
+ + 編集する + + + \ No newline at end of file From 571fcc6d902d40de637435df6639f5914165d6eb Mon Sep 17 00:00:00 2001 From: k-oshita Date: Fri, 18 Sep 2026 10:16:49 +0900 Subject: [PATCH 3/6] =?UTF-8?q?[add]=E4=BD=99=E5=88=86=E3=81=AA=E3=83=95?= =?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E3=82=B3=E3=83=9F=E3=83=83?= =?UTF-8?q?=E3=83=88=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/model/CategoryAnalysisModel.java | 2 +- .../service/impl/AnalysisServiceImpl.java | 132 ++++++++++++++++-- .../repository/AllocationRepository.java | 2 +- .../app/infra/repository/UserRepository.java | 1 + .../controller/AnalysisController.java | 12 +- src/main/resources/templates/analysis.html | 63 ++++++--- .../templates/user_register_confirm.html | 2 +- 7 files changed, 177 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/example/demo/app/domain/model/CategoryAnalysisModel.java b/src/main/java/com/example/demo/app/domain/model/CategoryAnalysisModel.java index 3a94930..47cdadf 100644 --- a/src/main/java/com/example/demo/app/domain/model/CategoryAnalysisModel.java +++ b/src/main/java/com/example/demo/app/domain/model/CategoryAnalysisModel.java @@ -13,7 +13,7 @@ public class CategoryAnalysisModel { private Integer previousMonthAmount; - private Integer previousMonthDifferenceAmount; + private Integer monthDifferenceAmount; private Integer courseLimitAmount; diff --git a/src/main/java/com/example/demo/app/domain/service/impl/AnalysisServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/AnalysisServiceImpl.java index 66f4bbc..d0f3388 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/AnalysisServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/AnalysisServiceImpl.java @@ -1,9 +1,21 @@ package com.example.demo.app.domain.service.impl; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + import org.springframework.stereotype.Service; import com.example.demo.app.domain.model.AnalysisModel; +import com.example.demo.app.domain.model.CategoryAnalysisModel; import com.example.demo.app.domain.service.AnalysisService; +import com.example.demo.app.infra.entity.AllocationEntity; +import com.example.demo.app.infra.entity.CategoryEntity; +import com.example.demo.app.infra.entity.UserEntity; +import com.example.demo.app.infra.repository.AllocationRepository; +import com.example.demo.app.infra.repository.CategoryRepository; +import com.example.demo.app.infra.repository.TransactionRepository; +import com.example.demo.app.infra.repository.UserRepository; import lombok.RequiredArgsConstructor; @@ -12,29 +24,119 @@ import lombok.RequiredArgsConstructor; public class AnalysisServiceImpl implements AnalysisService { //Repositoryの呼び出し -// private final TransactionRepository transactionRepository; -// private final AllocationRepository allocationRepository; -// private final UserRepository userRepository; -// private final CategoryRepository categoryRepository; + private final TransactionRepository transactionRepository; + private final AllocationRepository allocationRepository; + private final UserRepository userRepository; + private final CategoryRepository categoryRepository; @Override public AnalysisModel getAnalysis(Long userId) { // ユーザー情報取得、月別使用可能資金取得 + UserEntity userEntity = userRepository.findById(userId).orElseThrow(); + + // コースID取得 + Long courseId = userEntity.getCourseEntity().getCourseId(); + + // 月別使用可能資金取得 + Integer monthlyBudget =userEntity.getMonthlyBudget(); // 今月の期間取得 - // 前月の期間取得 - // 今月の支出取得 - // 前月の支出取得 - // コース配分取得 - // カテゴリ別集計 - // 前月との差額集計 - //総支出算出 - // コース限度額算出、コース別差額算出 - // CategoryAnalysisModel生成 - // AnalysisModelの生成 + LocalDate currentMonthStartDate = LocalDate.now().withDayOfMonth(1); + LocalDate currentMonthEndDate = LocalDate.now().withDayOfMonth(LocalDate.now().lengthOfMonth()); - return null; + // 前月の期間取得 + LocalDate previousMonthStartDate = LocalDate.now().minusMonths(1).withDayOfMonth(1); + LocalDate previousMonthEndDate = LocalDate.now().minusMonths(1).withDayOfMonth(LocalDate.now().minusMonths(1).lengthOfMonth()); + + // 今月の支出取得 + Integer currentMonthTotalAmount = transactionRepository.findTotalExpense(currentMonthStartDate, currentMonthEndDate, userId); + + if (currentMonthTotalAmount == null) { + currentMonthTotalAmount = 0; + } + + // 前月の支出取得 + Integer previousMonthTotalAmount = transactionRepository.findTotalExpense(previousMonthStartDate, previousMonthEndDate, userId); + + if (previousMonthTotalAmount == null) { + previousMonthTotalAmount = 0; + } + + //総支出差額算出 + Integer totalDifferenceAmount = currentMonthTotalAmount - previousMonthTotalAmount; + + //カテゴリ一覧取得 + List categoryAnalysisModelList = new ArrayList<>(); + List categoryEntityList = categoryRepository.findAll(); + List allocationEntityList = allocationRepository.findByCourseEntity_CourseId(courseId); + + //取得ループ + for (CategoryEntity categoryEntity : categoryEntityList) { + + if (categoryEntity.getTransactionType() != 0) { + continue; + } + // カテゴリ別今月金額取得 + Integer currentMonthAmount = + transactionRepository.findCategoryExpense(currentMonthStartDate, + currentMonthEndDate, + userId, + categoryEntity.getCategoryId()); + + // カテゴリ別前月金額取得 + Integer previousMonthAmount = + transactionRepository.findCategoryExpense(previousMonthStartDate, + previousMonthEndDate, + userId, + categoryEntity.getCategoryId()); + + if (currentMonthAmount == null) { + currentMonthAmount = 0; + } + + if (previousMonthAmount == null) { + previousMonthAmount = 0; + } + + // カテゴリ別前月差額算出 + Integer monthDifferenceAmount = currentMonthAmount - previousMonthAmount; + + // コース配分取得 + AllocationEntity allocationEntity = allocationEntityList.stream().filter(allocation -> + allocation.getCategoryEntity() + .getCategoryId() + .equals(categoryEntity.getCategoryId())) + .findFirst() + .orElse(null); + + Integer allocationRatio = 0; + + if (allocationEntity != null) { + allocationRatio = + allocationEntity.getAllocationRatio(); + } + + // コース限度額算出 + Integer courseLimitAmount = monthlyBudget * allocationRatio / 100; + + // コース差額算出 + Integer courseDifferenceAmount = currentMonthAmount - courseLimitAmount; + + // CategoryAnalysisModel生成 + CategoryAnalysisModel categoryAnalysisModel = new CategoryAnalysisModel( + categoryEntity.getCategoryName(), + currentMonthAmount, + previousMonthAmount, + monthDifferenceAmount, + courseLimitAmount, + courseDifferenceAmount); + + categoryAnalysisModelList.add(categoryAnalysisModel); + } + + // AnalysisModelの生成 + return new AnalysisModel(currentMonthTotalAmount, previousMonthTotalAmount, totalDifferenceAmount, categoryAnalysisModelList); } } diff --git a/src/main/java/com/example/demo/app/infra/repository/AllocationRepository.java b/src/main/java/com/example/demo/app/infra/repository/AllocationRepository.java index 5dc0ece..28656c2 100644 --- a/src/main/java/com/example/demo/app/infra/repository/AllocationRepository.java +++ b/src/main/java/com/example/demo/app/infra/repository/AllocationRepository.java @@ -28,5 +28,5 @@ public interface AllocationRepository extends JpaRepository findAllJoinedAllocation(); - + } diff --git a/src/main/java/com/example/demo/app/infra/repository/UserRepository.java b/src/main/java/com/example/demo/app/infra/repository/UserRepository.java index 239dba4..868dd8a 100644 --- a/src/main/java/com/example/demo/app/infra/repository/UserRepository.java +++ b/src/main/java/com/example/demo/app/infra/repository/UserRepository.java @@ -16,5 +16,6 @@ public interface UserRepository extends JpaRepository { String mailAddress, String password); + Optional findByMailAddress(String mailAddress); } diff --git a/src/main/java/com/example/demo/app/presentation/controller/AnalysisController.java b/src/main/java/com/example/demo/app/presentation/controller/AnalysisController.java index 905f2c3..5bc8cd9 100644 --- a/src/main/java/com/example/demo/app/presentation/controller/AnalysisController.java +++ b/src/main/java/com/example/demo/app/presentation/controller/AnalysisController.java @@ -1,10 +1,15 @@ package com.example.demo.app.presentation.controller; +import jakarta.servlet.http.HttpSession; + import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import com.example.demo.app.domain.model.AnalysisModel; +import com.example.demo.app.domain.model.LoginModel; import com.example.demo.app.domain.service.AnalysisService; +import com.example.demo.app.presentation.form.AnalysisForm; import lombok.RequiredArgsConstructor; @@ -16,13 +21,18 @@ public class AnalysisController { private final AnalysisService analysisService; @GetMapping("/analysis") - public String showAnalysis(Model model) { + public String showAnalysis(Model model, HttpSession session) { //ログインユーザーの取得(セッション) + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); //分析結果の取得(Service) + AnalysisModel analysisModel = analysisService.getAnalysis(loginUser.getUserId()); + AnalysisForm analysisForm = AnalysisForm.convertFrom(analysisModel); + //model格納 + model.addAttribute("analysisForm", analysisForm); return "analysis"; } diff --git a/src/main/resources/templates/analysis.html b/src/main/resources/templates/analysis.html index 31b6d9b..55201dd 100644 --- a/src/main/resources/templates/analysis.html +++ b/src/main/resources/templates/analysis.html @@ -12,7 +12,7 @@ - + @@ -20,8 +20,17 @@ - - + +
カテゴリ別 支出 前月比
総支出¥234,000+¥38,000 + 0 + + 0 +
@@ -33,24 +42,42 @@ カテゴリ別 支出 - 前月比
コース比 + + 前月比 +
+ コース比 + - - 食費 - ¥34,000 - +¥8,000
+¥1,100 - - - 交通費 - ¥14,000 - +¥8,000
+¥1,100 - - - 日用品 - ¥4,000 - +¥8,000
+¥1,100 + + + + 食費 + + + + 0 + + + + + +
+ + + diff --git a/src/main/resources/templates/user_register_confirm.html b/src/main/resources/templates/user_register_confirm.html index aad56dd..2b35041 100644 --- a/src/main/resources/templates/user_register_confirm.html +++ b/src/main/resources/templates/user_register_confirm.html @@ -1,5 +1,5 @@ - + 新規会員登録確認 From f55ece4dc7ab074f3c519c84874d644ead7120d9 Mon Sep 17 00:00:00 2001 From: k-oshita Date: Fri, 18 Sep 2026 10:55:37 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=E3=80=8CSTYLE]=20=E7=9B=AE=E6=A8=99?= =?UTF-8?q?=E5=90=8D=E3=82=92=E8=BF=BD=E8=A8=98=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 --- src/main/resources/templates/goal_view.html | 68 +++++++++++---------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/src/main/resources/templates/goal_view.html b/src/main/resources/templates/goal_view.html index 78bf40b..75c8cde 100644 --- a/src/main/resources/templates/goal_view.html +++ b/src/main/resources/templates/goal_view.html @@ -1,33 +1,37 @@ - - - - - 目標詳細 - - - -

目標詳細

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

目標詳細

+ + + + + + + + + + + + + + + + + +
目標補足説明
目標金額
目標達成期限
+ + 編集する + + \ No newline at end of file From d71194659b907c11e2acdb7c78c1fac4d21d7c8b Mon Sep 17 00:00:00 2001 From: k-oshita Date: Fri, 18 Sep 2026 11:02:42 +0900 Subject: [PATCH 5/6] =?UTF-8?q?[FIX]=E3=82=B4=E3=83=BC=E3=83=AB=E3=83=A2?= =?UTF-8?q?=E3=83=87=E3=83=AB=E3=81=AE=E3=83=90=E3=82=B0=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/demo/app/domain/model/GoalModel.java | 6 ------ 1 file changed, 6 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 52b3ad7..94a57d2 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 @@ -2,12 +2,9 @@ package com.example.demo.app.domain.model; import java.time.LocalDate; -<<<<<<< HEAD import com.example.demo.app.infra.entity.GoalEntity; import com.example.demo.app.presentation.form.GoalForm; -======= ->>>>>>> f955667682040961a972b0107053018dccd41543 import lombok.AllArgsConstructor; import lombok.Getter; @@ -27,7 +24,6 @@ public class GoalModel { private Integer goalComplete; -<<<<<<< HEAD public static GoalModel convertFrom(GoalEntity goalEntity) { return new GoalModel( goalEntity.getGoalId(), @@ -59,6 +55,4 @@ public class GoalModel { goalForm.getGoalComplete()); } -======= ->>>>>>> f955667682040961a972b0107053018dccd41543 } \ No newline at end of file From 15bf2949bc807a1e6e97267fc3b5f9da59ea7538 Mon Sep 17 00:00:00 2001 From: k-oshita Date: Fri, 18 Sep 2026 13:32:14 +0900 Subject: [PATCH 6/6] =?UTF-8?q?[EDIT]=20=E7=9B=AE=E6=A8=99=E3=82=92?= =?UTF-8?q?=E8=A1=A8=E7=A4=BA=E3=81=99=E3=82=8B=E6=A9=9F=E8=83=BD=E3=82=92?= =?UTF-8?q?=E8=BF=BD=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/service/GoalService.java | 2 + .../domain/service/impl/GoalServiceImpl.java | 14 +++-- .../demo/app/infra/entity/GoalEntity.java | 2 +- .../controller/GoalController.java | 52 +++++++++++++------ src/main/resources/templates/goal_edit.html | 7 +-- src/main/resources/templates/goal_view.html | 12 ++--- 6 files changed, 55 insertions(+), 34 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 ea2c3b7..294f7ac 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 @@ -5,6 +5,8 @@ import com.example.demo.app.domain.model.GoalModel; public interface GoalService { GoalModel getGoalById(Long goalId); + + GoalModel getGoalByUserId(Long userId); GoalModel createGoal(GoalModel goalModel); 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 c7063f3..56f4ea4 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 @@ -5,7 +5,9 @@ import org.springframework.stereotype.Service; import com.example.demo.app.domain.model.GoalModel; 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.UserRepository; import lombok.RequiredArgsConstructor; @@ -14,14 +16,20 @@ import lombok.RequiredArgsConstructor; public class GoalServiceImpl implements GoalService { private final GoalRepository goalRepository; + private final UserRepository userRepository; @Override public GoalModel getGoalById(Long goalId) { - GoalEntity goalEntity = goalRepository.findById(goalId).orElse(null); - return GoalModel.convertFrom(goalEntity); + } + @Override + public GoalModel getGoalByUserId(Long userId) { + + UserEntity userEntity = userRepository.findById(userId).orElseThrow(); + GoalEntity goalEntity = userEntity.getGoalEntity(); + return GoalModel.convertFrom(goalEntity); } @Override @@ -32,7 +40,6 @@ public class GoalServiceImpl implements GoalService { GoalEntity savedGoalEntity = goalRepository.save(goalEntity); return GoalModel.convertFrom(savedGoalEntity); - } @Override @@ -43,7 +50,6 @@ public class GoalServiceImpl implements GoalService { GoalEntity updatedGoalEntity = goalRepository.save(goalEntity); return GoalModel.convertFrom(updatedGoalEntity); - } } \ 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 f4bbe50..2996fe6 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 @@ -38,7 +38,7 @@ public class GoalEntity { @Column(name = "deadline", nullable = false) private LocalDate deadline; - @Column(name = "goal_complete", nullable = false) + @Column(name = "goal_complete", nullable = true) private Integer goalComplete; @OneToOne(mappedBy = "goalEntity") 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 96fe4ac..827e05b 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,14 +1,16 @@ package com.example.demo.app.presentation.controller; +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.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import com.example.demo.app.domain.model.GoalModel; +import com.example.demo.app.domain.model.LoginModel; import com.example.demo.app.domain.service.GoalService; import com.example.demo.app.presentation.form.GoalForm; @@ -21,41 +23,59 @@ public class GoalController { private final GoalService goalService; - @GetMapping("/{goalId}") - public String getGoal(@PathVariable Long goalId, Model model) { - - GoalModel goalModel = goalService.getGoalById(goalId); + @GetMapping("") + public String getGoal(Model model, HttpSession session) { + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + + Long userId = loginUser.getUserId(); + //テスト用 +// Long userId = 1L; + + GoalModel goalModel = goalService.getGoalByUserId(userId); GoalForm goalForm = GoalForm.convertFrom(goalModel); model.addAttribute("goalForm", goalForm); - return "goal_view"; - } - @GetMapping("/{goalId}/edit") - public String editGoal(@PathVariable Long goalId, Model model) { + @GetMapping("/edit") + public String editGoal(Model model, HttpSession session) { - GoalModel goalModel = goalService.getGoalById(goalId); + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + Long userId = loginUser.getUserId(); + + //テスト用 +// Long userId = 1L; + GoalModel goalModel = goalService.getGoalByUserId(userId); GoalForm goalForm = GoalForm.convertFrom(goalModel); model.addAttribute("goalForm", goalForm); - return "goal_edit"; - } @PostMapping("/update") - public String updateGoal(@ModelAttribute GoalForm goalForm) { + public String updateGoal(@ModelAttribute GoalForm goalForm, HttpSession session) { + + LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); + + Long userId = loginUser.getUserId(); + //テスト用 +// Long userId = 1L; + + + // 本人の目標かどうかを確認してから更新する + GoalModel currentGoal = goalService.getGoalByUserId(userId); + + if (!currentGoal.getGoalId().equals(goalForm.getGoalId())) { + return "redirect:/goal"; // 他人のデータを更新しようとしたら弾く + } GoalModel goalModel = GoalModel.convertFrom(goalForm); - goalService.updateGoal(goalModel); - return "redirect:/goal/" + goalForm.getGoalId(); - + return "redirect:/goal"; } } \ No newline at end of file diff --git a/src/main/resources/templates/goal_edit.html b/src/main/resources/templates/goal_edit.html index b3b59d3..0d3601e 100644 --- a/src/main/resources/templates/goal_edit.html +++ b/src/main/resources/templates/goal_edit.html @@ -9,18 +9,15 @@

目標編集

- -
- +
@@ -33,8 +30,6 @@ - -
diff --git a/src/main/resources/templates/goal_view.html b/src/main/resources/templates/goal_view.html index 75c8cde..348f7e4 100644 --- a/src/main/resources/templates/goal_view.html +++ b/src/main/resources/templates/goal_view.html @@ -9,16 +9,14 @@

目標詳細

- - - + - + @@ -31,7 +29,7 @@
目標補足説明目標説明
- 編集する - + 編集する + \ No newline at end of file