Merge remote-tracking branch 'origin/s-morimto' into s-choi

# Conflicts:
#	src/main/java/com/example/demo/app/infra/repository/AllocationRepository.java
This commit is contained in:
s-choi
2026-09-17 16:17:50 +09:00
25 changed files with 476 additions and 169 deletions

View File

@@ -5,10 +5,6 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public class AllocationModel {
private Long categoryId;
private Long courseId;
private Integer allocationRatio;
public class AuthenticationModel {
private Long userId;
}

View File

@@ -1,28 +0,0 @@
package com.example.demo.app.domain.model;
import java.util.List;
import com.example.demo.app.infra.entity.CourseEntity;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class CourseModel {
private Long courseId;
private String courseName;
private String description;
public static CourseModel convertFrom(CourseEntity courseEntity) {
return new CourseModel(
courseEntity.getCourseId(),
courseEntity.getCourseName(),
courseEntity.getDescription());
}
public static List<CourseModel> convertFrom(List<CourseEntity> courseEntityList) {
return courseEntityList.stream().map(CourseModel::convertFrom).toList();
}
}

View File

@@ -8,10 +8,9 @@ import lombok.Getter;
@Getter
@AllArgsConstructor
public class UserModel {
private Long userId;
private String userName;
private String emailAddress;
private String mailAddress;
private String password;
private Integer secretQuestionId;
private String secretAnswer;
@@ -19,7 +18,7 @@ public class UserModel {
private Integer saving;
private Integer annualIncome;
private Integer monthlyBudget;
private Integer goalId;
private Integer courseId;
private Long goalId;
private Long courseId;
private Integer deleteFlag;
}

View File

@@ -0,0 +1,9 @@
package com.example.demo.app.domain.service;
import com.example.demo.app.domain.model.AuthenticationModel;
import com.example.demo.app.presentation.form.AuthenticationForm;
public interface AuthenticationService {
AuthenticationModel authenticate(AuthenticationForm authenticationForm);
}

View File

@@ -0,0 +1,8 @@
package com.example.demo.app.domain.service;
import com.example.demo.app.presentation.form.PasswordResetForm;
public interface PasswordResetService {
boolean resetPassword(Long userId, PasswordResetForm passwordResetForm);
}

View File

@@ -0,0 +1,8 @@
package com.example.demo.app.domain.service;
import com.example.demo.app.presentation.form.UserForm;
public interface UserService {
void register(UserForm userForm);
}

View File

@@ -0,0 +1,42 @@
package com.example.demo.app.domain.service.impl;
import org.springframework.stereotype.Service;
import com.example.demo.app.domain.model.AuthenticationModel;
import com.example.demo.app.domain.service.AuthenticationService;
import com.example.demo.app.infra.entity.UserEntity;
import com.example.demo.app.infra.repository.UserRepository;
import com.example.demo.app.presentation.form.AuthenticationForm;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class AuthenticationServiceImpl implements AuthenticationService {
private final UserRepository userRepository;
@Override
public AuthenticationModel authenticate(AuthenticationForm authenticationForm) {
UserEntity userEntity = userRepository.findByMailAddress(
authenticationForm.getMailAddress())
.orElse(null);
if (userEntity == null) {
return null;
}
if (!userEntity.getQuestionEntity().getSecretQuestionId()
.equals(authenticationForm.getSecretQuestionId())) {
return null;
}
if (!userEntity.getSecretQuestionAnswer()
.equals(authenticationForm.getSecretAnswer())) {
return null;
}
return new AuthenticationModel(userEntity.getUserId());
}
}

View File

@@ -0,0 +1,41 @@
package com.example.demo.app.domain.service.impl;
import org.springframework.stereotype.Service;
import com.example.demo.app.domain.service.PasswordResetService;
import com.example.demo.app.infra.entity.UserEntity;
import com.example.demo.app.infra.repository.UserRepository;
import com.example.demo.app.presentation.form.PasswordResetForm;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class PasswordResetServiceImpl implements PasswordResetService {
private final UserRepository userRepository;
@Override
public boolean resetPassword(
Long userId,
PasswordResetForm passwordResetForm) {
if (!passwordResetForm.getPassword()
.equals(passwordResetForm.getPasswordConfirm())) {
return false;
}
UserEntity userEntity =
userRepository.findById(userId).orElse(null);
if (userEntity == null) {
return false;
}
userEntity.setPassword(passwordResetForm.getPassword());
userRepository.save(userEntity);
return true;
}
}

View File

@@ -0,0 +1,58 @@
package com.example.demo.app.domain.service.impl;
import org.springframework.stereotype.Service;
import com.example.demo.app.domain.service.UserService;
import com.example.demo.app.infra.entity.CourseEntity;
import com.example.demo.app.infra.entity.GoalEntity;
import com.example.demo.app.infra.entity.QuestionEntity;
import com.example.demo.app.infra.entity.UserEntity;
import com.example.demo.app.infra.repository.CourseRepository;
import com.example.demo.app.infra.repository.GoalRepository;
import com.example.demo.app.infra.repository.QuestionRepository;
import com.example.demo.app.infra.repository.UserRepository;
import com.example.demo.app.presentation.form.UserForm;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class UserServiceImpl implements UserService {
private final UserRepository userRepository;
private final QuestionRepository questionRepository;
private final GoalRepository goalRepository;
private final CourseRepository courseRepository;
@Override
public void register(UserForm userForm) {
UserEntity userEntity = new UserEntity();
userEntity.setUserName(userForm.getUserName());
userEntity.setMailAddress(userForm.getMailAddress());
userEntity.setPassword(userForm.getPassword());
userEntity.setSecretQuestionAnswer(userForm.getSecretAnswer());
userEntity.setBirthDate(userForm.getBirthDate());
userEntity.setSaving(userForm.getSaving());
userEntity.setAnnualIncome(userForm.getAnnualIncome());
userEntity.setMonthlyBudget(userForm.getMonthlyBudget());
QuestionEntity questionEntity =
questionRepository.findById(userForm.getSecretQuestionId()).orElse(null);
GoalEntity goalEntity =
goalRepository.findById(userForm.getGoalId()).orElse(null);
CourseEntity courseEntity =
courseRepository.findById(userForm.getCourseId()).orElse(null);
userEntity.setQuestionEntity(questionEntity);
userEntity.setGoalEntity(goalEntity);
userEntity.setCourseEntity(courseEntity);
userEntity.setDeleteFlag(0);
userRepository.save(userEntity);
}
}

View File

@@ -1,26 +1,20 @@
package com.example.demo.app.infra.entity;
import java.util.List;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
import jakarta.persistence.IdClass;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import com.example.demo.app.domain.model.AllocationModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@IdClass(AllocationId.class)
@Table(name = "allocation_m")
@Table(name = "allocation")
@Data
@NoArgsConstructor
@AllArgsConstructor
@@ -39,15 +33,4 @@ public class AllocationEntity {
@Column(name = "allocation_ratio", nullable = false)
private Integer allocationRatio;
public static List<AllocationModel> createAllocationModelList(List<AllocationEntity> allocationEntityList) {
return allocationEntityList
.stream()
.map(allocationEntity -> new AllocationModel(
allocationEntity.getCategoryEntity().getCategoryId(),
allocationEntity.getCourseEntity().getCourseId(),
allocationEntity.getAllocationRatio()
)).toList();
}
}

View File

@@ -1,16 +0,0 @@
package com.example.demo.app.infra.entity;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AllocationId implements Serializable {
private Long categoryEntity;
private Long courseEntity;
}

View File

@@ -6,19 +6,18 @@ import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import com.example.demo.app.domain.model.CourseModel;
import org.springframework.data.annotation.Id;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@Table(name = "course_m")
@Table(name = "course")
@Data
@NoArgsConstructor
@AllArgsConstructor
@@ -40,18 +39,6 @@ public class CourseEntity {
private List<UserEntity> userEntity;
@OneToOne(mappedBy = "courseEntity")
private AllocationEntity allocationEntity;
public static List<CourseModel> createCourseModelList(List<CourseEntity> courseEntityList) {
return courseEntityList
.stream()
.map(courseEntity -> new CourseModel(
courseEntity.getCourseId(),
courseEntity.getCourseName(),
courseEntity.getDescription()
)).toList();
}
private List<AllocationEntity> allocationEntity;
}

View File

@@ -29,7 +29,7 @@ public class QuestionEntity {
@Column(name = "question_text", nullable = false)
private String questionText;
@OneToMany(mappedBy = "questionEntity")
@OneToMany(mappedBy = "QuestionEntity")
private List<UserEntity> userEntity;
}

View File

@@ -7,7 +7,6 @@ import org.springframework.data.jpa.repository.Query;
import com.example.demo.app.domain.model.CourseInfoModel;
import com.example.demo.app.infra.entity.AllocationEntity;
import com.example.demo.app.infra.entity.AllocationId;
public interface AllocationRepository extends JpaRepository<AllocationEntity, AllocationId>{

View File

@@ -0,0 +1,56 @@
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.PostMapping;
import com.example.demo.app.domain.model.AuthenticationModel;
import com.example.demo.app.domain.service.AuthenticationService;
import com.example.demo.app.infra.repository.QuestionRepository;
import com.example.demo.app.presentation.form.AuthenticationForm;
import lombok.RequiredArgsConstructor;
@Controller
@RequiredArgsConstructor
public class AuthenticationController {
private final AuthenticationService authenticationService;
private final QuestionRepository questionRepository;
@GetMapping("/authentication")
public String showAuthentication(Model model) {
model.addAttribute("authenticationForm", new AuthenticationForm());
model.addAttribute("questionList", questionRepository.findAll());
return "authentication";
}
@PostMapping("/authentication")
public String authenticate(
AuthenticationForm authenticationForm,
Model model,
HttpSession session) {
AuthenticationModel authenticationModel =
authenticationService.authenticate(authenticationForm);
if (authenticationModel == null) {
model.addAttribute("errorMessage", "認証情報が正しくありません。");
model.addAttribute("questionList", questionRepository.findAll());
return "authentication";
}
session.setAttribute(
"passwordResetUserId",
authenticationModel.getUserId());
return "password_reset";
}
}

View File

@@ -0,0 +1,61 @@
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.PostMapping;
import com.example.demo.app.domain.service.PasswordResetService;
import com.example.demo.app.presentation.form.PasswordResetForm;
import lombok.RequiredArgsConstructor;
@Controller
@RequiredArgsConstructor
public class PasswordResetController {
private final PasswordResetService passwordResetService;
@GetMapping("/password_reset")
public String showPasswordReset(Model model) {
model.addAttribute(
"passwordResetForm",
new PasswordResetForm());
return "password_reset";
}
@PostMapping("/password_reset")
public String resetPassword(
PasswordResetForm passwordResetForm,
Model model,
HttpSession session) {
Long userId =
(Long) session.getAttribute("passwordResetUserId");
if (userId == null) {
return "redirect:/login";
}
boolean isReset =
passwordResetService.resetPassword(
userId,
passwordResetForm);
if (!isReset) {
model.addAttribute(
"errorMessage",
"パスワードが一致していません。");
return "password_reset";
}
session.removeAttribute("passwordResetUserId");
return "redirect:/login";
}
}

View File

@@ -0,0 +1,35 @@
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) {
model.addAttribute("userForm", new UserForm());
return "user_register";
}
@PostMapping("/user/register/confirm")
public String confirmRegister(
@ModelAttribute UserForm userForm,
HttpSession session) {
session.setAttribute("userForm", userForm);
return "user_register_confirm";
}
}

View File

@@ -0,0 +1,14 @@
package com.example.demo.app.presentation.form;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class AuthenticationForm {
private String mailAddress;
private Integer secretQuestionId;
private String secretAnswer;
}

View File

@@ -1,33 +0,0 @@
package com.example.demo.app.presentation.form;
import java.util.List;
import com.example.demo.app.domain.model.CourseModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CourseForm {
private Long courseId;
private String courseName;
private String description;
public static CourseForm convertFrom(CourseModel courseModel) {
return new CourseForm(
courseModel.getCourseId(),
courseModel.getCourseName(),
courseModel.getDescription()
);
}
public static List<CourseForm> convertFrom(List<CourseModel> courseModelList){
return courseModelList.stream().map(CourseForm::convertFrom).toList();
}
}

View File

@@ -1,44 +0,0 @@
package com.example.demo.app.presentation.form;
import java.util.List;
import com.example.demo.app.domain.model.CourseInfoModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CourseInfoForm {
private Long courseId;
private String courseName;
private Long categoryId;
private String categoryName;
private Integer allocationRatio;
public static CourseInfoForm convertFrom(CourseInfoModel courseInfoModel ) {
return new CourseInfoForm(courseInfoModel.getCategoryId(), courseInfoModel.getCourseName(), courseInfoModel.getCategoryId(), courseInfoModel.getCategoryName(), courseInfoModel.getAllocationRatio());
}
public static List<CourseInfoForm> convertFrom(List<CourseInfoModel> courseInfoModelList ) {
return courseInfoModelList.stream().map(CourseInfoForm::convertFrom).toList();
}
public static CourseInfoModel convertTo(CourseInfoForm courseInfoForm) {
return new CourseInfoModel(
courseInfoForm.getCourseId(),
courseInfoForm.getCourseName(),
courseInfoForm.getCategoryId(),
courseInfoForm.getCategoryName(),
courseInfoForm.getAllocationRatio());
}
}

View File

@@ -0,0 +1,13 @@
package com.example.demo.app.presentation.form;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PasswordResetForm {
private String password;
private String passwordConfirm;
}

View File

@@ -0,0 +1,24 @@
package com.example.demo.app.presentation.form;
import java.time.LocalDate;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserForm {
private String userName;
private String mailAddress;
private String password;
private Long secretQuestionId;
private String SecretAnswer;
private LocalDate birthDate;
private Integer saving;
private Integer annualIncome;
private Integer monthlyBudget;
private Long goalId;
private Long courseId;
}

View File

@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>認証</title>
</head>
<body>
<main>
<h1>本人認証確認</h1>
<form th:action="@{/authentication}" th:object="${authenticationForm}" method="post">
<div>
<label for="mailAddress">メールアドレス</label>
<input type="email" id="mailAddress" th:field="*{mailAddress}">
</div>
<div>
<label for="secretQuestionId">秘密の質問</label>
<select id="secretQuestionId" th:field="*{secretQuestionId}">
<option value="">選択してください</option>
<option th:each="question : ${questionList}" th:value="${question.secretQuestionId}"
th:text="${question.questionText}">
</option>
</select>
</div>
<div>
<label for="secretAnswer">秘密の質問の回答</label>
<input type="text" id="secretAnswer" th:field="*{secretAnswer}">
</div>
<button type="submit">確認</button>
</form>
<form th:action="@{/login}" method="get">
<button type="submit">戻る</button>
</form>
</main>
<script th:if="${errorMessage}" th:inline="javascript">
alert(/*[[${errorMessage}]]*/);
</script>
</body>
</html>

View File

@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="ja"xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>パスワード再設定</title>
</head>
<body>
<header></header>
<main>
<h1>パスワード再設定</h1>
<form th:action="@{/password_reset}" th:obiect="${passwordResteForm"} method="post">
<div>
<label for="password">新しいパスワード</label>
<input type="password"
id="password"
th:field="*{password}"
minlength="8"
maxlength="255"
required>
</div>
<div>
<label for="passwordConfirm">パスワード確認</label>
<input type="password"
id="passwordConfirm"
th:field="*{passwordConfirm}"
minlength="8"
maxlength="255"
required>
</div>
<button type="submit">再設定</button>
</form>
<div th:if="${errorMessage}">
<p th:text="${errorMessage}"></p>
</div>
</main>
</body>
</html>

View File

@@ -1,5 +1,5 @@
<!DOCTYPE html>
<html>
<html lang="ja"xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>新規会員登録確認</title>