3 Commits

Author SHA1 Message Date
aa470cbcce Merge branch 'k-kobayashi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-oshita
# Conflicts:
#	src/main/java/com/example/demo/app/presentation/controller/TransactionController.java
#	src/main/java/com/example/demo/app/presentation/controller/UserController.java
2026-09-25 15:00:19 +09:00
kkazuya
ff21efa943 [EDIT] 全コントローラに定数を反映させました。 2026-09-25 14:59:27 +09:00
kkazuya
a0ef7145d2 [FIX] 定数クラスの誤字を修正しました。 2026-09-25 14:58:09 +09:00
12 changed files with 231 additions and 177 deletions

View File

@@ -13,6 +13,9 @@ 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;
import com.example.demo.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.demo.app.presentation.controller.pageproperty.SessionKeyword;
import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.demo.app.presentation.form.AnalysisForm;
import lombok.RequiredArgsConstructor;
@@ -25,7 +28,7 @@ public class AnalysisController {
private final AnalysisService analysisService;
@SessionCheck
@GetMapping("/analysis")
@GetMapping(TransitionTargetPageNameKeyword.ANALYSIS)
public String showAnalysis(
@RequestParam(required = false) Integer year,
@RequestParam(required = false) Integer month,
@@ -33,7 +36,7 @@ public class AnalysisController {
HttpSession session) {
//ログインユーザーの取得(セッション)
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
//初期年月表示
LocalDate nowDate = LocalDate.now();
@@ -58,15 +61,15 @@ public class AnalysisController {
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());
model.addAttribute(PageReturnAttributeKeyword.ANALYSIS_FORM, analysisForm);
model.addAttribute(PageReturnAttributeKeyword.YEAR, year);
model.addAttribute(PageReturnAttributeKeyword.MONTH, month);
model.addAttribute(PageReturnAttributeKeyword.PREVIOUS_YEAR, previousDate.getYear());
model.addAttribute(PageReturnAttributeKeyword.PREVIOUS_MONTH, previousDate.getMonthValue());
model.addAttribute(PageReturnAttributeKeyword.NEXT_YEAR, nextDate.getYear());
model.addAttribute(PageReturnAttributeKeyword.NEXT_MONTH, nextDate.getMonthValue());
return "analysis";
return TransitionTargetPageNameKeyword.ANALYSIS_HTML;
}
}

View File

@@ -10,6 +10,8 @@ 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.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.demo.app.presentation.form.AuthenticationForm;
import com.example.demo.app.presentation.form.PasswordResetForm;
@@ -22,16 +24,16 @@ public class AuthenticationController {
private final AuthenticationService authenticationService;
private final QuestionRepository questionRepository;
@GetMapping("/authentication")
@GetMapping(TransitionTargetPageNameKeyword.AUTHENTICATION)
public String showAuthentication(Model model) {
model.addAttribute("authenticationForm", new AuthenticationForm());
model.addAttribute("questionList", questionRepository.findAll());
model.addAttribute(PageReturnAttributeKeyword.AUTHENTICATION_FORM, new AuthenticationForm());
model.addAttribute(PageReturnAttributeKeyword.QUESTION_LIST, questionRepository.findAll());
return "authentication";
return TransitionTargetPageNameKeyword.AUTHENTICATION_HTML;
}
@PostMapping("/authentication")
@PostMapping(TransitionTargetPageNameKeyword.AUTHENTICATION)
public String authenticate(
AuthenticationForm authenticationForm,
Model model,
@@ -41,21 +43,21 @@ public class AuthenticationController {
authenticationService.authenticate(authenticationForm);
if (authenticationModel == null) {
model.addAttribute("errorMessage", "認証情報が正しくありません。");
model.addAttribute("questionList", questionRepository.findAll());
model.addAttribute(PageReturnAttributeKeyword.ERROR_MESSAGE, "認証情報が正しくありません。");
model.addAttribute(PageReturnAttributeKeyword.QUESTION_LIST, questionRepository.findAll());
return "authentication";
return TransitionTargetPageNameKeyword.AUTHENTICATION_HTML;
}
session.setAttribute(
"passwordResetUserId",
PageReturnAttributeKeyword.PASSWOR_RESET_USER_ID,
authenticationModel.getUserId());
model.addAttribute(
"passwordResetForm",
PageReturnAttributeKeyword.PASSWOR_RESET_FORM,
new PasswordResetForm());
return "password_reset";
return TransitionTargetPageNameKeyword.PASSWORD_RESET_HTML;
}
}

View File

@@ -14,6 +14,9 @@ import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.service.CourseInfoService;
import com.example.demo.app.domain.service.CourseService;
import com.example.demo.app.domain.service.UserService;
import com.example.demo.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.demo.app.presentation.controller.pageproperty.SessionKeyword;
import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.demo.app.presentation.form.CourseForm;
import com.example.demo.app.presentation.form.CourseInfoForm;
import com.example.demo.app.presentation.form.UserForm;
@@ -30,51 +33,53 @@ public class CourseController {
private final UserService userService;
@PostMapping("/user/register/course")
@PostMapping(TransitionTargetPageNameKeyword.SHOW_SELECT_COURSE)
public String showSelectCourse(@ModelAttribute UserForm userForm, Model model, HttpSession session) {
final String MODE = "regist";
final String DEFAULT = "バランスコース";
session.setAttribute("userForm", userForm);
model.addAttribute("mode", "regist");
model.addAttribute("currentCourseId", courseService.findByName("バランスコース"));
model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll()));
model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll()));
session.setAttribute(PageReturnAttributeKeyword.USER_FORM, userForm);
model.addAttribute(PageReturnAttributeKeyword.MODE, MODE);
model.addAttribute(PageReturnAttributeKeyword.CURRENT_COURSE_ID, courseService.findByName(DEFAULT));
model.addAttribute(PageReturnAttributeKeyword.COURSE_LIST, CourseForm.convertFrom(courseService.findAll()));
model.addAttribute(PageReturnAttributeKeyword.COURSE_INFO_LIST, CourseInfoForm.convertFrom(courseInfoService.findAll()));
return "select_course";
return TransitionTargetPageNameKeyword.SELECT_COURSE_HTML;
}
@SessionCheck
@GetMapping("/course")
@GetMapping(TransitionTargetPageNameKeyword.COURSE)
public String showChangeCourse(Model model, HttpSession session) {
final String MODE = "change";
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
Long userId = loginUser.getUserId();
Long currentCourseId = userService.findByUserId(userId).getCourseId();
model.addAttribute("mode", "change");
model.addAttribute("currentCourseId", currentCourseId);
model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll()));
model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll()));
model.addAttribute(PageReturnAttributeKeyword.MODE, MODE);
model.addAttribute(PageReturnAttributeKeyword.CURRENT_COURSE_ID, currentCourseId);
model.addAttribute(PageReturnAttributeKeyword.COURSE_LIST, CourseForm.convertFrom(courseService.findAll()));
model.addAttribute(PageReturnAttributeKeyword.COURSE_INFO_LIST, CourseInfoForm.convertFrom(courseInfoService.findAll()));
return "select_course";
return TransitionTargetPageNameKeyword.SELECT_COURSE_HTML;
}
@SessionCheck
@PostMapping("/change")
@PostMapping(TransitionTargetPageNameKeyword.CHANGE)
public String changeCourse(@RequestParam Long courseId, HttpSession httpSession) {
LoginModel loginUser = (LoginModel) httpSession.getAttribute("loginUser");
LoginModel loginUser = (LoginModel) httpSession.getAttribute(SessionKeyword.LOGIN_USER);
userService.updateCourse(loginUser.getUserId(), courseId);
return "redirect:/menu";
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.MENU;
}

