[EDIT] コース選択のデフォルトをバランスコースにするよう編集しました。ログイン済みのユーザーがコースを変更できるようにしました。
This commit is contained in:
@@ -1,8 +1,5 @@
|
|||||||
package com.example.demo.app.presentation.controller;
|
package com.example.demo.app.presentation.controller;
|
||||||
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpSession;
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
@@ -25,74 +22,53 @@ import lombok.RequiredArgsConstructor;
|
|||||||
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
//@RequestMapping("/course")
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class CourseController {
|
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 CourseService courseService;
|
||||||
private final CourseInfoService courseInfoService;
|
private final CourseInfoService courseInfoService;
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/course/select/register")
|
@PostMapping("/user/register/course")
|
||||||
public String showSelectCourse(@ModelAttribute UserForm userForm, Model model, HttpSession session) {
|
public String showSelectCourse(@ModelAttribute UserForm userForm, Model model, HttpSession session) {
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
session.setAttribute("userForm", userForm);
|
|
||||||
model.addAttribute("mode", "regist");
|
|
||||||
model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll()));
|
|
||||||
model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
|
||||||
|
|
||||||
|
|
||||||
return "select_course";
|
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()));
|
||||||
|
|
||||||
} catch (Exception e) {
|
return "select_course";
|
||||||
// ログイン情報の破棄
|
|
||||||
httpSession.invalidate();
|
|
||||||
|
|
||||||
e.printStackTrace();
|
|
||||||
|
|
||||||
// エラーログ出力
|
|
||||||
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
|
|
||||||
// エラー画面遷移
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SessionCheck
|
@SessionCheck
|
||||||
@GetMapping("/select/change")
|
@GetMapping("/course")
|
||||||
public String showChangeCourse(Model model) {
|
public String showChangeCourse(Model model, HttpSession session) {
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
model.addAttribute("mode", "change");
|
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||||
model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll()));
|
Long userId = loginUser.getUserId();
|
||||||
model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
|
||||||
|
|
||||||
return "select_course";
|
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()));
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
// ログイン情報の破棄
|
|
||||||
httpSession.invalidate();
|
|
||||||
|
|
||||||
e.printStackTrace();
|
return "select_course";
|
||||||
|
|
||||||
|
|
||||||
// エラーログ出力
|
|
||||||
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
|
|
||||||
// エラー画面遷移
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SessionCheck
|
@SessionCheck
|
||||||
@PostMapping("/change")
|
@PostMapping("/change")
|
||||||
public String changeCourse(@RequestParam Long courseId) {
|
public String changeCourse(@RequestParam Long courseId, HttpSession httpSession) {
|
||||||
|
|
||||||
LoginModel loginUser = (LoginModel) httpSession.getAttribute("loginUser");
|
LoginModel loginUser = (LoginModel) httpSession.getAttribute("loginUser");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user