4 Commits

15 changed files with 195 additions and 42 deletions

1
.gitignore vendored
View File

@@ -31,3 +31,4 @@ build/
### VS Code ###
.vscode/
/bin/

View File

@@ -10,8 +10,8 @@ import lombok.Getter;
public class ProfileModel {
private Long userId;
private String userName;
private String emailAddress;
private LocalDate brithDate;
private String mailAddress;
private LocalDate birthDate;
private Integer saving;
private Integer annualIncome;
private Integer monthlyBudget;

View File

@@ -3,5 +3,8 @@ package com.example.demo.app.domain.service;
import com.example.demo.app.presentation.form.UserForm;
public interface UserService {
void register(UserForm userForm);
void register(UserForm userForm);
public void updateCourse(Long userId, Long courseId);
}

View File

@@ -57,6 +57,18 @@ public class UserServiceImpl implements UserService {
userRepository.save(userEntity);
}
@Override
public void updateCourse(Long userId, Long courseId) {
UserEntity userEntity = userRepository.findById(userId).orElseThrow();
CourseEntity courseEntity = courseRepository.findById(courseId).orElseThrow();
userEntity.setCourseEntity(courseEntity);
userRepository.save(userEntity);
}
}

View File

@@ -1,13 +1,22 @@
package com.example.demo.app.presentation.controller;
import java.util.logging.Level;
import java.util.logging.Logger;
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 org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.model.UserModel;
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.CourseForm;
import com.example.demo.app.presentation.form.CourseInfoForm;
@@ -15,6 +24,7 @@ import lombok.RequiredArgsConstructor;
@Controller
@RequestMapping("/course")
@RequiredArgsConstructor
public class CourseController {
@@ -22,31 +32,70 @@ public class CourseController {
// エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
// private final HttpSession httpSession;
private final HttpSession httpSession;
private final CourseService courseService;
private final CourseInfoService courseInfoService;
private final UserService userService;
@GetMapping("/select-course")
public String select(Model model) {
@PostMapping("/select/register")
public String showSelectCourse(@ModelAttribute UserModel userModel, Model model) {
//try {
try {
model.addAttribute("mode", "select");
model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll()));
model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll()));
return "select_course";
//} catch (Exception e) {
// // ログイン情報の破棄
// httpSession.invalidate();
//
// e.printStackTrace();
//
// // エラーログ出力
// LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// // エラー画面遷移
// return null;
// }
} catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return null;
}
}
@PostMapping("/select/change")
public String showChangeCourse(Model model) {
try {
model.addAttribute("mode", "change");
model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll()));
model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll()));
return "select_course";
} catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return null;
}
}
@PostMapping("/change")
public String changeCourse(@RequestParam Long courseId) {
LoginModel loginUser = (LoginModel) httpSession.getAttribute("loginUser");
userService.updateCourse(loginUser.getUserId(), courseId);
return "redirect:/menu";
}
}

View File

