Merge branch 's-morimto' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-kobayashi
# Conflicts: # src/main/java/com/example/demo/app/presentation/controller/UserController.java # src/main/resources/templates/login.html # src/main/resources/templates/password_reset.html
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package com.example.demo.app.domain.model;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class ProfileModel {
|
||||
private Long userId;
|
||||
private String userName;
|
||||
private String emailAddress;
|
||||
private LocalDate brithDate;
|
||||
private Integer saving;
|
||||
private Integer annualIncome;
|
||||
private Integer monthlyBudget;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.demo.app.domain.service;
|
||||
|
||||
import com.example.demo.app.domain.model.ProfileModel;
|
||||
|
||||
public interface ProfileService {
|
||||
ProfileModel findOne(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.app.domain.model.ProfileModel;
|
||||
import com.example.demo.app.domain.service.ProfileService;
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ProfileServiceImpl implements ProfileService{
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public ProfileModel findOne(Long userId) {
|
||||
UserEntity userEntity = userRepository.findById(userId).orElse(null);
|
||||
|
||||
if(userEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ProfileModel(
|
||||
userEntity.getUserId(),
|
||||
userEntity.getUserName(),
|
||||
userEntity.getMailAddress(),
|
||||
userEntity.getBirthDate(),
|
||||
userEntity.getSaving(),
|
||||
userEntity.getAnnualIncome(),
|
||||
userEntity.getMonthlyBudget());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import com.example.demo.app.domain.model.LoginModel;
|
||||
import com.example.demo.app.domain.model.ProfileModel;
|
||||
import com.example.demo.app.domain.service.ProfileService;
|
||||
import com.example.demo.app.presentation.form.ProfileForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class ProfileController {
|
||||
private final ProfileService profileService;
|
||||
|
||||
@GetMapping("/profile")
|
||||
public String profile(Model model, HttpSession session) {
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||
|
||||
ProfileModel profileModel = profileService.findOne(loginUser.getUserId());
|
||||
|
||||
ProfileForm profileForm = ProfileForm.convertForm(profileModel);
|
||||
|
||||
model.addAttribute("profileForm", profileForm);
|
||||
return "profile";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
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 com.example.demo.app.presentation.form.UserForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class UserController {
|
||||
|
||||
@GetMapping("/user/register")
|
||||
public String showRegister(Model model, HttpSession session) {
|
||||
UserForm userForm = (UserForm) session.getAttribute("userForm");
|
||||
|
||||
if(userForm == null) {
|
||||
userForm = new UserForm();
|
||||
}
|
||||
|
||||
model.addAttribute("userForm", userForm);
|
||||
return "user_register";
|
||||
}
|
||||
|
||||
@PostMapping("/user/register/confirm")
|
||||
public String confirmRegister(
|
||||
@ModelAttribute UserForm userForm,
|
||||
HttpSession session) {
|
||||
|
||||
session.setAttribute("userForm", userForm);
|
||||
|
||||
return "user_register_confirm";
|
||||
}
|
||||
|
||||
@PostMapping("/user/register/complete")
|
||||
public String completeRegister(HttpSession session) {
|
||||
|
||||
UserForm userForm =
|
||||
(UserForm) session.getAttribute("userForm");
|
||||
|
||||
// DBへの登録処理
|
||||
|
||||
session.removeAttribute("userForm");
|
||||
|
||||
return "redirect:/login";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import com.example.demo.app.domain.model.ProfileModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ProfileForm {
|
||||
private Long userId;
|
||||
private String userName;
|
||||
private String emailAddress;
|
||||
private LocalDate brithDate;
|
||||
private Integer saving;
|
||||
private Integer annualIncome;
|
||||
private Integer monthlyBudget;
|
||||
|
||||
public static ProfileForm convertForm(ProfileModel profileModel) {
|
||||
return new ProfileForm(
|
||||
profileModel.getUserId(),
|
||||
profileModel.getUserName(),
|
||||
profileModel.getEmailAddress(),
|
||||
profileModel.getBrithDate(),
|
||||
profileModel.getSaving(),
|
||||
profileModel.getAnnualIncome(),
|
||||
profileModel.getMonthlyBudget());
|
||||
}
|
||||
}
|
||||
@@ -98,28 +98,18 @@
|
||||
|
||||
<div>
|
||||
<label for="goalId">目標</label>
|
||||
<select id="goalId"
|
||||
<input type="number"
|
||||
id="goalId"
|
||||
th:field="*{goalId}"
|
||||
min="0"
|
||||
required>
|
||||
<option value="">選択してください</option>
|
||||
<option th:each="goal : ${goalList}"
|
||||
th:value="${goal.goalId}"
|
||||
th:text="${goal.goalTitle}">
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="courseId">コース</label>
|
||||
<select id="courseId"
|
||||
th:field="*{courseId}"
|
||||
required>
|
||||
<option value="">選択してください</option>
|
||||
<option th:each="course : ${courseList}"
|
||||
th:value="${course.courseId}"
|
||||
th:text="${course.courseName}">
|
||||
</option>
|
||||
</select>
|
||||
<label>コース</label>
|
||||
<input type="hidden" th:field="*{courseId}">
|
||||
<span th:text="${selectedCourseName}">未選択</span>
|
||||
<button type="button"onclick="location.href='/select-course'">コース選択</button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user