5 Commits

4 changed files with 30 additions and 55 deletions

View File

@@ -45,13 +45,11 @@ public class UserServiceImpl implements UserService {
GoalEntity goalEntity = new GoalEntity();
goalEntity.setTargetAmount(Integer.parseInt(String.valueOf(userForm.getGoalId())));
goalRepository.save(
goalEntity);
CourseEntity courseEntity = courseRepository.findById(courseId).orElse(null);
userEntity.setQuestionEntity(questionEntity);
userEntity.setGoalEntity(goalEntity);
userEntity.setGoalEntity(goalRepository.save(
goalEntity));
userEntity.setCourseEntity(courseEntity);
userEntity.setDeleteFlag(0);

View File

@@ -1,8 +1,5 @@
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;
@@ -25,74 +22,53 @@ import lombok.RequiredArgsConstructor;
@Controller
//@RequestMapping("/course")
@RequiredArgsConstructor
public class CourseController {
private final static Logger LOGGER = Logger.getLogger(CourseController.class.getName());
// エラーメッセージ用の定数フィールド
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
private final HttpSession httpSession;
private final CourseService courseService;
private final CourseInfoService courseInfoService;
private final UserService userService;
@PostMapping("/course/select/register")
@PostMapping("/user/register/course")
public String showSelectCourse(@ModelAttribute UserForm userForm, Model model, HttpSession session) {
try {
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";
} catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return null;
}
}
@SessionCheck
@GetMapping("/select/change")
public String showChangeCourse(Model model) {
@GetMapping("/course")
public String showChangeCourse(Model model, HttpSession session) {
try {
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";
} catch (Exception e) {
// ログイン情報の破棄
httpSession.invalidate();
e.printStackTrace();
// エラーログ出力
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
// エラー画面遷移
return null;
}
}
@SessionCheck
@PostMapping("/change")
public String changeCourse(@RequestParam Long courseId) {
public String changeCourse(@RequestParam Long courseId, HttpSession httpSession) {
LoginModel loginUser = (LoginModel) httpSession.getAttribute("loginUser");

View File

@@ -7,6 +7,7 @@
<title>コース選択</title>
</head>
<body>
<div th:replace="~{header :: header}"></div>
<h1>コース選択</h1>
@@ -17,7 +18,7 @@
<div class="accordion" id="accordionExample">
<div class="accordion-item" th:each="course:${courseList}">
<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">
<input type="radio" name="courseId" th:value="${course.courseId}" th:checked="${course.courseId==currentCourseId}" 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>

View File

@@ -13,7 +13,7 @@
<main>
<h1>新規会員登録</h1>
<form th:action="@{/course/select/register}" th:object="${userForm}" method="post">
<form th:action="@{/user/register/course}" th:object="${userForm}" method="post">
<div>
<label for="userName">氏名</label>
<input type="text"