Merge branch 'n-kawahito' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into s-choi
This commit is contained in:
@@ -4,6 +4,9 @@ import com.example.demo.app.domain.model.AnalysisModel;
|
|||||||
|
|
||||||
public interface AnalysisService {
|
public interface AnalysisService {
|
||||||
|
|
||||||
AnalysisModel getAnalysis(Long userId);
|
AnalysisModel getAnalysis(
|
||||||
|
Long userId,
|
||||||
|
Integer year,
|
||||||
|
Integer month);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.example.demo.app.domain.service;
|
package com.example.demo.app.domain.service;
|
||||||
|
|
||||||
import com.example.demo.app.domain.model.ProfileModel;
|
import com.example.demo.app.domain.model.ProfileModel;
|
||||||
|
import com.example.demo.app.presentation.form.ProfileEditForm;
|
||||||
|
|
||||||
public interface ProfileService {
|
public interface ProfileService {
|
||||||
ProfileModel findOne(Long userId);
|
ProfileModel findOne(Long userId);
|
||||||
void withdraw(Long userId);
|
void withdraw(Long userId);
|
||||||
|
void update(Long userId, ProfileEditForm profileEditForm);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|||||||
private final CategoryRepository categoryRepository;
|
private final CategoryRepository categoryRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AnalysisModel getAnalysis(Long userId) {
|
public AnalysisModel getAnalysis(Long userId, Integer year, Integer month) {
|
||||||
|
|
||||||
// ユーザー情報取得、月別使用可能資金取得
|
// ユーザー情報取得、月別使用可能資金取得
|
||||||
UserEntity userEntity = userRepository.findById(userId).orElseThrow(() ->
|
UserEntity userEntity = userRepository.findById(userId).orElseThrow(() ->
|
||||||
@@ -44,12 +44,15 @@ public class AnalysisServiceImpl implements AnalysisService {
|
|||||||
Integer monthlyBudget =userEntity.getMonthlyBudget();
|
Integer monthlyBudget =userEntity.getMonthlyBudget();
|
||||||
|
|
||||||
// 今月の期間取得
|
// 今月の期間取得
|
||||||
LocalDate currentMonthStartDate = LocalDate.now().withDayOfMonth(1);
|
LocalDate targetDate = LocalDate.of(year, month, 1);
|
||||||
LocalDate currentMonthEndDate = LocalDate.now().withDayOfMonth(LocalDate.now().lengthOfMonth());
|
LocalDate currentMonthStartDate = targetDate.withDayOfMonth(1);
|
||||||
|
LocalDate currentMonthEndDate = targetDate.withDayOfMonth(targetDate.lengthOfMonth());
|
||||||
|
|
||||||
// 前月の期間取得
|
// 前月の期間取得
|
||||||
LocalDate previousMonthStartDate = LocalDate.now().minusMonths(1).withDayOfMonth(1);
|
LocalDate previousDate = targetDate.minusMonths(1);
|
||||||
LocalDate previousMonthEndDate = LocalDate.now().minusMonths(1).withDayOfMonth(LocalDate.now().minusMonths(1).lengthOfMonth());
|
|
||||||
|
LocalDate previousMonthStartDate = previousDate.withDayOfMonth(1);
|
||||||
|
LocalDate previousMonthEndDate = previousDate.withDayOfMonth(previousDate.lengthOfMonth());
|
||||||
|
|
||||||
// 今月の支出取得
|
// 今月の支出取得
|
||||||
Integer currentMonthTotalAmount = transactionRepository.findTotalExpense(currentMonthStartDate, currentMonthEndDate, userId);
|
Integer currentMonthTotalAmount = transactionRepository.findTotalExpense(currentMonthStartDate, currentMonthEndDate, userId);
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import com.example.demo.app.domain.model.ProfileModel;
|
|||||||
import com.example.demo.app.domain.service.ProfileService;
|
import com.example.demo.app.domain.service.ProfileService;
|
||||||
import com.example.demo.app.infra.entity.UserEntity;
|
import com.example.demo.app.infra.entity.UserEntity;
|
||||||
import com.example.demo.app.infra.repository.UserRepository;
|
import com.example.demo.app.infra.repository.UserRepository;
|
||||||
|
import com.example.demo.app.presentation.form.ProfileEditForm;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ public class ProfileServiceImpl implements ProfileService{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void withdraw(Long userId) {
|
public void withdraw(Long userId) {
|
||||||
UserEntity userEntity =userRepository.findById(userId).orElse(null);
|
UserEntity userEntity = userRepository.findById(userId).orElse(null);
|
||||||
|
|
||||||
if (userEntity == null) {
|
if (userEntity == null) {
|
||||||
return;
|
return;
|
||||||
@@ -43,4 +44,20 @@ public class ProfileServiceImpl implements ProfileService{
|
|||||||
userEntity.setDeleteFlag(1);
|
userEntity.setDeleteFlag(1);
|
||||||
userRepository.save(userEntity);
|
userRepository.save(userEntity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update(Long userId, ProfileEditForm profileEditForm) {
|
||||||
|
UserEntity userEntity = userRepository.findById(userId).orElse(null);
|
||||||
|
|
||||||
|
if (userEntity == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
userEntity.setUserName(profileEditForm.getUserName());
|
||||||
|
userEntity.setMailAddress(profileEditForm.getMailAddress());
|
||||||
|
userEntity.setSaving(profileEditForm.getSaving());
|
||||||
|
userEntity.setAnnualIncome(profileEditForm.getAnnualIncome());
|
||||||
|
userEntity.setMonthlyBudget(profileEditForm.getMonthlyBudget());
|
||||||
|
userRepository.save(userEntity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
package com.example.demo.app.presentation.controller;
|
package com.example.demo.app.presentation.controller;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
import jakarta.servlet.http.HttpSession;
|
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.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import com.example.demo.aop.aspect.SessionCheck;
|
import com.example.demo.aop.aspect.SessionCheck;
|
||||||
import com.example.demo.app.domain.model.AnalysisModel;
|
import com.example.demo.app.domain.model.AnalysisModel;
|
||||||
@@ -23,18 +26,45 @@ public class AnalysisController {
|
|||||||
|
|
||||||
@SessionCheck
|
@SessionCheck
|
||||||
@GetMapping("/analysis")
|
@GetMapping("/analysis")
|
||||||
public String showAnalysis(Model model, HttpSession session) {
|
public String showAnalysis(
|
||||||
|
@RequestParam(required = false) Integer year,
|
||||||
|
@RequestParam(required = false) Integer month,
|
||||||
|
Model model,
|
||||||
|
HttpSession session) {
|
||||||
|
|
||||||
//ログインユーザーの取得(セッション)
|
//ログインユーザーの取得(セッション)
|
||||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||||
|
|
||||||
|
//初期年月表示
|
||||||
|
LocalDate nowDate = LocalDate.now();
|
||||||
|
|
||||||
|
if (year == null) {
|
||||||
|
year = nowDate.getYear();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (month == null) {
|
||||||
|
month = nowDate.getMonthValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
//前月・翌月作成
|
||||||
|
LocalDate targetDate = LocalDate.of(year, month, 1);
|
||||||
|
|
||||||
|
LocalDate previousDate = targetDate.minusMonths(1);
|
||||||
|
LocalDate nextDate = targetDate.plusMonths(1);
|
||||||
|
|
||||||
//分析結果の取得(Service)
|
//分析結果の取得(Service)
|
||||||
AnalysisModel analysisModel = analysisService.getAnalysis(loginUser.getUserId());
|
AnalysisModel analysisModel = analysisService.getAnalysis(loginUser.getUserId(), year, month);
|
||||||
|
|
||||||
AnalysisForm analysisForm = AnalysisForm.convertFrom(analysisModel);
|
AnalysisForm analysisForm = AnalysisForm.convertFrom(analysisModel);
|
||||||
|
|
||||||
//model格納
|
//model格納
|
||||||
model.addAttribute("analysisForm", analysisForm);
|
model.addAttribute("analysisForm", analysisForm);
|
||||||
|
model.addAttribute("year", year);
|
||||||
|
model.addAttribute("month", month);
|
||||||
|
model.addAttribute("previousYear", previousDate.getYear());
|
||||||
|
model.addAttribute("previousMonth", previousDate.getMonthValue());
|
||||||
|
model.addAttribute("nextYear", nextDate.getYear());
|
||||||
|
model.addAttribute("nextMonth", nextDate.getMonthValue());
|
||||||
|
|
||||||
return "analysis";
|
return "analysis";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,53 @@
|
|||||||
|
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("Message", "パスワードが一致しません。");
|
||||||
|
return "password_reset";
|
||||||
|
}
|
||||||
|
|
||||||
|
session.removeAttribute("passwordResetUserId");
|
||||||
|
|
||||||
|
return "redirect:/login";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -5,12 +5,14 @@ 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.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
import com.example.demo.aop.aspect.SessionCheck;
|
import com.example.demo.aop.aspect.SessionCheck;
|
||||||
import com.example.demo.app.domain.model.LoginModel;
|
import com.example.demo.app.domain.model.LoginModel;
|
||||||
import com.example.demo.app.domain.model.ProfileModel;
|
import com.example.demo.app.domain.model.ProfileModel;
|
||||||
import com.example.demo.app.domain.service.ProfileService;
|
import com.example.demo.app.domain.service.ProfileService;
|
||||||
|
import com.example.demo.app.presentation.form.ProfileEditForm;
|
||||||
import com.example.demo.app.presentation.form.ProfileForm;
|
import com.example.demo.app.presentation.form.ProfileForm;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -35,10 +37,43 @@ public class ProfileController {
|
|||||||
|
|
||||||
@SessionCheck
|
@SessionCheck
|
||||||
@GetMapping("/profile/edit")
|
@GetMapping("/profile/edit")
|
||||||
public String showEditProfile() {
|
public String showEditProfile(
|
||||||
|
Model model,
|
||||||
|
HttpSession session) {
|
||||||
|
|
||||||
|
LoginModel loginUser =
|
||||||
|
(LoginModel) session.getAttribute("loginUser");
|
||||||
|
|
||||||
|
ProfileModel profileModel =
|
||||||
|
profileService.findOne(loginUser.getUserId());
|
||||||
|
|
||||||
|
ProfileEditForm profileEditForm =
|
||||||
|
new ProfileEditForm(
|
||||||
|
profileModel.getUserName(),
|
||||||
|
profileModel.getMailAddress(),
|
||||||
|
profileModel.getSaving(),
|
||||||
|
profileModel.getAnnualIncome(),
|
||||||
|
profileModel.getMonthlyBudget());
|
||||||
|
|
||||||
|
model.addAttribute("profileEditForm", profileEditForm);
|
||||||
return "profile_edit";
|
return "profile_edit";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/profile/edit")
|
||||||
|
public String updateProfile(
|
||||||
|
@ModelAttribute ProfileEditForm profileEditForm,
|
||||||
|
HttpSession session) {
|
||||||
|
|
||||||
|
LoginModel loginUser =
|
||||||
|
(LoginModel) session.getAttribute("loginUser");
|
||||||
|
|
||||||
|
profileService.update(
|
||||||
|
loginUser.getUserId(),
|
||||||
|
profileEditForm);
|
||||||
|
|
||||||
|
return "redirect:/profile";
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/withdraw")
|
@PostMapping("/withdraw")
|
||||||
public String withdraw(HttpSession session) {
|
public String withdraw(HttpSession session) {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.example.demo.app.presentation.form;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ProfileEditForm {
|
||||||
|
private String userName;
|
||||||
|
private String mailAddress;
|
||||||
|
private Integer saving;
|
||||||
|
private Integer annualIncome;
|
||||||
|
private Integer monthlyBudget;
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
<title>分析画面</title>
|
<title>分析画面</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body class="pb-5 pt-5">
|
<body class="pb-5 pt-5">
|
||||||
|
|
||||||
<div th:replace="~{header :: header}">
|
<div th:replace="~{header :: header}">
|
||||||
@@ -13,6 +14,23 @@
|
|||||||
<div class="container mt-4">
|
<div class="container mt-4">
|
||||||
<h2 class="text-center">支出分析</h2>
|
<h2 class="text-center">支出分析</h2>
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
|
||||||
|
<a class="month-button" th:href="@{/analysis(year=${previousYear}, month=${previousMonth})}">
|
||||||
|
←
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<div class="calendar-date">
|
||||||
|
<span class="year" th:text="|${year}年|"></span>
|
||||||
|
<span class="month" th:text="|${month}月|"></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<a class="month-button" th:href="@{/analysis(year=${nextYear}, month=${nextMonth})}">
|
||||||
|
→
|
||||||
|
</a>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
<table class="table text-center">
|
<table class="table text-center">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>プロフィール</title>
|
<title>プロフィール</title>
|
||||||
|
|||||||
72
src/main/resources/templates/profile_edit.html
Normal file
72
src/main/resources/templates/profile_edit.html
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>プロフィール編集</title>
|
||||||
|
</head>
|
||||||
|
<body class="pb-5 pt-5">
|
||||||
|
|
||||||
|
<div th:replace="~{header :: header}">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<main>
|
||||||
|
<h1>プロフィール編集</h1>
|
||||||
|
|
||||||
|
<form th:action="@{/profile/edit}"th:object="${profileEditForm}"method="post">
|
||||||
|
<div>
|
||||||
|
<label>氏名</label>
|
||||||
|
<input type="text"
|
||||||
|
th:field="*{userName}"
|
||||||
|
maxlength="100"
|
||||||
|
required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>メールアドレス</label>
|
||||||
|
<input type="email"
|
||||||
|
th:field="*{mailAddress}"
|
||||||
|
maxlength="255"
|
||||||
|
required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>パスワード</label>
|
||||||
|
<input type="password"
|
||||||
|
value="********"
|
||||||
|
disabled>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>貯蓄金</label>
|
||||||
|
<input type="number"
|
||||||
|
th:field="*{saving}"
|
||||||
|
min="0"
|
||||||
|
required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>年収</label>
|
||||||
|
<input type="number"
|
||||||
|
th:field="*{annualIncome}"
|
||||||
|
min="0"
|
||||||
|
required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label>月別使用可能額</label>
|
||||||
|
<input type="number"
|
||||||
|
th:field="*{monthlyBudget}"
|
||||||
|
min="0"
|
||||||
|
required>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<button type="submit">確認</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<div th:replace="~{footer :: footer}">
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user