Compare commits
5 Commits
dfcc49ad94
...
f588e29b46
| Author | SHA1 | Date | |
|---|---|---|---|
| f588e29b46 | |||
| 11fbec6d8c | |||
| 2372c81ddd | |||
| 254286f14e | |||
| d8ea1acf2f |
@@ -24,6 +24,8 @@ public class GoalModel {
|
|||||||
|
|
||||||
private Integer goalComplete;
|
private Integer goalComplete;
|
||||||
|
|
||||||
|
private Integer achievementRate; // 達成率
|
||||||
|
|
||||||
public static GoalModel convertFrom(GoalEntity goalEntity) {
|
public static GoalModel convertFrom(GoalEntity goalEntity) {
|
||||||
return new GoalModel(
|
return new GoalModel(
|
||||||
goalEntity.getGoalId(),
|
goalEntity.getGoalId(),
|
||||||
@@ -31,7 +33,8 @@ public class GoalModel {
|
|||||||
goalEntity.getGoalSubtitle(),
|
goalEntity.getGoalSubtitle(),
|
||||||
goalEntity.getTargetAmount(),
|
goalEntity.getTargetAmount(),
|
||||||
goalEntity.getDeadline(),
|
goalEntity.getDeadline(),
|
||||||
goalEntity.getGoalComplete());
|
goalEntity.getGoalComplete(),
|
||||||
|
null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GoalEntity convertTo(GoalModel goalModel) {
|
public static GoalEntity convertTo(GoalModel goalModel) {
|
||||||
@@ -52,7 +55,8 @@ public class GoalModel {
|
|||||||
goalForm.getGoalSubtitle(),
|
goalForm.getGoalSubtitle(),
|
||||||
goalForm.getTargetAmount(),
|
goalForm.getTargetAmount(),
|
||||||
goalForm.getDeadline(),
|
goalForm.getDeadline(),
|
||||||
goalForm.getGoalComplete());
|
goalForm.getGoalComplete()
|
||||||
|
,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,4 +4,5 @@ import com.example.demo.app.domain.model.ProfileModel;
|
|||||||
|
|
||||||
public interface ProfileService {
|
public interface ProfileService {
|
||||||
ProfileModel findOne(Long userId);
|
ProfileModel findOne(Long userId);
|
||||||
|
void withdraw(Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,34 @@ public class GoalServiceImpl implements GoalService {
|
|||||||
|
|
||||||
UserEntity userEntity = userRepository.findById(userId).orElseThrow();
|
UserEntity userEntity = userRepository.findById(userId).orElseThrow();
|
||||||
GoalEntity goalEntity = userEntity.getGoalEntity();
|
GoalEntity goalEntity = userEntity.getGoalEntity();
|
||||||
return GoalModel.convertFrom(goalEntity);
|
|
||||||
|
// 収支の合計を計算(収入はプラス、支出はマイナス)
|
||||||
|
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;
|
||||||
|
|
||||||
|
// 達成率(%) = 現在の資産 ÷ 目標金額 × 100
|
||||||
|
int achievementRate =
|
||||||
|
(goalEntity.getTargetAmount() == null)
|
||||||
|
? 0 :
|
||||||
|
(int) ((currentAmount * 100.0) / goalEntity.getTargetAmount());
|
||||||
|
|
||||||
|
GoalModel goalModel = GoalModel.convertFrom(goalEntity);
|
||||||
|
|
||||||
|
return new GoalModel(
|
||||||
|
goalModel.getGoalId(),
|
||||||
|
goalModel.getGoalTitle(),
|
||||||
|
goalModel.getGoalSubtitle(),
|
||||||
|
goalModel.getTargetAmount(),
|
||||||
|
goalModel.getDeadline(),
|
||||||
|
goalModel.getGoalComplete(),
|
||||||
|
achievementRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -31,4 +31,16 @@ public class ProfileServiceImpl implements ProfileService{
|
|||||||
userEntity.getAnnualIncome(),
|
userEntity.getAnnualIncome(),
|
||||||
userEntity.getMonthlyBudget());
|
userEntity.getMonthlyBudget());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void withdraw(Long userId) {
|
||||||
|
UserEntity userEntity =userRepository.findById(userId).orElse(null);
|
||||||
|
|
||||||
|
if (userEntity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
userEntity.setDeleteFlag(1);
|
||||||
|
userRepository.save(userEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ public class GoalController {
|
|||||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||||
|
|
||||||
Long userId = loginUser.getUserId();
|
Long userId = loginUser.getUserId();
|
||||||
//テスト用
|
|
||||||
// Long userId = 1L;
|
|
||||||
|
|
||||||
GoalModel goalModel = goalService.getGoalByUserId(userId);
|
GoalModel goalModel = goalService.getGoalByUserId(userId);
|
||||||
GoalForm goalForm = GoalForm.convertFrom(goalModel);
|
GoalForm goalForm = GoalForm.convertFrom(goalModel);
|
||||||
@@ -45,9 +43,6 @@ public class GoalController {
|
|||||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||||
Long userId = loginUser.getUserId();
|
Long userId = loginUser.getUserId();
|
||||||
|
|
||||||
//テスト用
|
|
||||||
// Long userId = 1L;
|
|
||||||
|
|
||||||
GoalModel goalModel = goalService.getGoalByUserId(userId);
|
GoalModel goalModel = goalService.getGoalByUserId(userId);
|
||||||
GoalForm goalForm = GoalForm.convertFrom(goalModel);
|
GoalForm goalForm = GoalForm.convertFrom(goalModel);
|
||||||
|
|
||||||
@@ -61,9 +56,6 @@ public class GoalController {
|
|||||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||||
|
|
||||||
Long userId = loginUser.getUserId();
|
Long userId = loginUser.getUserId();
|
||||||
//テスト用
|
|
||||||
// Long userId = 1L;
|
|
||||||
|
|
||||||
|
|
||||||
// 本人の目標かどうかを確認してから更新する
|
// 本人の目標かどうかを確認してから更新する
|
||||||
GoalModel currentGoal = goalService.getGoalByUserId(userId);
|
GoalModel currentGoal = goalService.getGoalByUserId(userId);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import jakarta.servlet.http.HttpSession;
|
|||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
import com.example.demo.app.domain.model.LoginModel;
|
import com.example.demo.app.domain.model.LoginModel;
|
||||||
import com.example.demo.app.domain.model.ProfileModel;
|
import com.example.demo.app.domain.model.ProfileModel;
|
||||||
@@ -29,4 +30,28 @@ public class ProfileController {
|
|||||||
model.addAttribute("profileForm", profileForm);
|
model.addAttribute("profileForm", profileForm);
|
||||||
return "profile";
|
return "profile";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/profile/edit")
|
||||||
|
public String showEditProfile() {
|
||||||
|
return "profile_edit";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/withdraw")
|
||||||
|
public String withdraw(HttpSession session) {
|
||||||
|
|
||||||
|
LoginModel loginUser =
|
||||||
|
(LoginModel) session.getAttribute("loginUser");
|
||||||
|
|
||||||
|
profileService.withdraw(loginUser.getUserId());
|
||||||
|
|
||||||
|
session.invalidate();
|
||||||
|
|
||||||
|
return "redirect:/login";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/logout")
|
||||||
|
public String logout(HttpSession session) {
|
||||||
|
session.invalidate();
|
||||||
|
return "redirect:/login";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ public class GoalForm {
|
|||||||
|
|
||||||
private Integer goalComplete;
|
private Integer goalComplete;
|
||||||
|
|
||||||
|
private Integer achievementRate; // 達成率
|
||||||
|
|
||||||
public static GoalForm convertFrom(GoalModel goalModel) {
|
public static GoalForm convertFrom(GoalModel goalModel) {
|
||||||
return new GoalForm(
|
return new GoalForm(
|
||||||
goalModel.getGoalId(),
|
goalModel.getGoalId(),
|
||||||
@@ -32,7 +34,8 @@ public class GoalForm {
|
|||||||
goalModel.getGoalSubtitle(),
|
goalModel.getGoalSubtitle(),
|
||||||
goalModel.getTargetAmount(),
|
goalModel.getTargetAmount(),
|
||||||
goalModel.getDeadline(),
|
goalModel.getDeadline(),
|
||||||
goalModel.getGoalComplete());
|
goalModel.getGoalComplete(),
|
||||||
|
goalModel.getAchievementRate());
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static List<GoalForm> convertFrom(List<GoalModel> goalModelList) {
|
// public static List<GoalForm> convertFrom(List<GoalModel> goalModelList) {
|
||||||
|
|||||||
@@ -3,8 +3,12 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>目標編集</title>
|
<title>目標編集</title>
|
||||||
|
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div th:replace="~{header :: header}"></div>
|
||||||
|
|
||||||
<h1>目標編集</h1>
|
<h1>目標編集</h1>
|
||||||
|
|
||||||
@@ -13,26 +17,29 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label>目標名</label>
|
<label>目標名</label>
|
||||||
<input type="text" th:field="*{goalTitle}">
|
<input type="text" th:field="*{goalTitle}" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label>目標説明</label>
|
<label>目標説明</label>
|
||||||
<textarea th:field="*{goalSubtitle}"></textarea>
|
<textarea th:field="*{goalSubtitle}" required></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label>目標金額</label>
|
<label>目標金額</label>
|
||||||
<input type="number" th:field="*{targetAmount}">
|
<input type="number" th:field="*{targetAmount}" required min="1">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label>目標達成期限</label>
|
<label>目標達成期限</label>
|
||||||
<input type="date" th:field="*{deadline}">
|
<input type="date" th:field="*{deadline}" th:min="${#temporals.format(#temporals.createNow(), 'yyyy-MM-dd')}" required>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit">更新する</button>
|
<button type="submit">更新する</button>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<div th:replace="~{footer :: footer}"></div>
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -3,8 +3,13 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>目標詳細</title>
|
<title>目標詳細</title>
|
||||||
|
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div th:replace="~{header :: header}"></div>
|
||||||
|
|
||||||
|
|
||||||
<h1>目標詳細</h1>
|
<h1>目標詳細</h1>
|
||||||
|
|
||||||
@@ -27,9 +32,18 @@
|
|||||||
<th>目標達成期限</th>
|
<th>目標達成期限</th>
|
||||||
<td th:text="${goalForm.deadline}"></td>
|
<td th:text="${goalForm.deadline}"></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<th>達成率</th>
|
||||||
|
<td th:text="${goalForm.achievementRate} + '%'"></td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<a th:href="@{/goal/edit}">編集する</a>
|
<a th:href="@{/goal/edit}">編集する</a>
|
||||||
|
|
||||||
|
<div th:replace="~{footer :: footer}"></div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -51,12 +51,13 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<form th:action="@{/login}" method="post">
|
<form th:action="@{/logout}" method="post">
|
||||||
<button type="submit">ログアウト</button>
|
<button type="submit">ログアウト</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<form th:action="@{/aaa}" method="post">
|
<form th:action="@{/withdraw}" method="post"
|
||||||
<button type="submit">脱退</button>
|
onsubmit="return confirm('本当に脱退しますか?');">
|
||||||
|
<button type="submit">脱退</button>
|
||||||
</form>
|
</form>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -109,7 +109,7 @@
|
|||||||
<label>コース</label>
|
<label>コース</label>
|
||||||
<input type="hidden" th:field="*{courseId}">
|
<input type="hidden" th:field="*{courseId}">
|
||||||
<span th:text="${selectedCourseName}">未選択</span>
|
<span th:text="${selectedCourseName}">未選択</span>
|
||||||
<button type="button"onclick="location.href='/select-course'">コース選択</button>
|
<button type="submit"onclick="location.href='/course/select/register'">コース選択</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
Reference in New Issue
Block a user