View File

@@ -3,10 +3,12 @@ package com.example.demo.app.presentation.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
@Controller
public class ErrorController {
@GetMapping("/error")
@GetMapping(TransitionTargetPageNameKeyword.ERROR)
public String showError() {
return "error";
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
}

View File

@@ -13,13 +13,16 @@ 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;
import com.example.demo.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.demo.app.presentation.controller.pageproperty.SessionKeyword;
import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.demo.app.presentation.form.GoalForm;
import lombok.RequiredArgsConstructor;
@Controller
@RequiredArgsConstructor
@RequestMapping("/goal")
@RequestMapping(TransitionTargetPageNameKeyword.GOAL)
public class GoalController {
private final GoalService goalService;
@@ -28,36 +31,36 @@ public class GoalController {
@GetMapping("")
public String getGoal(Model model, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
Long userId = loginUser.getUserId();
GoalModel goalModel = goalService.getGoalByUserId(userId);
GoalForm goalForm = GoalForm.convertFrom(goalModel);
model.addAttribute("goalForm", goalForm);
return "goal_view";
model.addAttribute(PageReturnAttributeKeyword.GOAL_FORM, goalForm);
return TransitionTargetPageNameKeyword.GOAL_VIEW_HTML;
}
@SessionCheck
@GetMapping("/edit")
@GetMapping(TransitionTargetPageNameKeyword.EDIT)
public String editGoal(Model model, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
Long userId = loginUser.getUserId();
GoalModel goalModel = goalService.getGoalByUserId(userId);
GoalForm goalForm = GoalForm.convertFrom(goalModel);
model.addAttribute("goalForm", goalForm);
return "goal_edit";
model.addAttribute(PageReturnAttributeKeyword.GOAL_FORM, goalForm);
return TransitionTargetPageNameKeyword.GOAL_EDIT_HTML;
}
@SessionCheck
@PostMapping("/update")
@PostMapping(TransitionTargetPageNameKeyword.UPDATE)
public String updateGoal(@ModelAttribute GoalForm goalForm, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
Long userId = loginUser.getUserId();
@@ -65,13 +68,13 @@ public class GoalController {
GoalModel currentGoal = goalService.getGoalByUserId(userId);
if (!currentGoal.getGoalId().equals(goalForm.getGoalId())) {
return "redirect:/goal"; // 他人のデータを更新しようとしたら弾く
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.GOAL; // 他人のデータを更新しようとしたら弾く
}
GoalModel goalModel = GoalModel.convertFrom(goalForm);
goalService.updateGoal(goalModel, userId);
return "redirect:/goal";
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.GOAL;
}
}

View File

@@ -10,6 +10,9 @@ import org.springframework.web.bind.annotation.PostMapping;
import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.service.LoginService;
import com.example.demo.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.demo.app.presentation.controller.pageproperty.SessionKeyword;
import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.demo.app.presentation.form.LoginForm;
import lombok.RequiredArgsConstructor;
@@ -20,13 +23,13 @@ public class LoginController {
private final LoginService loginService;
@GetMapping("/login")
@GetMapping(TransitionTargetPageNameKeyword.LOGIN)
public String showLogin(@ModelAttribute LoginForm loginForm) {
return "login";
return TransitionTargetPageNameKeyword.LOGIN_HTML;
}
@PostMapping("/login")
@PostMapping(TransitionTargetPageNameKeyword.LOGIN)
public String login(
@ModelAttribute LoginForm loginForm,
Model model,
@@ -38,15 +41,15 @@ public class LoginController {
if (loginModel == null) {
model.addAttribute(
"errorMessage",
"Email address or password is incorrect.");
PageReturnAttributeKeyword.ERROR_MESSAGE,
"IDまたはパスワードが間違っています.");
return "login";
return TransitionTargetPageNameKeyword.LOGIN_HTML;
}
session.setAttribute("loginUser", loginModel);
session.setAttribute(SessionKeyword.LOGIN_USER, loginModel);
return "redirect:/menu";
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.MENU;
}
}

View File

@@ -9,6 +9,9 @@ import org.springframework.web.bind.annotation.PostMapping;
import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.service.PasswordResetService;
import com.example.demo.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.demo.app.presentation.controller.pageproperty.SessionKeyword;
import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.demo.app.presentation.form.PasswordResetForm;
import lombok.RequiredArgsConstructor;
@@ -18,24 +21,24 @@ import lombok.RequiredArgsConstructor;
public class PasswordResetController {
private final PasswordResetService passwordResetService;
@GetMapping("/password/reset")
@GetMapping(TransitionTargetPageNameKeyword.PASSWORD_RESET)
public String showPasswordReset(Model model) {
model.addAttribute("passwordResetForm", new PasswordResetForm());
return "password_reset";
model.addAttribute(PageReturnAttributeKeyword.PASSWOR_RESET_FORM, new PasswordResetForm());
return TransitionTargetPageNameKeyword.PASSWORD_RESET_HTML;
}
@PostMapping("/password/reset")
@PostMapping(TransitionTargetPageNameKeyword.PASSWORD_RESET)
public String resetPassword(
PasswordResetForm passwordResetForm,
Model model,
HttpSession session){
Long userId =
(Long) session.getAttribute("passwordResetUserId");
(Long) session.getAttribute(PageReturnAttributeKeyword.PASSWOR_RESET_USER_ID);
if (userId == null) {
LoginModel loginUser =
(LoginModel) session.getAttribute("loginUser");
(LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
if (loginUser != null) {
userId = loginUser.getUserId();
@@ -43,28 +46,29 @@ public class PasswordResetController {
}
if (userId == null) {
return "redirect:/login";
return TransitionTargetPageNameKeyword.REDIRECT +
TransitionTargetPageNameKeyword.LOGIN;
}
boolean isReset =
passwordResetService.resetPassword(userId, passwordResetForm);
System.out.println("isReset=" + isReset);
if(!isReset) {
model.addAttribute("message", "パスワードが一致しません。");
return "password_reset";
model.addAttribute(PageReturnAttributeKeyword.MESSAGE, "パスワードが一致しません。");
return TransitionTargetPageNameKeyword.PASSWORD_RESET_HTML;
}
session.removeAttribute("passwordResetUserId");
session.removeAttribute(PageReturnAttributeKeyword.PASSWOR_RESET_USER_ID);
LoginModel loginUser =
(LoginModel) session.getAttribute("loginUser");
(LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
if (loginUser != null) {
return "redirect:/menu";
return TransitionTargetPageNameKeyword.REDIRECT +
TransitionTargetPageNameKeyword.MENU;
}
return "redirect:/login";
return TransitionTargetPageNameKeyword.REDIRECT +
TransitionTargetPageNameKeyword.LOGIN;
}
}

View File

@@ -12,6 +12,9 @@ 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.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.demo.app.presentation.controller.pageproperty.SessionKeyword;
import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.demo.app.presentation.form.ProfileEditForm;
import com.example.demo.app.presentation.form.ProfileForm;
@@ -23,26 +26,26 @@ public class ProfileController {
private final ProfileService profileService;
@SessionCheck
@GetMapping("/profile")
@GetMapping(TransitionTargetPageNameKeyword.PROFILE)
public String profile(Model model, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
ProfileModel profileModel = profileService.findOne(loginUser.getUserId());
ProfileForm profileForm = ProfileForm.convertForm(profileModel);
model.addAttribute("profileForm", profileForm);
return "profile";
model.addAttribute(PageReturnAttributeKeyword.PROFILE_FORM, profileForm);
return TransitionTargetPageNameKeyword.PROFILE_HTML;
}
@SessionCheck
@GetMapping("/profile/edit")
@GetMapping(TransitionTargetPageNameKeyword.PROFILE_EDIT)
public String showEditProfile(
Model model,
HttpSession session) {
LoginModel loginUser =
(LoginModel) session.getAttribute("loginUser");
(LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
ProfileModel profileModel =
profileService.findOne(loginUser.getUserId());
@@ -55,42 +58,42 @@ public class ProfileController {
profileModel.getAnnualIncome(),
profileModel.getMonthlyBudget());
model.addAttribute("profileEditForm", profileEditForm);
return "profile_edit";
model.addAttribute(PageReturnAttributeKeyword.PROFILE_EDIT_FORM, profileEditForm);
return TransitionTargetPageNameKeyword.PROFILE_EDIT_HTML;
}
@PostMapping("/profile/edit")
@PostMapping(TransitionTargetPageNameKeyword.PROFILE_EDIT)
public String updateProfile(
@ModelAttribute ProfileEditForm profileEditForm,
HttpSession session) {
LoginModel loginUser =
(LoginModel) session.getAttribute("loginUser");
(LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
profileService.update(
loginUser.getUserId(),
profileEditForm);
return "redirect:/profile";
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.PROFILE;
}
@PostMapping("/withdraw")
@PostMapping(TransitionTargetPageNameKeyword.WITHDRAW)
public String withdraw(HttpSession session) {
LoginModel loginUser =
(LoginModel) session.getAttribute("loginUser");
(LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
profileService.withdraw(loginUser.getUserId());
session.invalidate();
return "redirect:/login";
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.LOGIN;
}
@PostMapping("/logout")
@PostMapping(TransitionTargetPageNameKeyword.LOGOUT)
public String logout(HttpSession session) {
session.invalidate();
return "redirect:/login";
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.LOGIN;
}
}

View File

@@ -24,6 +24,9 @@ import com.example.demo.app.domain.service.FixedCostService;
import com.example.demo.app.domain.service.GoalService;
import com.example.demo.app.domain.service.TransactionService;
import com.example.demo.app.domain.service.UserService;
import com.example.demo.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.demo.app.presentation.controller.pageproperty.SessionKeyword;
import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.demo.app.presentation.form.CategoryForm;
import com.example.demo.app.presentation.form.Expense;
import com.example.demo.app.presentation.form.FixedCostForm;
@@ -45,14 +48,14 @@ public class TransactionController {
// 一覧画面
@SessionCheck
@GetMapping("/transaction/list")
@GetMapping(TransitionTargetPageNameKeyword.TRANSACTION_LIST)
public String transactionList(
@RequestParam(required = false, defaultValue = "0") String years,
@RequestParam(required = false, defaultValue = "0") String months,
Model model,
HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
LocalDate today = LocalDate.now();
@@ -113,28 +116,28 @@ public class TransactionController {
transactionFormMap.put(date, transactionFormList);
});
model.addAttribute("year", year);
model.addAttribute("month", month);
model.addAttribute(PageReturnAttributeKeyword.YEAR, year);
model.addAttribute(PageReturnAttributeKeyword.MONTH, month);
model.addAttribute("previousYear", previousYear);
model.addAttribute("previousMonth", previousMonth);
model.addAttribute(PageReturnAttributeKeyword.PREVIOUS_YEAR, previousYear);
model.addAttribute(PageReturnAttributeKeyword.PREVIOUS_MONTH, previousMonth);
model.addAttribute("nextYear", nextYear);
model.addAttribute("nextMonth", nextMonth);
model.addAttribute(PageReturnAttributeKeyword.NEXT_YEAR, nextYear);
model.addAttribute(PageReturnAttributeKeyword.NEXT_MONTH, nextMonth);
model.addAttribute("transactionFormMap", transactionFormMap);
model.addAttribute(PageReturnAttributeKeyword.TRANSACTION_FORM_MAP, transactionFormMap);
return "transaction_list";
return TransitionTargetPageNameKeyword.TRANSACTION_LIST_HTML;
}
// 詳細画面
@SessionCheck
@GetMapping("/transaction/detail")
@GetMapping(TransitionTargetPageNameKeyword.TRANSACTION_DETAIL)
public String findOne(@RequestParam(required = false) LocalDate todayDates, Model model, HttpSession session) {
LocalDate todayDate = (todayDates == null) ? LocalDate.now() : todayDates;
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
List<TransactionForm> transactionFormList = transactionService
.findByUserIdAndDate(todayDate, loginUser.getUserId()).stream()
@@ -175,14 +178,14 @@ public class TransactionController {
return transactionForm;
}).collect(Collectors.toList());
model.addAttribute("today", todayDate);
model.addAttribute("transactionFormList", transactionFormList);
model.addAttribute(PageReturnAttributeKeyword.TODAY, todayDate);
model.addAttribute(PageReturnAttributeKeyword.TRANSACTION_FORM_LIST, transactionFormList);
return "transaction_detail";
return TransitionTargetPageNameKeyword.TRANSACTION_DETAIL_HTML;
}
@SessionCheck
@GetMapping("/transaction/create")
@GetMapping(TransitionTargetPageNameKeyword.TRANSACTION_CREATE)
public String createOneGet(@RequestParam(defaultValue = "") LocalDate today,
Long fixedCostId,
Model model) {
@@ -202,35 +205,38 @@ public class TransactionController {
List<CategoryForm> categoryFormList = CategoryForm.convertFrom(categoryService.findAll());
System.out.println(transactionForm.getCategoryName() + " " + transactionForm.getAmount());
model.addAttribute(PageReturnAttributeKeyword.TRANSACTION_FORM, transactionForm);
model.addAttribute("transactionForm", transactionForm);
model.addAttribute(PageReturnAttributeKeyword.CATEGORY_FORM_LIST, categoryFormList);
model.addAttribute("categoryFormList", categoryFormList);
model.addAttribute(PageReturnAttributeKeyword.TODAY, today.format(DateTimeFormatter.ISO_LOCAL_DATE));
model.addAttribute("today", today.format(DateTimeFormatter.ISO_LOCAL_DATE));
return "transaction_create";
return TransitionTargetPageNameKeyword.TRANSACTION_CREATE_HTML;
}
@SessionCheck
@PostMapping("/transaction/create")
@PostMapping(TransitionTargetPageNameKeyword.TRANSACTION_CREATE)
public String createOnePost(@ModelAttribute TransactionForm transactionForm, @RequestParam LocalDate today,
Model model,
HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
transactionForm.setUserId(loginUser.getUserId());
if (transactionService.createTransaction(TransactionForm.convertTo(transactionForm)) != 0) {
return "error";
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
return "redirect:/transaction/detail?todayDates=" + transactionForm.getTransactionDate();
return TransitionTargetPageNameKeyword.REDIRECT +
TransitionTargetPageNameKeyword.TRANSACTION_DETAIL +
TransitionTargetPageNameKeyword.INTERROGATION +
TransitionTargetPageNameKeyword.TODAY_DATES +
TransitionTargetPageNameKeyword.EQUAL +
transactionForm.getTransactionDate();
}
@SessionCheck
@GetMapping("/transaction/update")
@GetMapping(TransitionTargetPageNameKeyword.TRANSACTION_UPDATE)
public String updateOneGet(@RequestParam Long transactionId, @RequestParam(defaultValue = "") LocalDate today,
Model model) {
@@ -247,22 +253,20 @@ public class TransactionController {
transactionService.findMoneyRecord(transactionId),
CategoryForm.convertFrom(categoryService.findByTransactionId(transactionId)).getTransactionType());
System.out.println("category: " + transactionForm.getCategoryId() + "金額: " + transactionForm.getAmount());
model.addAttribute(PageReturnAttributeKeyword.TRANSACTION_ID, transactionId);
model.addAttribute("transactionId", transactionId);
model.addAttribute(PageReturnAttributeKeyword.TRANSACTION_FORM, transactionForm);
model.addAttribute("transactionForm", transactionForm);
model.addAttribute(PageReturnAttributeKeyword.CATEGORY_FORM_LIST, categoryFormList);
model.addAttribute("categoryFormList", categoryFormList);
model.addAttribute(PageReturnAttributeKeyword.TODAY, today);
model.addAttribute("today", today);
return "transaction_update";
return TransitionTargetPageNameKeyword.TRANSACTION_UPDATE_HTML;
}
@SessionCheck
@PostMapping("/transaction/update")
@PostMapping(TransitionTargetPageNameKeyword.TRANSACTION_UPDATE)
public String updateOnePost(@RequestParam Long transactionId, @ModelAttribute TransactionForm transactionForm,
@RequestParam LocalDate today, Model model,
HttpSession session) {
@@ -273,28 +277,38 @@ public class TransactionController {
transactionForm.setTransactionId(transactionId);
if (transactionService.updateTransaction(TransactionForm.convertTo(transactionForm)) != 0) {
return "error";
return TransitionTargetPageNameKeyword.ERROR_HTML;
}
return "redirect:/transaction/detail?todayDates=" + transactionForm.getTransactionDate();
return TransitionTargetPageNameKeyword.REDIRECT +
TransitionTargetPageNameKeyword.TRANSACTION_DETAIL +
TransitionTargetPageNameKeyword.INTERROGATION +
TransitionTargetPageNameKeyword.TODAY_DATES +
TransitionTargetPageNameKeyword.EQUAL +
transactionForm.getTransactionDate();
}
@SessionCheck
@PostMapping("/transaction/delete")
@PostMapping(TransitionTargetPageNameKeyword.TRANSACTION_DELETE)
public String deleteOne(@RequestParam Long transactionId, @RequestParam LocalDate today) {
transactionService.deleteTransaction(transactionId);
return "redirect:/transaction/detail?todayDates=" + today;
return TransitionTargetPageNameKeyword.REDIRECT +
TransitionTargetPageNameKeyword.TRANSACTION_DETAIL +
TransitionTargetPageNameKeyword.INTERROGATION +
TransitionTargetPageNameKeyword.TODAY_DATES +
TransitionTargetPageNameKeyword.EQUAL +
today;
}
@SessionCheck
@GetMapping("/menu")
@GetMapping(TransitionTargetPageNameKeyword.MENU)
public String menu(HttpSession session, Model model,
@RequestParam(required = false, defaultValue = "0") String years,
@RequestParam(required = false, defaultValue = "0") String months) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
LocalDate today = LocalDate.now();
@@ -318,18 +332,18 @@ public class TransactionController {
int nextYear = nextYearMonth.getYear();
int nextMonth = nextYearMonth.getMonthValue();
model.addAttribute("year", year);
model.addAttribute("month", month);
model.addAttribute("day", today.getDayOfMonth());
model.addAttribute(PageReturnAttributeKeyword.YEAR, year);
model.addAttribute(PageReturnAttributeKeyword.MONTH, month);
model.addAttribute(PageReturnAttributeKeyword.DAY, today.getDayOfMonth());
model.addAttribute("lastDay", lastDay);
model.addAttribute("firstDayOfWeek", firstDayOfWeek);
model.addAttribute(PageReturnAttributeKeyword.LAST_DAY, lastDay);
model.addAttribute(PageReturnAttributeKeyword.FIRST_DAY_OF_WEEK, firstDayOfWeek);
model.addAttribute("previousYear", previousYear);
model.addAttribute("previousMonth", previousMonth);
model.addAttribute(PageReturnAttributeKeyword.PREVIOUS_YEAR, previousYear);
model.addAttribute(PageReturnAttributeKeyword.PREVIOUS_MONTH, previousMonth);
model.addAttribute("nextYear", nextYear);
model.addAttribute("nextMonth", nextMonth);
model.addAttribute(PageReturnAttributeKeyword.NEXT_YEAR, nextYear);
model.addAttribute(PageReturnAttributeKeyword.NEXT_MONTH, nextMonth);
LocalDate startDate = yearMonth.atDay(1);
LocalDate endDate = yearMonth.atEndOfMonth();
@@ -338,31 +352,43 @@ public class TransactionController {
List<Expense> expenseList = transactionService.findTotalExpenseList(startDate, endDate, loginUser.getUserId());
model.addAttribute("incomeList", incomeList);
model.addAttribute("expenseList", expenseList);
model.addAttribute(PageReturnAttributeKeyword.INCOME_LIST, incomeList);
model.addAttribute(PageReturnAttributeKeyword.EXPENSE_LIST, 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);
model.addAttribute(PageReturnAttributeKeyword.TOTAL_INCOME, totalIncome);
model.addAttribute(PageReturnAttributeKeyword.TOTAL_EXPENSE, totalExpense);
// List<GoalForm> goalForm = GoalForm.convertFrom(goalService.getGoalByUserId(loginUser.getUserId()));
UserForm userForm = UserForm.convertFrom(userService.findByUserId(loginUser.getUserId()));
<<<<<<< HEAD
// model.addAttribute("achievementRate", goalForm.getAchievementRate());
//
// model.addAttribute("currentAmount", goalForm.getCurrentAmount());
//
// model.addAttribute("targetAmount", goalForm.getTargetAmount());
=======
model.addAttribute(PageReturnAttributeKeyword.ACHIEVEMENT_RATE, goalForm.getAchievementRate());
model.addAttribute(PageReturnAttributeKeyword.CURRENT_AMOUNT, goalForm.getCurrentAmount());
model.addAttribute("saving", userForm.getSaving());
model.addAttribute(PageReturnAttributeKeyword.TARGET_AMOUNT, goalForm.getTargetAmount());
>>>>>>> ff21efa943799a8b9b43d58660dbaf6fce2953f0
model.addAttribute(PageReturnAttributeKeyword.SAVING, userForm.getSaving());
<<<<<<< HEAD
// model.addAttribute("deadline", goalForm.getDeadline());
=======
model.addAttribute(PageReturnAttributeKeyword.DEADLINE, goalForm.getDeadline());
>>>>>>> ff21efa943799a8b9b43d58660dbaf6fce2953f0
return "menu";
return TransitionTargetPageNameKeyword.MENU_HTML;
}
}

View File

@@ -16,6 +16,8 @@ import com.example.demo.app.domain.service.CourseService;
import com.example.demo.app.domain.service.QuestionService;
import com.example.demo.app.domain.service.UserService;
import com.example.demo.app.infra.entity.QuestionEntity;
import com.example.demo.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
import com.example.demo.app.presentation.form.UserForm;
import lombok.RequiredArgsConstructor;
@@ -31,66 +33,66 @@ public class UserController {
private final QuestionService questionService;
@GetMapping("/user/register")
@GetMapping(TransitionTargetPageNameKeyword.USER_RESISTER)
public String showRegister(Model model, HttpSession session) {
UserForm userForm = new UserForm();
List<QuestionEntity> questionList = questionService.findAll();
session.setAttribute("questionList", questionList);
session.setAttribute(PageReturnAttributeKeyword.QUESTION_LIST, questionList);
model.addAttribute("userForm", userForm);
return "user_register";
model.addAttribute(PageReturnAttributeKeyword.USER_FORM, userForm);
return TransitionTargetPageNameKeyword.USER_RESISTER_HTML;
}
@PostMapping("/user/register/return")
@PostMapping(TransitionTargetPageNameKeyword.USER_RESISTER_RETURN)
public String showRegisterReturn(@RequestParam(required = false) Long courseId, Model model, HttpSession session) {
UserForm userForm = (UserForm) session.getAttribute("userForm");
System.out.println(
"######################################################################3" + userForm.getBirthDate());
UserForm userForm = (UserForm) session.getAttribute(PageReturnAttributeKeyword.USER_FORM);
if (userForm.getUserName().equals("")) {
userForm = new UserForm();
userForm.setCourseId(courseId);
}
if (courseId != null) {
model.addAttribute("selectedCourseName", courseService.findById(courseId).getCourseName());
model.addAttribute(PageReturnAttributeKeyword.SELECTED_COURSE_NAME, courseService.findById(courseId).getCourseName());
}
session.setAttribute("selectedCourseName", courseService.findById(courseId).getCourseName());
model.addAttribute("courseId", courseId);
System.out.println(
"######################################################################3" + userForm.getBirthDate());
model.addAttribute("userForm", userForm);
session.setAttribute(PageReturnAttributeKeyword.SELECTED_COURSE_NAME, courseService.findById(courseId).getCourseName());
model.addAttribute(PageReturnAttributeKeyword.COURESE_ID, courseId);
model.addAttribute(PageReturnAttributeKeyword.USER_FORM, userForm);
return "user_register_return";
return TransitionTargetPageNameKeyword.USER_RESISTER_RETURN_HTML;
}
@GetMapping("/user/register/confirm")
@GetMapping(TransitionTargetPageNameKeyword.USER_RESISTER_CONFIRM)
public String confirmRegisterGet(@ModelAttribute UserForm userForm,
String selectedCourseName, Model model,
HttpSession session) {
model.addAttribute("selectedCourseName", (String) session.getAttribute("selectedCourseName"));
return "user_register_confirm";
model.addAttribute(PageReturnAttributeKeyword.SELECTED_COURSE_NAME, (String) session.getAttribute("selectedCourseName"));
return TransitionTargetPageNameKeyword.USER_RESISTER_CONFIRM_HTML;
}
@PostMapping("/user/register/complete")
@PostMapping(TransitionTargetPageNameKeyword.USER_RESISTER_COMPLETE)
public String confirmRegister(
@ModelAttribute UserForm userForm,
Model model,
HttpSession session) {
<<<<<<< HEAD
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
Long courseId = courseService.findByName((String) session.getAttribute("selectedCourseName"));
=======
Long courseId = courseService.findByName((String) session.getAttribute(PageReturnAttributeKeyword.SELECTED_COURSE_NAME));
>>>>>>> ff21efa943799a8b9b43d58660dbaf6fce2953f0
userService.register(userForm, courseId, loginUser.getUserId());
return "redirect:/login";
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.LOGIN;
}

View File

@@ -14,7 +14,7 @@ public class PageReturnAttributeKeyword {
public static final String PASSWOR_RESET_FORM = "passwordResetForm";
public static final String PASSWOR_RESET_USER_ID = "passwordResetUserId";
public static final String AUTENTICATION_FORM = "authenticationForm";
public static final String AUTHENTICATION_FORM = "authenticationForm";
public static final String PROFILE_FORM = "profileForm";
public static final String PROFILE_EDIT_FORM = "profileEditForm";

View File

@@ -5,13 +5,13 @@ public class TransitionTargetPageNameKeyword {
// HTML
public static final String ERROR_HTML = "error";
public static final String USER_RESISTER_HTML = "user_resiter";
public static final String USER_RESISTER_RETURN_HTML = "user_resiter_return";
public static final String USER_RESISTER_CONFIRM_HTML = "user_resiter_confirm";
public static final String USER_RESISTER_HTML = "user_register";
public static final String USER_RESISTER_RETURN_HTML = "user_register_return";
public static final String USER_RESISTER_CONFIRM_HTML = "user_register_confirm";
public static final String LOGIN_HTML = "login";
public static final String PASSWORD_RESET_HTML = "passsword_reset";
public static final String PASSWORD_RESET_HTML = "password_reset";
public static final String AUTHENTICATION_HTML = "authentication";
@@ -47,7 +47,7 @@ public class TransitionTargetPageNameKeyword {
public static final String AUTHENTICATION = "/authentication";
public static final String PASSWORD_RESET = "/passsword/reset";
public static final String PASSWORD_RESET = "/password/reset";
public static final String MENU = "/menu";
@@ -65,12 +65,13 @@ public class TransitionTargetPageNameKeyword {
public static final String TRANSACTION_DETAIL = "/transaction/detail";
public static final String TRANSACTION_CREATE = "/transaction/create";
public static final String TRANSACTION_UPDATE = "/transaction/update";
public static final String TRANSACTION_DELETE = "/transaction/delete";
public static final String TODAY_DATES = "todayDates";
public static final String ANALYSIS = "/analysis";
public static final String GOAL = "/goal";
public static final String GOAL_EDIT = "/goal/edit";
public static final String GOAL_UPDATE = "/goal/update";
public static final String EDIT = "/edit";
public static final String UPDATE = "/update";
}