[EDIT] コース選択機能を修正しました
This commit is contained in:
@@ -8,4 +8,6 @@ public interface CourseService {
|
|||||||
|
|
||||||
public List<CourseModel> findAll();
|
public List<CourseModel> findAll();
|
||||||
|
|
||||||
|
public CourseModel findById(Long courseId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,4 +21,8 @@ public class CourseServiceImpl implements CourseService {
|
|||||||
|
|
||||||
return CourseEntity.createCourseModelList(courseRepository.findAll());
|
return CourseEntity.createCourseModelList(courseRepository.findAll());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CourseModel findById(Long courseId) {
|
||||||
|
return CourseModel.convertFrom(courseRepository.findByCourseId(courseId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
package com.example.demo.app.infra.repository;
|
package com.example.demo.app.infra.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
import com.example.demo.app.infra.entity.CourseEntity;
|
import com.example.demo.app.infra.entity.CourseEntity;
|
||||||
|
|
||||||
public interface CourseRepository extends JpaRepository<CourseEntity, Long> {
|
public interface CourseRepository extends JpaRepository<CourseEntity, Long> {
|
||||||
|
|
||||||
|
@Query("SELECT c FROM CourseEntity c WHERE c.courseId = :courseId ")
|
||||||
|
public CourseEntity findByCourseId(Long courseId);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,24 +7,24 @@ 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.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import com.example.demo.app.domain.model.LoginModel;
|
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.CourseInfoService;
|
||||||
import com.example.demo.app.domain.service.CourseService;
|
import com.example.demo.app.domain.service.CourseService;
|
||||||
import com.example.demo.app.domain.service.UserService;
|
import com.example.demo.app.domain.service.UserService;
|
||||||
import com.example.demo.app.presentation.form.CourseForm;
|
import com.example.demo.app.presentation.form.CourseForm;
|
||||||
import com.example.demo.app.presentation.form.CourseInfoForm;
|
import com.example.demo.app.presentation.form.CourseInfoForm;
|
||||||
|
import com.example.demo.app.presentation.form.UserForm;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("/course")
|
//@RequestMapping("/course")
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class CourseController {
|
public class CourseController {
|
||||||
|
|
||||||
@@ -39,15 +39,18 @@ public class CourseController {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/select/register")
|
@GetMapping("/course/select/register")
|
||||||
public String showSelectCourse(@ModelAttribute UserModel userModel, Model model) {
|
public String showSelectCourse(@ModelAttribute UserForm userForm, Model model, HttpSession session) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
System.out.println(userForm.getMailAddress());
|
||||||
|
|
||||||
model.addAttribute("mode", "select");
|
session.setAttribute("userForm", userForm);
|
||||||
|
model.addAttribute("mode", "regist");
|
||||||
model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll()));
|
model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll()));
|
||||||
model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
||||||
|
|
||||||
|
|
||||||
return "select_course";
|
return "select_course";
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -63,7 +66,7 @@ public class CourseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/select/change")
|
@GetMapping("/select/change")
|
||||||
public String showChangeCourse(Model model) {
|
public String showChangeCourse(Model model) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ 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.ModelAttribute;
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
|
import com.example.demo.app.domain.service.CourseService;
|
||||||
import com.example.demo.app.presentation.form.UserForm;
|
import com.example.demo.app.presentation.form.UserForm;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -16,15 +18,33 @@ import lombok.RequiredArgsConstructor;
|
|||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class UserController {
|
public class UserController {
|
||||||
|
|
||||||
|
private final CourseService courseService;
|
||||||
|
|
||||||
@GetMapping("/user/register")
|
@GetMapping("/user/register")
|
||||||
public String showRegister(Model model, HttpSession session) {
|
public String showRegister(Model model, HttpSession session) {
|
||||||
|
UserForm userForm = new UserForm();
|
||||||
|
|
||||||
|
model.addAttribute("userForm", userForm);
|
||||||
|
return "user_register";
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/user/register/return")
|
||||||
|
public String showRegisterReturn(@RequestParam(required = false) Long courseId, Model model, HttpSession session) {
|
||||||
|
|
||||||
UserForm userForm = (UserForm) session.getAttribute("userForm");
|
UserForm userForm = (UserForm) session.getAttribute("userForm");
|
||||||
|
|
||||||
if(userForm == null) {
|
if(userForm == null) {
|
||||||
userForm = new UserForm();
|
userForm = new UserForm();
|
||||||
|
userForm.setCourseId(courseId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(courseId != null) {
|
||||||
|
model.addAttribute("selectedCourseName", courseService.findById(courseId).getCourseName());
|
||||||
|
}
|
||||||
|
|
||||||
|
model.addAttribute("courseId", courseId);
|
||||||
model.addAttribute("userForm", userForm);
|
model.addAttribute("userForm", userForm);
|
||||||
|
|
||||||
return "user_register";
|
return "user_register";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,17 +9,9 @@
|
|||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h1>コース選択</h1>
|
<h1>コース選択</h1>
|
||||||
<form th:action="@{/user/register}" th:object="${userForm}" method="post">
|
|
||||||
<input type="hidden" th:field="*{userName}">
|
|
||||||
<input type="hidden" th:field="*{mailAddress}">
|
<form th:action="${mode == 'regist'} ? @{/user/register/return}: @{/change}" method="post">
|
||||||
<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>
|
<button type="submit">確定</button>
|
||||||
<div class="accordion" id="accordionExample">
|
<div class="accordion" id="accordionExample">
|
||||||
<div class="accordion-item" th:each="course:${courseList}">
|
<div class="accordion-item" th:each="course:${courseList}">
|
||||||
|
|||||||
Reference in New Issue
Block a user