Compare commits
10 Commits
69213bcf9c
...
ed7a3a67b7
| Author | SHA1 | Date | |
|---|---|---|---|
| ed7a3a67b7 | |||
|
|
41c5f6e99e | ||
|
|
af3e171006 | ||
| 79b1abeac6 | |||
| 1d010dc02b | |||
|
|
d308f14df4 | ||
|
|
a36705d83f | ||
|
|
ab802cdb25 | ||
|
|
1160af5711 | ||
|
|
d2cf2e6e98 |
11
src/main/java/com/example/demo/aop/aspect/SessionCheck.java
Normal file
11
src/main/java/com/example/demo/aop/aspect/SessionCheck.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.example.demo.aop.aspect;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface SessionCheck {
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.example.demo.aop.aspect;
|
||||
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.example.demo.exception.NoSessionException;
|
||||
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class SessionCheckAspect {
|
||||
|
||||
HttpServletRequest request;
|
||||
|
||||
@Autowired
|
||||
public SessionCheckAspect(HttpServletRequest request) {
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
@Pointcut("@annotation(com.example.demo.aop.aspect.SessionCheck)")
|
||||
public void sessionCheckMethod() {
|
||||
}
|
||||
|
||||
@Before("sessionCheckMethod()")
|
||||
public void checkSession() {
|
||||
HttpSession session = request.getSession(false);
|
||||
|
||||
if (session == null || session.getAttribute("loginUser") == null) {
|
||||
throw new NoSessionException("不正なログインです");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.example.demo.aop.handler;
|
||||
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
||||
import com.example.demo.exception.NoSessionException;
|
||||
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(GlobalExceptionHandler.class.getName());
|
||||
|
||||
private final String SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION = "不正な遷移です。";
|
||||
private final String SEVERE_ERROR_MESSAGE_BAD_REQUEST = "不正なリクエストです。";
|
||||
|
||||
@ExceptionHandler(NoSessionException.class)
|
||||
public String handleNoSessionException(Model model, Exception e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
|
||||
|
||||
model.addAttribute(
|
||||
"errorMessage",
|
||||
"システムエラーが発生しました。"
|
||||
+ "初めからやり直してください。");
|
||||
|
||||
return "error";
|
||||
|
||||
}
|
||||
|
||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
||||
public String handleBadRequestException(Model model, Exception e) {
|
||||
model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST);
|
||||
model.addAttribute("status", HttpStatus.BAD_REQUEST.value());
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
|
||||
|
||||
return "error";
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public String AllException(Model model, Exception e) {
|
||||
model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST);
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
|
||||
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,8 @@ public class GoalModel {
|
||||
|
||||
private Integer achievementRate; // 達成率
|
||||
|
||||
private Integer currentAmount; // 現在の資産
|
||||
|
||||
public static GoalModel convertFrom(GoalEntity goalEntity) {
|
||||
return new GoalModel(
|
||||
goalEntity.getGoalId(),
|
||||
@@ -34,7 +36,7 @@ public class GoalModel {
|
||||
goalEntity.getTargetAmount(),
|
||||
goalEntity.getDeadline(),
|
||||
goalEntity.getGoalComplete(),
|
||||
null);
|
||||
null,null);
|
||||
}
|
||||
|
||||
public static GoalEntity convertTo(GoalModel goalModel) {
|
||||
@@ -56,7 +58,7 @@ public class GoalModel {
|
||||
goalForm.getTargetAmount(),
|
||||
goalForm.getDeadline(),
|
||||
goalForm.getGoalComplete()
|
||||
,null);
|
||||
,null,null);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,9 @@ import com.example.demo.app.domain.model.AnalysisModel;
|
||||
|
||||
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;
|
||||
|
||||
import com.example.demo.app.domain.model.ProfileModel;
|
||||
import com.example.demo.app.presentation.form.ProfileEditForm;
|
||||
|
||||
public interface ProfileService {
|
||||
ProfileModel findOne(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;
|
||||
|
||||
@Override
|
||||
public AnalysisModel getAnalysis(Long userId) {
|
||||
public AnalysisModel getAnalysis(Long userId, Integer year, Integer month) {
|
||||
|
||||
// ユーザー情報取得、月別使用可能資金取得
|
||||
UserEntity userEntity = userRepository.findById(userId).orElseThrow(() ->
|
||||
@@ -44,12 +44,15 @@ public class AnalysisServiceImpl implements AnalysisService {
|
||||
Integer monthlyBudget =userEntity.getMonthlyBudget();
|
||||
|
||||
// 今月の期間取得
|
||||
LocalDate currentMonthStartDate = LocalDate.now().withDayOfMonth(1);
|
||||
LocalDate currentMonthEndDate = LocalDate.now().withDayOfMonth(LocalDate.now().lengthOfMonth());
|
||||
LocalDate targetDate = LocalDate.of(year, month, 1);
|
||||
LocalDate currentMonthStartDate = targetDate.withDayOfMonth(1);
|
||||
LocalDate currentMonthEndDate = targetDate.withDayOfMonth(targetDate.lengthOfMonth());
|
||||
|
||||
// 前月の期間取得
|
||||
LocalDate previousMonthStartDate = LocalDate.now().minusMonths(1).withDayOfMonth(1);
|
||||
LocalDate previousMonthEndDate = LocalDate.now().minusMonths(1).withDayOfMonth(LocalDate.now().minusMonths(1).lengthOfMonth());
|
||||
LocalDate previousDate = targetDate.minusMonths(1);
|
||||
|
||||
LocalDate previousMonthStartDate = previousDate.withDayOfMonth(1);
|
||||
LocalDate previousMonthEndDate = previousDate.withDayOfMonth(previousDate.lengthOfMonth());
|
||||
|
||||
// 今月の支出取得
|
||||
Integer currentMonthTotalAmount = transactionRepository.findTotalExpense(currentMonthStartDate, currentMonthEndDate, userId);
|
||||
|
||||
@@ -56,7 +56,8 @@ public class GoalServiceImpl implements GoalService {
|
||||
goalModel.getTargetAmount(),
|
||||
goalModel.getDeadline(),
|
||||
goalModel.getGoalComplete(),
|
||||
achievementRate);
|
||||
achievementRate,
|
||||
currentAmount);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -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.infra.entity.UserEntity;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
import com.example.demo.app.presentation.form.ProfileEditForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -34,7 +35,7 @@ public class ProfileServiceImpl implements ProfileService{
|
||||
|
||||
@Override
|
||||
public void withdraw(Long userId) {
|
||||
UserEntity userEntity =userRepository.findById(userId).orElse(null);
|
||||
UserEntity userEntity = userRepository.findById(userId).orElse(null);
|
||||
|
||||
if (userEntity == null) {
|
||||
return;
|
||||
@@ -43,4 +44,20 @@ public class ProfileServiceImpl implements ProfileService{
|
||||
userEntity.setDeleteFlag(1);
|
||||
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,11 +1,15 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
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.RequestParam;
|
||||
|
||||
import com.example.demo.aop.aspect.SessionCheck;
|
||||
import com.example.demo.app.domain.model.AnalysisModel;
|
||||
import com.example.demo.app.domain.model.LoginModel;
|
||||
import com.example.demo.app.domain.service.AnalysisService;
|
||||
@@ -20,19 +24,47 @@ public class AnalysisController {
|
||||
|
||||
private final AnalysisService analysisService;
|
||||
|
||||
@SessionCheck
|
||||
@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");
|
||||
|
||||
//初期年月表示
|
||||
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)
|
||||
AnalysisModel analysisModel = analysisService.getAnalysis(loginUser.getUserId());
|
||||
AnalysisModel analysisModel = analysisService.getAnalysis(loginUser.getUserId(), year, month);
|
||||
|
||||
AnalysisForm analysisForm = AnalysisForm.convertFrom(analysisModel);
|
||||
|
||||
//model格納
|
||||
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";
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import com.example.demo.aop.aspect.SessionCheck;
|
||||
import com.example.demo.app.domain.model.AuthenticationModel;
|
||||
import com.example.demo.app.domain.service.AuthenticationService;
|
||||
import com.example.demo.app.infra.repository.QuestionRepository;
|
||||
@@ -21,6 +22,7 @@ public class AuthenticationController {
|
||||
private final AuthenticationService authenticationService;
|
||||
private final QuestionRepository questionRepository;
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping("/authentication")
|
||||
public String showAuthentication(Model model) {
|
||||
|
||||
@@ -30,6 +32,7 @@ public class AuthenticationController {
|
||||
return "authentication";
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping("/authentication")
|
||||
public String authenticate(
|
||||
AuthenticationForm authenticationForm,
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import com.example.demo.aop.aspect.SessionCheck;
|
||||
import com.example.demo.app.domain.model.LoginModel;
|
||||
import com.example.demo.app.domain.model.UserModel;
|
||||
import com.example.demo.app.domain.service.CourseInfoService;
|
||||
@@ -38,7 +39,7 @@ public class CourseController {
|
||||
private final UserService userService;
|
||||
|
||||
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping("/select/register")
|
||||
public String showSelectCourse(@ModelAttribute UserModel userModel, Model model) {
|
||||
|
||||
@@ -63,6 +64,7 @@ public class CourseController {
|
||||
}
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping("/select/change")
|
||||
public String showChangeCourse(Model model) {
|
||||
|
||||
@@ -87,6 +89,7 @@ public class CourseController {
|
||||
}
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping("/change")
|
||||
public String changeCourse(@RequestParam Long courseId) {
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import com.example.demo.aop.aspect.SessionCheck;
|
||||
import com.example.demo.app.domain.model.GoalModel;
|
||||
import com.example.demo.app.domain.model.LoginModel;
|
||||
import com.example.demo.app.domain.service.GoalService;
|
||||
@@ -23,6 +24,7 @@ public class GoalController {
|
||||
|
||||
private final GoalService goalService;
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping("")
|
||||
public String getGoal(Model model, HttpSession session) {
|
||||
|
||||
@@ -37,6 +39,7 @@ public class GoalController {
|
||||
return "goal_view";
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping("/edit")
|
||||
public String editGoal(Model model, HttpSession session) {
|
||||
|
||||
@@ -50,6 +53,7 @@ public class GoalController {
|
||||
return "goal_edit";
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping("/update")
|
||||
public String updateGoal(@ModelAttribute GoalForm goalForm, HttpSession session) {
|
||||
|
||||
|
||||
@@ -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,11 +5,14 @@ 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.aop.aspect.SessionCheck;
|
||||
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.ProfileEditForm;
|
||||
import com.example.demo.app.presentation.form.ProfileForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -19,6 +22,7 @@ import lombok.RequiredArgsConstructor;
|
||||
public class ProfileController {
|
||||
private final ProfileService profileService;
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping("/profile")
|
||||
public String profile(Model model, HttpSession session) {
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||
@@ -31,11 +35,45 @@ public class ProfileController {
|
||||
return "profile";
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@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";
|
||||
}
|
||||
|
||||
@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")
|
||||
public String withdraw(HttpSession session) {
|
||||
|
||||
@@ -49,6 +87,7 @@ public class ProfileController {
|
||||
return "redirect:/login";
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/logout")
|
||||
public String logout(HttpSession session) {
|
||||
session.invalidate();
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import com.example.demo.aop.aspect.SessionCheck;
|
||||
import com.example.demo.app.domain.model.LoginModel;
|
||||
import com.example.demo.app.domain.service.CategoryService;
|
||||
import com.example.demo.app.domain.service.GoalService;
|
||||
@@ -41,44 +42,91 @@ public class TransactionController {
|
||||
private final UserService userService;
|
||||
|
||||
// 一覧画面
|
||||
@SessionCheck
|
||||
@GetMapping("/transaction/list")
|
||||
public String transactionList(@RequestParam(required = false) LocalDate startDates,
|
||||
@RequestParam(required = false) LocalDate endDates, Model model,
|
||||
public String transactionList(
|
||||
@RequestParam(required = false, defaultValue = "0") String years,
|
||||
@RequestParam(required = false, defaultValue = "0") String months,
|
||||
Model model,
|
||||
HttpSession session) {
|
||||
|
||||
LocalDate startDate = (startDates == null) ? LocalDate.now().withDayOfMonth(1) : startDates;
|
||||
|
||||
LocalDate endDate = (endDates == null) ? LocalDate.now().withDayOfMonth(LocalDate.now().lengthOfMonth())
|
||||
: endDates;
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
int year = years.equals("0")
|
||||
? today.getYear()
|
||||
: Integer.parseInt(years);
|
||||
|
||||
int month = months.equals("0")
|
||||
? today.getMonthValue()
|
||||
: Integer.parseInt(months);
|
||||
|
||||
YearMonth yearMonth = YearMonth.of(year, month);
|
||||
|
||||
YearMonth previousYearMonth = yearMonth.minusMonths(1);
|
||||
|
||||
int previousYear = previousYearMonth.getYear();
|
||||
int previousMonth = previousYearMonth.getMonthValue();
|
||||
|
||||
YearMonth nextYearMonth = yearMonth.plusMonths(1);
|
||||
|
||||
int nextYear = nextYearMonth.getYear();
|
||||
int nextMonth = nextYearMonth.getMonthValue();
|
||||
|
||||
LocalDate startDate = yearMonth.atDay(1);
|
||||
LocalDate endDate = yearMonth.atEndOfMonth();
|
||||
|
||||
Map<LocalDate, List<TransactionForm>> transactionFormMap = new HashMap<>();
|
||||
|
||||
transactionService.findAllByDate(startDate, endDate, loginUser.getUserId()).forEach((date, list) -> {
|
||||
List<TransactionForm> transactionFormList = list.stream().map(transaction -> {
|
||||
System.out.println(transaction.getTransactionDate());
|
||||
TransactionForm transactionForm = TransactionForm.convertFrom(
|
||||
transactionService
|
||||
.findAllByDate(
|
||||
startDate,
|
||||
endDate,
|
||||
loginUser.getUserId())
|
||||
.forEach((date, list) -> {
|
||||
|
||||
List<TransactionForm> transactionFormList = list.stream()
|
||||
.map(transaction -> {
|
||||
|
||||
CategoryForm categoryForm = CategoryForm.convertFrom(
|
||||
categoryService.findOne(
|
||||
transaction.getCategoryId()));
|
||||
|
||||
return TransactionForm.convertFrom(
|
||||
transaction,
|
||||
CategoryForm.convertFrom(categoryService.findOne(transaction.getCategoryId()))
|
||||
.getCategoryName(),
|
||||
transactionService.findTotalExpense(startDate, endDate, loginUser.getUserId()),
|
||||
transactionService.findTotalIncome(startDate, endDate, loginUser.getUserId()),
|
||||
CategoryForm.convertFrom(categoryService.findOne(transaction.getCategoryId()))
|
||||
.getTransactionType());
|
||||
System.out.println("startDate = " + startDate);
|
||||
System.out.println("endDate = " + endDate);
|
||||
return transactionForm;
|
||||
}).collect(Collectors.toList());
|
||||
categoryForm.getCategoryName(),
|
||||
transactionService.findTotalExpense(
|
||||
startDate,
|
||||
endDate,
|
||||
loginUser.getUserId()),
|
||||
transactionService.findTotalIncome(
|
||||
startDate,
|
||||
endDate,
|
||||
loginUser.getUserId()),
|
||||
categoryForm.getTransactionType());
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
transactionFormMap.put(date, transactionFormList);
|
||||
});
|
||||
|
||||
model.addAttribute("year", year);
|
||||
model.addAttribute("month", month);
|
||||
|
||||
model.addAttribute("previousYear", previousYear);
|
||||
model.addAttribute("previousMonth", previousMonth);
|
||||
|
||||
model.addAttribute("nextYear", nextYear);
|
||||
model.addAttribute("nextMonth", nextMonth);
|
||||
|
||||
model.addAttribute("transactionFormMap", transactionFormMap);
|
||||
|
||||
return "transaction_list";
|
||||
}
|
||||
|
||||
// 詳細画面
|
||||
@SessionCheck
|
||||
@GetMapping("/transaction/detail")
|
||||
public String findOne(@RequestParam(required = false) LocalDate todayDates, Model model, HttpSession session) {
|
||||
|
||||
@@ -131,6 +179,7 @@ public class TransactionController {
|
||||
return "transaction_detail";
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping("/transaction/create")
|
||||
public String createOneGet(@RequestParam(defaultValue = "") LocalDate today,
|
||||
Model model) {
|
||||
@@ -155,6 +204,7 @@ public class TransactionController {
|
||||
return "transaction_create";
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping("/transaction/create")
|
||||
public String createOnePost(@ModelAttribute TransactionForm transactionForm, @RequestParam LocalDate today,
|
||||
Model model,
|
||||
@@ -170,6 +220,7 @@ public class TransactionController {
|
||||
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping("/transaction/update")
|
||||
public String updateOneGet(@RequestParam Long transactionId, @RequestParam(defaultValue = "") LocalDate today,
|
||||
Model model) {
|
||||
@@ -189,7 +240,6 @@ public class TransactionController {
|
||||
|
||||
System.out.println("category: " + transactionForm.getCategoryId() + "金額: " + transactionForm.getAmount());
|
||||
|
||||
|
||||
model.addAttribute("transactionId", transactionId);
|
||||
|
||||
model.addAttribute("transactionForm", transactionForm);
|
||||
@@ -202,8 +252,10 @@ public class TransactionController {
|
||||
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping("/transaction/update")
|
||||
public String updateOnePost(@RequestParam Long transactionId, @ModelAttribute TransactionForm transactionForm, @RequestParam LocalDate today, Model model,
|
||||
public String updateOnePost(@RequestParam Long transactionId, @ModelAttribute TransactionForm transactionForm,
|
||||
@RequestParam LocalDate today, Model model,
|
||||
HttpSession session) {
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||
@@ -219,6 +271,7 @@ public class TransactionController {
|
||||
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping("/transaction/delete")
|
||||
public String deleteOne(@RequestParam Long transactionId, @RequestParam LocalDate today) {
|
||||
|
||||
@@ -226,6 +279,7 @@ public class TransactionController {
|
||||
return "redirect:/transaction/detail?todayDates=" + today;
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping("/menu")
|
||||
public String menu(HttpSession session, Model model,
|
||||
@RequestParam(required = false, defaultValue = "0") String years,
|
||||
@@ -255,7 +309,6 @@ public class TransactionController {
|
||||
int nextYear = nextYearMonth.getYear();
|
||||
int nextMonth = nextYearMonth.getMonthValue();
|
||||
|
||||
|
||||
model.addAttribute("year", year);
|
||||
model.addAttribute("month", month);
|
||||
model.addAttribute("day", today.getDayOfMonth());
|
||||
@@ -272,7 +325,6 @@ public class TransactionController {
|
||||
LocalDate startDate = yearMonth.atDay(1);
|
||||
LocalDate endDate = yearMonth.atEndOfMonth();
|
||||
|
||||
|
||||
List<Income> incomeList = transactionService.findTotalIncomeList(startDate, endDate, loginUser.getUserId());
|
||||
|
||||
List<Expense> expenseList = transactionService.findTotalExpenseList(startDate, endDate, loginUser.getUserId());
|
||||
@@ -280,33 +332,28 @@ public class TransactionController {
|
||||
model.addAttribute("incomeList", incomeList);
|
||||
model.addAttribute("expenseList", expenseList);
|
||||
|
||||
|
||||
int totalIncome = transactionService.findTotalIncome(startDate, endDate, loginUser.getUserId());
|
||||
|
||||
int totalExpense = transactionService.findTotalExpense(startDate, endDate, loginUser.getUserId());
|
||||
|
||||
|
||||
model.addAttribute("totalIncome", totalIncome);
|
||||
model.addAttribute("totalExpense", totalExpense);
|
||||
|
||||
|
||||
|
||||
GoalForm goalForm = GoalForm.convertFrom(goalService.getGoalByUserId(loginUser.getUserId()));
|
||||
|
||||
UserForm userForm = UserForm.convertFrom(userService.findByUserId(loginUser.getUserId()));
|
||||
|
||||
model.addAttribute("achievementRate", goalForm.getAchievementRate());
|
||||
|
||||
model.addAttribute("currentAmount", goalForm.getCurrentAmount());
|
||||
|
||||
model.addAttribute("targetAmount", goalForm.getTargetAmount());
|
||||
|
||||
model.addAttribute("saving", userForm.getSaving());
|
||||
|
||||
model.addAttribute("deadline", goalForm.getDeadline());
|
||||
|
||||
|
||||
|
||||
return "menu";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.example.demo.app.presentation.form.UserForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class UserController {
|
||||
|
||||
@@ -30,6 +30,8 @@ public class GoalForm {
|
||||
|
||||
private Integer achievementRate; // 達成率
|
||||
|
||||
private Integer currentAmount; // 現在の資産
|
||||
|
||||
public static GoalForm convertFrom(GoalModel goalModel) {
|
||||
return new GoalForm(
|
||||
goalModel.getGoalId(),
|
||||
@@ -38,7 +40,8 @@ public class GoalForm {
|
||||
goalModel.getTargetAmount(),
|
||||
goalModel.getDeadline(),
|
||||
goalModel.getGoalComplete(),
|
||||
goalModel.getAchievementRate());
|
||||
goalModel.getAchievementRate(),
|
||||
goalModel.getCurrentAmount());
|
||||
}
|
||||
|
||||
// public static List<GoalForm> convertFrom(List<GoalModel> goalModelList) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.example.demo.exception;
|
||||
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public String handleException(
|
||||
Exception e,
|
||||
Model model) {
|
||||
|
||||
model.addAttribute(
|
||||
"errorMessage",
|
||||
"システムエラーが発生しました。"
|
||||
+ "初めからやり直してください。");
|
||||
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.example.demo.exception;
|
||||
|
||||
public class InsufficientPermissionException extends RuntimeException {
|
||||
|
||||
public InsufficientPermissionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.example.demo.exception;
|
||||
|
||||
public class NoSessionException extends RuntimeException {
|
||||
|
||||
public NoSessionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,7 +22,7 @@ th {
|
||||
}
|
||||
|
||||
td {
|
||||
width: 14.28%;
|
||||
width: 14%;
|
||||
height: 70px;
|
||||
padding: 5px;
|
||||
text-align: left;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<title>分析画面</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body class="pb-5 pt-5">
|
||||
|
||||
<div th:replace="~{header :: header}">
|
||||
@@ -13,6 +14,23 @@
|
||||
<div class="container mt-4">
|
||||
<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">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
<h1>目標詳細</h1>
|
||||
|
||||
<table>
|
||||
|
||||
<tr>
|
||||
<th>目標名</th>
|
||||
<td th:text="${goalForm.goalTitle}"></td>
|
||||
|
||||
@@ -118,6 +118,13 @@
|
||||
<span th:text="${targetAmount}"></span>
|
||||
<span>円</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span>現在高</span>
|
||||
<span th:text="${currentAmount}"></span>
|
||||
<span>円</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span>貯金額</span>
|
||||
<span th:text="${saving}"></span>
|
||||
@@ -129,7 +136,7 @@
|
||||
<div>
|
||||
<span>達成率</span>
|
||||
<span th:text="${achievementRate}"></span>
|
||||
<span>円</span>
|
||||
<span>%</span>
|
||||
</div>
|
||||
<div>
|
||||
<span>達成期限</span>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<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>
|
||||
@@ -13,6 +13,33 @@
|
||||
|
||||
<div th:replace="~{header :: header}"></div>
|
||||
|
||||
<div class="calendar-title">
|
||||
|
||||
<a class="month-button" th:href="@{/transaction/list(
|
||||
years=${previousYear},
|
||||
months=${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="@{/transaction/list(
|
||||
years=${nextYear},
|
||||
months=${nextMonth}
|
||||
)}">
|
||||
→
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div th:each="transactionForm : ${transactionFormMap}">
|
||||
|
||||
<a th:href="@{/transaction/detail(todayDates=${transactionForm.key})}">
|
||||
|
||||
Reference in New Issue
Block a user