@@ -129,6 +129,10 @@ public class TransactionController {
public String createOneGet(@RequestParam(defaultValue = "") LocalDate today,
Model model) {
if (today == null) {
today = LocalDate.now();
}
List<CategoryForm> categoryFormList = CategoryForm.convertFrom(categoryService.findAll());
TransactionForm transactionForm = new TransactionForm();
@@ -164,7 +168,7 @@ public class TransactionController {
public String updateOneGet(@RequestParam Long transactionId, @RequestParam(defaultValue = "") LocalDate today,
Model model) {
if (today.equals(null)) {
if (today == null) {
today = LocalDate.now();
}

View File

@@ -14,8 +14,8 @@ import lombok.NoArgsConstructor;
public class ProfileForm {
private Long userId;
private String userName;
private String emailAddress;
private LocalDate brithDate;
private String mailAddress;
private LocalDate birthDate;
private Integer saving;
private Integer annualIncome;
private Integer monthlyBudget;
@@ -24,8 +24,8 @@ public class ProfileForm {
return new ProfileForm(
profileModel.getUserId(),
profileModel.getUserName(),
profileModel.getEmailAddress(),
profileModel.getBrithDate(),
profileModel.getMailAddress(),
profileModel.getBirthDate(),
profileModel.getSaving(),
profileModel.getAnnualIncome(),
profileModel.getMonthlyBudget());

View File

@@ -101,6 +101,7 @@
</div>
<div th:replace="~{footer :: footer}"></div>
</body>

View File

@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>プロフィール</title>
</head>
<body>
<header></header>
<main>
<div>
<p>氏名</p>
<p th:text="${profileForm.userName}"></p>
</div>
<div>
<p>メールアドレス</p>
<p th:text="${profileForm.mailAddress}"></p>
</div>
<div>
<p>生年月日</p>
<p th:text="${profileForm.birthDate}"></p>
</div>
<div>
<p>パスワード</p>
<form th:action="@{/password/reset}" method="get">
<button type="submit">パスワード再設定</button>
</form>
</div>
<div>
<p>貯蓄金</p>
<p th:text="${profileForm.saving}"></p>
</div>
<div>
<p>年収</p>
<p th:text="${profileForm.annualIncome}"></p>
</div>
<div>
<p>月別使用可能額</p>
<p th:text="${profileForm.monthlyBudget}"></p>
</div>
<div>
<form th:action="@{/profile/edit}" method="get">
<button type="submit">編集</button>
</form>
</div>
<form th:action="@{/login}" method="post">
<button type="submit">ログアウト</button>
</form>
<form th:action="@{/aaa}" method="post">
<button type="submit">脱退</button>
</form>
</main>
</body>
</html>

View File

@@ -2,25 +2,41 @@
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
<title>コース選択</title>
</head>
<body>
<h1>コース選択</h1>
<form th:action="@{/user/register}" th:object="${userForm}" method="post">
<input type="hidden" th:field="*{userName}">
<input type="hidden" th:field="*{mailAddress}">
<input type="hidden" th:field="*{birthDate}">
<input type="hidden" th:field="*{password}">
<input type="hidden" th:field="*{secretQuestionId}">
<input type="hidden" th:field="*{secretAnswer}">
<input type="hidden" th:field="*{saving}">
<input type="hidden" th:field="*{annualIncome}">
<input type="hidden" th:field="*{monthlyBudget}">
<input type="hidden" th:field="*{targetAmount}">
<button type="submit">確定</button>
<div class="accordion" id="accordionExample">
<div class="accordion-item" th:each="course:${courseList}">
<h2 class="accordion-header">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<span th:text="${course.courseName}"></span>
<h2 class="accordion-header d-flex align-items-center">
<input type="radio" name="courseId" th:value="${course.courseId}" class="form-check-input ms-3 me-2">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" th:data-bs-target="'#collapse' + ${course.courseId}" aria-expanded="false" aria-controls="'collapse' + ${course.courseId}">
<span th:text="${course.courseName}"></span>
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" data-bs-parent="#accordionExample">
<div th:id="'collapse' + ${course.courseId}" class="accordion-collapse collapse" data-bs-parent="#accordionExample">
<div class="accordion-body">
<span th:text="${course.description}"></span>
<table border="1">
<tr>
<th>カテゴリ名</th><tr>配分(%)</tr>
<th>カテゴリ名</th><th>配分(%)</th>
</tr>
<tr th:each="courseInfo:${courseInfoList}" th:if="course.courseId == courseInfo.courseId">
<tr th:each="courseInfo:${courseInfoList}" th:if="${course.courseId == courseInfo.courseId}">
<td th:text="${courseInfo.categoryName}"></td>
<td th:text="${courseInfo.allocationRatio}"></td>
</tr>
@@ -29,7 +45,8 @@
</div>
</div>
</div>
</form>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

View File

@@ -67,6 +67,7 @@
</form>
<div th:replace="~{footer :: footer}"></div>
</body>

View File

@@ -57,6 +57,7 @@
<button type="submit">新規登録</button>
</form>
<div th:replace="~{footer :: footer}"></div>
</body>
</html>

View File

@@ -28,6 +28,7 @@
</ul>
</div>
<div th:replace="~{footer :: footer}"></div>
</body>

View File

@@ -69,7 +69,7 @@
</form>
<div th:replace="~{footer :: footer}"></div>
</body>

View File

@@ -12,17 +12,17 @@
<div>
<p>氏名</p>
<p th:text="${session.userForm.userName}" readonly></p>
<p th:text="${user.userName}"></p>
</div>
<div>
<p>メールアドレス</p>
<p th:text="${session.userForm.mailAddress}" readonly></p>
<p th:text="${user.mailAddress}"></p>
</div>
<div>
<p>生年月日</p>
<p th:text="${session.userForm.barthDate}" readonly></p>
<p th:text="${user.birthDate}"></p>
</div>
<div>
@@ -32,37 +32,37 @@
<div>
<p>秘密の質問</p>
<p th:text="${session.userForm.secretQuestionId}" readonly></p>
<p th:text="${user.secretQuestionId}"></p>
</div>
<div>
<p>秘密の質問の回答</p>
<p th:text="${session.userForm.secretAnswer}" readonly></p>
<p th:text="${user.secretAnswer}"></p>
</div>
<div>
<p>貯蓄金</p>
<p th:text="${session.userForm.saving}" readonly></p>
<p th:text="${user.saving}"></p>
</div>
<div>
<p>年収</p>
<p th:text="${session.userForm.annualIncome}" readonly></p>
<p th:text="${user.annualIncome}"></p>
</div>
<div>
<p>月別使用可能額</p>
<p th:text="${session.userForm.monthlyBudget}" readonly></p>
<p th:text="${user.monthlyBudget}"></p>
</div>
<div>
<p>目標</p>
<p th:text="${session.userForm.goalId}" readonly></p>
<p th:text="${user.goalId}"></p>
</div>
<div>
<p>コース</p>
<p th:text="${session.userForm.courseId}" readonly></p>
<p th:text="${user.courseId}"></p>
</div>
<div>