Compare commits
3 Commits
76e3fc2345
...
58da1fcbfc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58da1fcbfc | ||
|
|
ec862f8271 | ||
|
|
918b7f7218 |
@@ -51,7 +51,7 @@ public class GoalModel {
|
|||||||
goalModel.getGoalSubtitle(),
|
goalModel.getGoalSubtitle(),
|
||||||
goalModel.getTargetAmount(),
|
goalModel.getTargetAmount(),
|
||||||
goalModel.getDeadline(),
|
goalModel.getDeadline(),
|
||||||
goalModel.getGoalComplete(),
|
0,
|
||||||
userEntity, 0);
|
userEntity, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ public interface GoalService {
|
|||||||
public GoalModel createGoal(GoalModel goalModel, Long userId);
|
public GoalModel createGoal(GoalModel goalModel, Long userId);
|
||||||
|
|
||||||
GoalModel updateGoal(GoalModel goalModel, Long userId);
|
GoalModel updateGoal(GoalModel goalModel, Long userId);
|
||||||
|
|
||||||
|
public void delete(Long goalId);
|
||||||
|
|
||||||
// void deleteGoal(Long goalId);
|
// void deleteGoal(Long goalId);
|
||||||
|
|
||||||
|
|||||||
@@ -78,5 +78,9 @@ public class GoalServiceImpl implements GoalService {
|
|||||||
|
|
||||||
return GoalModel.convertFrom(updatedGoalEntity, 0, 0);
|
return GoalModel.convertFrom(updatedGoalEntity, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void delete(Long goalId) {
|
||||||
|
goalRepository.deleteById(goalId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.example.demo.app.presentation.controller;
|
package com.example.demo.app.presentation.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpSession;
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@@ -32,22 +34,21 @@ public class GoalController {
|
|||||||
|
|
||||||
Long userId = loginUser.getUserId();
|
Long userId = loginUser.getUserId();
|
||||||
|
|
||||||
GoalModel goalModel = goalService.getGoalByUserId(userId);
|
List<GoalModel> goalModelList = goalService.getGoalByUserId(userId);
|
||||||
GoalForm goalForm = GoalForm.convertFrom(goalModel);
|
List<GoalForm> goalFormList = GoalForm.convertFrom(goalModelList);
|
||||||
|
|
||||||
model.addAttribute("goalForm", goalForm);
|
model.addAttribute("goalFormList", goalFormList);
|
||||||
return "goal_view";
|
return "goal_view";
|
||||||
}
|
}
|
||||||
|
|
||||||
@SessionCheck
|
@SessionCheck
|
||||||
@GetMapping("/edit")
|
@GetMapping("/edit")
|
||||||
public String editGoal(Model model, HttpSession session) {
|
public String editGoal(Model model, HttpSession session, Long goalId) {
|
||||||
|
|
||||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||||
Long userId = loginUser.getUserId();
|
Long userId = loginUser.getUserId();
|
||||||
|
|
||||||
GoalModel goalModel = goalService.getGoalByUserId(userId);
|
GoalForm goalForm = GoalForm.convertFrom(goalService.getGoalById(goalId));
|
||||||
GoalForm goalForm = GoalForm.convertFrom(goalModel);
|
|
||||||
|
|
||||||
model.addAttribute("goalForm", goalForm);
|
model.addAttribute("goalForm", goalForm);
|
||||||
return "goal_edit";
|
return "goal_edit";
|
||||||
@@ -61,17 +62,49 @@ public class GoalController {
|
|||||||
|
|
||||||
Long userId = loginUser.getUserId();
|
Long userId = loginUser.getUserId();
|
||||||
|
|
||||||
// 本人の目標かどうかを確認してから更新する
|
// // 本人の目標かどうかを確認してから更新する
|
||||||
GoalModel currentGoal = goalService.getGoalByUserId(userId);
|
// GoalModel currentGoal = goalService.getGoalByUserId(userId);
|
||||||
|
//
|
||||||
if (!currentGoal.getGoalId().equals(goalForm.getGoalId())) {
|
// if (!currentGoal.getGoalId().equals(goalForm.getGoalId())) {
|
||||||
return "redirect:/goal"; // 他人のデータを更新しようとしたら弾く
|
// return "redirect:/goal"; // 他人のデータを更新しようとしたら弾く
|
||||||
}
|
// }
|
||||||
|
|
||||||
GoalModel goalModel = GoalModel.convertFrom(goalForm);
|
GoalModel goalModel = GoalModel.convertFrom(goalForm);
|
||||||
goalService.updateGoal(goalModel, userId);
|
goalService.updateGoal(goalModel, userId);
|
||||||
|
|
||||||
return "redirect:/goal";
|
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";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
46
src/main/resources/templates/goal_create.html
Normal file
46
src/main/resources/templates/goal_create.html
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>目標作成</title>
|
||||||
|
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
|
||||||
|
</head>
|
||||||
|
<body class="pb-5 pt-5">
|
||||||
|
|
||||||
|
<div th:replace="~{header :: header}"></div>
|
||||||
|
|
||||||
|
<h1>目標作成</h1>
|
||||||
|
|
||||||
|
<form th:action="@{/goal/create}" th:object="${goalForm}" method="post">
|
||||||
|
<input type="hidden" th:field="*{goalId}">
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>目標名</label>
|
||||||
|
<input type="text" th:field="*{goalTitle}" required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>目標説明</label>
|
||||||
|
<textarea th:field="*{goalSubtitle}" required></textarea>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>目標金額</label>
|
||||||
|
<input type="number" th:field="*{targetAmount}" required min="1">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>目標達成期限</label>
|
||||||
|
<input type="date" th:field="*{deadline}" th:min="${#temporals.format(#temporals.createNow(), 'yyyy-MM-dd')}" required>
|
||||||
|
</div>
|
||||||
|
<button type="submit">更新する</button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div th:replace="~{footer :: footer}"></div>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,48 +1,67 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html xmlns:th="http://www.thymeleaf.org">
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
<head>
|
||||||
<title>目標詳細</title>
|
<meta charset="UTF-8">
|
||||||
|
<title>目標詳細</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
</head>
|
|
||||||
<body class="pb-5 pt-5">
|
</head>
|
||||||
<div th:replace="~{header :: header}"></div>
|
|
||||||
|
<body class="pb-5 pt-5">
|
||||||
|
<div th:replace="~{header :: header}"></div>
|
||||||
<h1>目標詳細</h1>
|
|
||||||
|
|
||||||
<table>
|
<h1>目標詳細</h1>
|
||||||
<tr>
|
|
||||||
<th>目標名</th>
|
<div>
|
||||||
<td th:text="${goalForm.goalTitle}"></td>
|
<ul>
|
||||||
</tr>
|
<li th:each="goalForm : ${goalFormList}" class="transaction-item">
|
||||||
|
|
||||||
<tr>
|
<div>
|
||||||
<th>目標説明</th>
|
<p>
|
||||||
<td th:text="${goalForm.goalSubtitle}"></td>
|
目標名:
|
||||||
</tr>
|
<span th:text="${goalForm.goalTitle}"></span>
|
||||||
<tr>
|
<br>
|
||||||
<th>目標金額</th>
|
目標説明:
|
||||||
<td th:text="${goalForm.targetAmount}"></td>
|
<span th:text="${goalForm.goalSubtitle}"></span>
|
||||||
</tr>
|
<br>
|
||||||
<tr>
|
目標金額:
|
||||||
<th>目標達成期限</th>
|
<span th:text="${goalForm.targetAmount}"></span>
|
||||||
<td th:text="${goalForm.deadline}"></td>
|
<br>
|
||||||
</tr>
|
目標達成期限:
|
||||||
|
<span th:text="${goalForm.deadline}"></span>
|
||||||
<tr>
|
<br>
|
||||||
<th>達成率</th>
|
達成率:
|
||||||
<td th:text="${goalForm.achievementRate} + '%'"></td>
|
<span th:text="${goalForm.achievementRate} + '%'"></span>
|
||||||
</tr>
|
<br>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</table>
|
|
||||||
|
<div class="transaction-buttons">
|
||||||
<a th:href="@{/goal/edit}">編集する</a>
|
|
||||||
|
<form th:action="@{/goal/edit}" method="get">
|
||||||
<div th:replace="~{footer :: footer}"></div>
|
<input type="hidden" name="goalId" th:value="${goalForm.goalId}">
|
||||||
|
<button type="submit">編集</button>
|
||||||
</body>
|
</form>
|
||||||
|
<form th:action="@{/goal/delete}" method="post">
|
||||||
|
<input type="hidden" name="goalId" th:value="${goalForm.goalId}">
|
||||||
|
<button type="submit">削除</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form th:action="@{/goal/create}" method="get">
|
||||||
|
<button type="submit">新規登録</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<div th:replace="~{footer :: footer}"></div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user