Compare commits
27 Commits
0f800da9a3
...
s-morimto
| Author | SHA1 | Date | |
|---|---|---|---|
| acd7534fdb | |||
|
|
add6a85c64 | ||
|
|
fd74dee965 | ||
|
|
7aa8e31bfd | ||
|
|
e3af89a694 | ||
|
|
efdaacbb27 | ||
| 154e6787d4 | |||
| 75f2f7c8d0 | |||
| ac101172d2 | |||
| ee5ec5009d | |||
|
|
d7a0aac355 | ||
|
|
a45045d008 | ||
|
|
17074c3132 | ||
| 7604e9ee76 | |||
|
|
34172aecc9 | ||
|
|
e5af64b53b | ||
|
|
b76be8f38a | ||
|
|
47185d8f26 | ||
|
|
546206317d | ||
| 26fa2365e8 | |||
| 5adb527d7a | |||
| e54e0133f7 | |||
| c3dae348bf | |||
| ea1e18ad93 | |||
| bb3b8965b2 | |||
| 3b239d07bd | |||
| 0c54a42b97 |
@@ -4,6 +4,8 @@ package com.example.demo.aop.handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
||||
@@ -37,7 +39,7 @@ public class GlobalExceptionHandler {
|
||||
}
|
||||
|
||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
||||
public String handleBadRequestException(Model model, Exception e) {
|
||||
public String handleBadRequestException(Model model, Exception e, HttpSession session) {
|
||||
model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST);
|
||||
model.addAttribute("status", HttpStatus.BAD_REQUEST.value());
|
||||
|
||||
@@ -45,17 +47,23 @@ public class GlobalExceptionHandler {
|
||||
|
||||
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
|
||||
|
||||
System.out.println("session invalidated");
|
||||
session.invalidate();
|
||||
|
||||
return "error";
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public String AllException(Model model, Exception e) {
|
||||
public String AllException(Model model, Exception e, HttpSession session) {
|
||||
model.addAttribute("error", SEVERE_ERROR_MESSAGE_BAD_REQUEST);
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
|
||||
|
||||
System.out.println("session invalidated");
|
||||
session.invalidate();
|
||||
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package com.example.demo.app.domain.model;
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.infra.entity.CourseEntity;
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -27,11 +26,10 @@ public class CourseModel {
|
||||
return courseEntityList.stream().map(CourseModel::convertFrom).toList();
|
||||
}
|
||||
|
||||
public static CourseEntity convertTo(CourseModel courseModel, List<UserEntity> userEntityList) {
|
||||
public static CourseEntity convertTo(CourseModel courseModel) {
|
||||
return new CourseEntity(
|
||||
courseModel.getCourseId(),
|
||||
courseModel.getCourseName(),
|
||||
courseModel.getDescription(),
|
||||
userEntityList);
|
||||
courseModel.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,4 +13,11 @@ public interface CourseService {
|
||||
public Long findByName(String courName);
|
||||
|
||||
public CourseModel save(CourseModel courseModel, Long userId);
|
||||
|
||||
public List<CourseModel> findAllByUserId(Long userId);
|
||||
|
||||
public List<CourseModel> findAllByNull();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ public interface GoalService {
|
||||
|
||||
public void updateGoalComplete(Long userId);
|
||||
|
||||
public int getCurrentAmount(Long userId);
|
||||
|
||||
// void deleteGoal(Long goalId);
|
||||
|
||||
}
|
||||
@@ -3,12 +3,16 @@ package com.example.demo.app.domain.service.impl;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.app.domain.model.CourseModel;
|
||||
import com.example.demo.app.domain.service.CourseService;
|
||||
import com.example.demo.app.infra.entity.CourseEntity;
|
||||
import com.example.demo.app.infra.entity.CourseOwnerEntity;
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
import com.example.demo.app.infra.repository.CourseOwnerRepository;
|
||||
import com.example.demo.app.infra.repository.CourseRepository;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
|
||||
@@ -20,12 +24,22 @@ public class CourseServiceImpl implements CourseService {
|
||||
|
||||
private final CourseRepository courseRepository;
|
||||
private final UserRepository userRepository;
|
||||
private final CourseOwnerRepository courseOwnerRepository;
|
||||
|
||||
public List<CourseModel> findAll(){
|
||||
|
||||
return CourseEntity.createCourseModelList(courseRepository.findAll());
|
||||
}
|
||||
|
||||
public List<CourseModel> findAllByUserId(Long userId) {
|
||||
|
||||
return CourseModel.convertFrom(courseRepository.findAllByUserId(userId));
|
||||
}
|
||||
|
||||
public List<CourseModel> findAllByNull() {
|
||||
return CourseModel.convertFrom(courseRepository.findAllByNull());
|
||||
}
|
||||
|
||||
public CourseModel findById(Long courseId) {
|
||||
return CourseModel.convertFrom(courseRepository.findByCourseId(courseId));
|
||||
}
|
||||
@@ -34,12 +48,27 @@ public class CourseServiceImpl implements CourseService {
|
||||
return courseRepository.findByCourseName(courseName).getCourseId();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public CourseModel save(CourseModel courseModel, Long userId) {
|
||||
|
||||
List<UserEntity> userEntityList = new ArrayList<>();
|
||||
userEntityList.add(userRepository.findById(userId).get());
|
||||
CourseEntity result = courseRepository.save( CourseModel.convertTo(courseModel));
|
||||
|
||||
UserEntity user = userRepository.findById(userId).orElse(null);
|
||||
|
||||
user.setCourseEntity(result);
|
||||
|
||||
UserEntity userResult = userRepository.save(user);
|
||||
|
||||
CourseOwnerEntity courseOwnerEntity = new CourseOwnerEntity();
|
||||
courseOwnerEntity.setUserEntity(userResult);
|
||||
courseOwnerEntity.setCourseEntity(result);
|
||||
|
||||
courseOwnerRepository.save(courseOwnerEntity);
|
||||
|
||||
return CourseModel.convertFrom(result);
|
||||
|
||||
return CourseModel.convertFrom( courseRepository.save( CourseModel.convertTo(courseModel, userEntityList)));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,13 +59,28 @@ public class GoalServiceImpl implements GoalService {
|
||||
: (int) ((currentAmount * 100.0) / goalEntity.getTargetAmount()),
|
||||
currentAmount)));
|
||||
|
||||
|
||||
return goalModelList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GoalModel createGoal(GoalModel goalModel, Long userId) {
|
||||
|
||||
UserEntity userEntity = userRepository.findById(userId).orElseThrow();
|
||||
|
||||
int transactionTotal = userEntity.getTransactionEntityList().stream()
|
||||
.mapToInt(t -> {
|
||||
int sign = t.getCategoryEntity().getTransactionType() == 1 ? 1 : -1;
|
||||
return sign * t.getAmount();
|
||||
})
|
||||
.sum();
|
||||
|
||||
// 現在の資産 = 貯蓄金 + 収支合計
|
||||
int currentAmount = userEntity.getSaving() + transactionTotal;
|
||||
|
||||
if (currentAmount >= goalModel.getTargetAmount()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
GoalEntity goalEntity = GoalModel.convertTo(goalModel, userRepository.findById(userId).get());
|
||||
|
||||
GoalEntity savedGoalEntity = goalRepository.save(goalEntity);
|
||||
@@ -108,4 +123,21 @@ public class GoalServiceImpl implements GoalService {
|
||||
});
|
||||
}
|
||||
|
||||
public int getCurrentAmount(Long userId) {
|
||||
|
||||
UserEntity userEntity = userRepository.findById(userId).orElseThrow();
|
||||
|
||||
int transactionTotal = userEntity.getTransactionEntityList().stream()
|
||||
.mapToInt(t -> {
|
||||
int sign = t.getCategoryEntity().getTransactionType() == 1 ? 1 : -1;
|
||||
return sign * t.getAmount();
|
||||
})
|
||||
.sum();
|
||||
|
||||
int currentAmount = userEntity.getSaving() + transactionTotal;
|
||||
|
||||
return currentAmount;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,6 +58,7 @@ public class ProfileServiceImpl implements ProfileService{
|
||||
userEntity.setSaving(profileEditForm.getSaving());
|
||||
userEntity.setAnnualIncome(profileEditForm.getAnnualIncome());
|
||||
userEntity.setMonthlyBudget(profileEditForm.getMonthlyBudget());
|
||||
userEntity.setBirthDate(profileEditForm.getBirthDate());
|
||||
userRepository.save(userEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,9 @@ public class UserServiceImpl implements UserService {
|
||||
CourseEntity courseEntity = courseRepository.findById(courseId).orElse(null);
|
||||
|
||||
userEntity.setQuestionEntity(questionEntity);
|
||||
|
||||
|
||||
|
||||
userEntity.setCourseEntity(courseEntity);
|
||||
|
||||
userEntity.setDeleteFlag(0);
|
||||
|
||||
@@ -7,7 +7,6 @@ import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import com.example.demo.app.domain.model.CourseModel;
|
||||
@@ -35,9 +34,6 @@ public class CourseEntity {
|
||||
@Column(name = "description", nullable = false)
|
||||
private String description;
|
||||
|
||||
@OneToMany(mappedBy = "courseEntity")
|
||||
private List<UserEntity> userEntity;
|
||||
|
||||
public static List<CourseModel> createCourseModelList(List<CourseEntity> courseEntityList) {
|
||||
|
||||
return courseEntityList
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.example.demo.app.infra.entity;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Table(name = "course_owner_t")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CourseOwnerEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long courseOwnerId;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id")
|
||||
private UserEntity userEntity;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "course_id")
|
||||
private CourseEntity courseEntity;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package com.example.demo.app.infra.entity;
|
||||
|
||||
public class TestController6 {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.example.demo.app.infra.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.example.demo.app.infra.entity.CourseOwnerEntity;
|
||||
|
||||
public interface CourseOwnerRepository extends JpaRepository<CourseOwnerEntity, Long>{
|
||||
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.demo.app.infra.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
@@ -13,5 +15,10 @@ public interface CourseRepository extends JpaRepository<CourseEntity, Long> {
|
||||
@Query("SELECT c FROM CourseEntity c WHERE c.courseName = :courseName ")
|
||||
public CourseEntity findByCourseName(String courseName);
|
||||
|
||||
@Query("select c from CourseEntity c inner join CourseOwnerEntity o on c.courseId = o.courseEntity.courseId inner join UserEntity u on o.userEntity.userId = u.userId where u.userId = :userId")
|
||||
public List<CourseEntity> findAllByUserId(Long userId);
|
||||
|
||||
@Query("select c from CourseEntity c where c.courseId between 1 and 6")
|
||||
public List<CourseEntity> findAllByNull();
|
||||
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import com.example.demo.aop.aspect.SessionCheck;
|
||||
import com.example.demo.app.domain.model.AllocationModel;
|
||||
import com.example.demo.app.domain.model.CourseModel;
|
||||
import com.example.demo.app.domain.model.LoginModel;
|
||||
import com.example.demo.app.domain.service.AllocationService;
|
||||
import com.example.demo.app.domain.service.CourseInfoService;
|
||||
@@ -47,7 +48,9 @@ public class CourseController {
|
||||
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_LIST,
|
||||
CourseForm.convertFrom(courseService.findAllByNull()));
|
||||
model.addAttribute(PageReturnAttributeKeyword.COURSE_INFO_LIST,
|
||||
CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
||||
|
||||
@@ -66,9 +69,15 @@ public class CourseController {
|
||||
|
||||
Long currentCourseId = userService.findByUserId(userId).getCourseId();
|
||||
|
||||
List<CourseModel> courseModelList = new ArrayList<>(courseService.findAllByNull());
|
||||
|
||||
List<CourseModel> tempList = courseService.findAllByUserId(userId);
|
||||
|
||||
tempList.forEach(courseModelList::add);
|
||||
|
||||
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_LIST, CourseForm.convertFrom(courseModelList));
|
||||
model.addAttribute(PageReturnAttributeKeyword.COURSE_INFO_LIST,
|
||||
CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
||||
|
||||
@@ -117,27 +126,38 @@ public class CourseController {
|
||||
List<AllocationModel> allocationModelList = new ArrayList<>();
|
||||
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId1(),
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio1()));
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
|
||||
allocationFormList.getAllocationRatio1()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId2(),
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio2()));
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
|
||||
allocationFormList.getAllocationRatio2()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId3(),
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio3()));
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
|
||||
allocationFormList.getAllocationRatio3()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId4(),
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio4()));
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
|
||||
allocationFormList.getAllocationRatio4()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId5(),
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio5()));
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
|
||||
allocationFormList.getAllocationRatio5()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId6(),
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio6()));
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
|
||||
allocationFormList.getAllocationRatio6()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId7(),
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio7()));
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
|
||||
allocationFormList.getAllocationRatio7()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId8(),
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio8()));
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
|
||||
allocationFormList.getAllocationRatio8()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId9(),
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio9()));
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
|
||||
allocationFormList.getAllocationRatio9()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId10(),
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio10()));
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
|
||||
allocationFormList.getAllocationRatio10()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId11(),
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID), allocationFormList.getAllocationRatio11()));
|
||||
(Long) session.getAttribute(PageReturnAttributeKeyword.COURSE_ID),
|
||||
allocationFormList.getAllocationRatio11()));
|
||||
|
||||
allocationService.save(allocationModelList);
|
||||
|
||||
|
||||
@@ -267,20 +267,31 @@ public class GoalController {
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping(TransitionTargetPageNameKeyword.CREATE)
|
||||
public String createGoalGet(@ModelAttribute GoalForm goalForm, HttpSession session) {
|
||||
public String createGoalGet(@ModelAttribute GoalForm goalForm, HttpSession session, Model model) {
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
Long userId = loginUser.getUserId();
|
||||
|
||||
int currentAmount = goalService.getCurrentAmount(userId);
|
||||
|
||||
model.addAttribute("currentAmount", currentAmount);
|
||||
|
||||
return TransitionTargetPageNameKeyword.GOAL_CREATE_HTML;
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping(TransitionTargetPageNameKeyword.CREATE)
|
||||
public String createGoalPost(@ModelAttribute GoalForm goalForm, HttpSession session) {
|
||||
public String createGoalPost(@ModelAttribute GoalForm goalForm, HttpSession session, Model model) {
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
Long userId = loginUser.getUserId();
|
||||
|
||||
goalService.createGoal(GoalModel.convertFrom(goalForm), userId);
|
||||
if (goalService.createGoal(GoalModel.convertFrom(goalForm), userId) == null) {
|
||||
model.addAttribute(PageReturnAttributeKeyword.MESSAGE, "現在所持金より高い金額を設定してください。");
|
||||
return TransitionTargetPageNameKeyword.GOAL_CREATE_HTML;
|
||||
}
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.GOAL;
|
||||
}
|
||||
|
||||
@@ -54,9 +54,11 @@ public class ProfileController {
|
||||
new ProfileEditForm(
|
||||
profileModel.getUserName(),
|
||||
profileModel.getMailAddress(),
|
||||
profileModel.getBirthDate(),
|
||||
profileModel.getSaving(),
|
||||
profileModel.getAnnualIncome(),
|
||||
profileModel.getMonthlyBudget());
|
||||
profileModel.getMonthlyBudget(),
|
||||
profileModel.getBirthDate());
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.PROFILE_EDIT_FORM, profileEditForm);
|
||||
return TransitionTargetPageNameKeyword.PROFILE_EDIT_HTML;
|
||||
|
||||
@@ -218,8 +218,28 @@ public class TransactionController {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
List<CategoryForm> expenseList = new ArrayList<CategoryForm>();
|
||||
|
||||
List<CategoryForm> incomeList = new ArrayList<CategoryForm>();
|
||||
|
||||
for (CategoryForm categoryForm : categoryFormList) {
|
||||
|
||||
if (categoryForm.getTransactionType() == 0) {
|
||||
expenseList.add(categoryForm);
|
||||
} else {
|
||||
incomeList.add(categoryForm);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.EXPENSE_LIST, expenseList);
|
||||
model.addAttribute(PageReturnAttributeKeyword.INCOME_LIST, incomeList);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.TRANSACTION_FORM, transactionForm);
|
||||
|
||||
session.setAttribute("tType", String.valueOf(transactionForm.getTransactionType()));
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.CATEGORY_FORM_LIST, categoryFormList);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.TODAY, today.format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -10,7 +12,9 @@ import lombok.NoArgsConstructor;
|
||||
public class ProfileEditForm {
|
||||
private String userName;
|
||||
private String mailAddress;
|
||||
private LocalDate birthDate;
|
||||
private Integer saving;
|
||||
private Integer annualIncome;
|
||||
private Integer monthlyBudget;
|
||||
private LocalDate birthDate;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
<body style="padding-top:80px; padding-bottom:80px;">
|
||||
<body style="padding-top:80px; padding-bottom:120px;">
|
||||
|
||||
<div th:replace="~{header :: header}"></div>
|
||||
|
||||
|
||||
@@ -10,12 +10,6 @@
|
||||
<div th:replace="~{header :: header}">
|
||||
</div>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div th:replace="~{header :: header}">
|
||||
</div>
|
||||
|
||||
<div class="container text-center mt-5">
|
||||
|
||||
<h2 class="text-danger">
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
|
||||
<div th:replace="~{footer :: footer}"></div>
|
||||
|
||||
|
||||
<script>
|
||||
const transactionType = document.getElementById("transactionType");
|
||||
const categoryId = document.getElementById("categoryId");
|
||||
@@ -90,6 +91,7 @@
|
||||
const expenseList = document.getElementsByClassName("expenseListClass");
|
||||
const incomeList = document.getElementsByClassName("incomeListClass");
|
||||
|
||||
|
||||
transactionType.addEventListener("change", function () {
|
||||
|
||||
if (this.value === "1") {
|
||||
|
||||
@@ -37,6 +37,10 @@
|
||||
<div>
|
||||
<label>目標金額</label>
|
||||
<input type="number" th:field="*{targetAmount}" required min="1">
|
||||
<span th:text="|所持金:${currentAmount}円|"></span>
|
||||
<span th:if="${message != null}">
|
||||
<span th:text="${message}" style="color: red;"></span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@@ -44,7 +48,7 @@
|
||||
<input type="date" th:field="*{deadline}"
|
||||
th:min="${#temporals.format(#temporals.createNow(), 'yyyy-MM-dd')}" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-sm btn-primary w-100">更新する</button>
|
||||
<button type="submit" class="btn btn-sm btn-primary w-100">登録</button>
|
||||
|
||||
</form>
|
||||
|
||||
|
||||
@@ -138,6 +138,8 @@
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
|
||||
@@ -60,6 +60,10 @@
|
||||
|
||||
</div>
|
||||
|
||||
<span th:if="${message != null}">
|
||||
<h4 th:text="${message}" style="color: red;"></h4>
|
||||
</span>
|
||||
|
||||
<div class="d-grid">
|
||||
|
||||
<button type="submit"
|
||||
|
||||
@@ -52,13 +52,15 @@
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label">
|
||||
パスワード
|
||||
生年月日
|
||||
</label>
|
||||
|
||||
<input type="password"
|
||||
<input type="date"
|
||||
class="form-control"
|
||||
value="********"
|
||||
disabled>
|
||||
id="birthDate"
|
||||
name="birthDate"
|
||||
th:value="*{birthDate}"
|
||||
required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
@@ -105,7 +107,7 @@
|
||||
<div class="d-grid">
|
||||
<button type="submit"
|
||||
class="btn btn-primary">
|
||||
確認
|
||||
確定
|
||||
</button>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
<title>コース選択</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<body style="padding-bottom: 120px">
|
||||
<div th:replace="~{header :: header}"></div>
|
||||
|
||||
<h1 class="page-title">コース選択</h1>
|
||||
|
||||
<th:block th:if="${mode == 'change'}">
|
||||
@@ -34,7 +35,7 @@
|
||||
</button>
|
||||
</h2>
|
||||
<div th:id="'collapse' + ${course.courseId}" class="accordion-collapse collapse"
|
||||
data-bs-parent="#accordionExample">
|
||||
data-bs-parent="#accordionExample" style="padding-bottom: 120px;">
|
||||
<div class="accordion-body">
|
||||
<span th:text="${course.description}"></span>
|
||||
<table class="table table-bordered">
|
||||
|
||||
@@ -23,34 +23,23 @@
|
||||
|
||||
<div class="card-body">
|
||||
|
||||
<form th:action="@{/transaction/create}"
|
||||
th:object="${transactionForm}"
|
||||
method="post">
|
||||
<form th:action="@{/transaction/create}" th:object="${transactionForm}" method="post">
|
||||
|
||||
<div class="mb-3">
|
||||
<label for="transactionDate"
|
||||
class="form-label">
|
||||
<label for="transactionDate" class="form-label">
|
||||
日付
|
||||
</label>
|
||||
<input type="date"
|
||||
id="transactionDate"
|
||||
class="form-select"
|
||||
name="transactionDate"
|
||||
th:value="*{transactionDate}"
|
||||
required>
|
||||
<input type="date" id="transactionDate" class="form-select" name="transactionDate"
|
||||
th:value="*{transactionDate}" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
|
||||
<label for="transactionType"
|
||||
class="form-label">
|
||||
<label for="transactionType" class="form-label">
|
||||
収入・支出
|
||||
</label>
|
||||
|
||||
<select id="transactionType"
|
||||
class="form-select"
|
||||
th:field="*{transactionType}"
|
||||
required>
|
||||
<select id="transactionType" class="form-select" name="transactionType" required>
|
||||
|
||||
<option value="">
|
||||
選択してください
|
||||
@@ -70,23 +59,22 @@
|
||||
|
||||
<div class="mb-3">
|
||||
|
||||
<label for="categoryId"
|
||||
class="form-label">
|
||||
<label for="categoryId" class="form-label">
|
||||
カテゴリ
|
||||
</label>
|
||||
|
||||
<select id="categoryId"
|
||||
class="form-select"
|
||||
th:field="*{categoryId}"
|
||||
required>
|
||||
<select id="categoryId" class="form-select" th:field="*{categoryId}" required>
|
||||
|
||||
<option value="">
|
||||
選択してください
|
||||
</option>
|
||||
|
||||
<option th:each="category : ${categoryFormList}"
|
||||
th:value="${category.categoryId}"
|
||||
th:text="${category.categoryName}">
|
||||
<option class="expenseListClass" th:each="category : ${expenseList}"
|
||||
th:value="${category.categoryId}" th:text="${category.categoryName}">
|
||||
</option>
|
||||
|
||||
<option class="incomeListClass" th:each="category : ${incomeList}"
|
||||
th:value="${category.categoryId}" th:text="${category.categoryName}">
|
||||
</option>
|
||||
|
||||
</select>
|
||||
@@ -95,30 +83,20 @@
|
||||
|
||||
<div class="mb-3">
|
||||
|
||||
<label for="amount"
|
||||
class="form-label">
|
||||
<label for="amount" class="form-label">
|
||||
金額
|
||||
</label>
|
||||
|
||||
<input type="number"
|
||||
id="amount"
|
||||
class="form-control"
|
||||
th:field="*{amount}"
|
||||
min="0"
|
||||
max="100000000"
|
||||
placeholder="金額を入力してください"
|
||||
required>
|
||||
<input type="number" id="amount" class="form-control" th:field="*{amount}" min="1"
|
||||
max="100000000" placeholder="金額を入力してください" required>
|
||||
|
||||
</div>
|
||||
|
||||
<input type="hidden"
|
||||
name="today"
|
||||
th:value="${today}">
|
||||
<input type="hidden" name="today" th:value="${today}">
|
||||
|
||||
<div class="d-grid">
|
||||
|
||||
<button type="submit"
|
||||
class="btn btn-primary">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
|
||||
登録
|
||||
|
||||
@@ -136,6 +114,59 @@
|
||||
|
||||
<div th:replace="~{footer :: footer}"></div>
|
||||
|
||||
<script inline="javascript">
|
||||
const transactionType = document.getElementById("transactionType");
|
||||
const categoryId = document.getElementById("categoryId");
|
||||
|
||||
const expenseList = document.getElementsByClassName("expenseListClass");
|
||||
const incomeList = document.getElementsByClassName("incomeListClass");
|
||||
|
||||
const tType = '[[${session.tType}]]';
|
||||
|
||||
if (tType == "0") {
|
||||
transactionType.value = 1;
|
||||
} else {
|
||||
transactionType.value = 2;
|
||||
}
|
||||
|
||||
|
||||
transactionType.addEventListener("change", function () {
|
||||
|
||||
if (this.value === "1") {
|
||||
|
||||
for (let i = 0; i < expenseList.length; i++) {
|
||||
expenseList[i].style.display = "";
|
||||
}
|
||||
|
||||
for (let i = 0; i < incomeList.length; i++) {
|
||||
incomeList[i].style.display = "none";
|
||||
}
|
||||
|
||||
} else if (this.value === "2") {
|
||||
|
||||
for (let i = 0; i < expenseList.length; i++) {
|
||||
expenseList[i].style.display = "none";
|
||||
}
|
||||
|
||||
for (let i = 0; i < incomeList.length; i++) {
|
||||
incomeList[i].style.display = "";
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
for (let i = 0; i < expenseList.length; i++) {
|
||||
expenseList[i].style.display = "none";
|
||||
}
|
||||
|
||||
for (let i = 0; i < incomeList.length; i++) {
|
||||
incomeList[i].style.display = "none";
|
||||
}
|
||||
}
|
||||
|
||||
categoryId.value = "";
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
|
||||
@@ -90,6 +90,7 @@
|
||||
|
||||
<input type="hidden"
|
||||
name="today"
|
||||
id="today"
|
||||
th:value="${today}">
|
||||
|
||||
<button class="btn btn-success w-100"
|
||||
@@ -103,22 +104,49 @@
|
||||
|
||||
</div>
|
||||
|
||||
<div class="d-grid mt-4">
|
||||
|
||||
<form th:action="@{/fixed-cost/list}" method="get">
|
||||
|
||||
<input type="hidden"
|
||||
name="today"
|
||||
id="today"
|
||||
th:value="${today}">
|
||||
|
||||
<button class="btn btn-dark w-100"
|
||||
type="submit">
|
||||
|
||||
固定費一覧
|
||||
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="d-grid mt-4">
|
||||
|
||||
<form th:action="@{/category/list}"
|
||||
method="get">
|
||||
|
||||
<input type="hidden"
|
||||
name="today"
|
||||
id="today"
|
||||
th:value="${today}">
|
||||
|
||||
<button class="btn btn-dark w-100"
|
||||
type="submit">
|
||||
|
||||
カテゴリ一覧
|
||||
|
||||
</button>
|
||||
|
||||
<form th:action="@{/transaction/create}" method="get">
|
||||
<input type="hidden" name="today" id="today" th:value="${today}">
|
||||
<button type="submit">新規登録</button>
|
||||
</form>
|
||||
<form th:action="@{/fixed-cost/list}" method="get">
|
||||
<input type="hidden" name="today" th:value="${today}">
|
||||
<button type="submit">固定費一覧</button>
|
||||
</form>
|
||||
<form th:action="@{/category/list}" method="get">
|
||||
<input type="hidden" name="today" th:value="${today}">
|
||||
<button type="submit">カテゴリ一覧</button>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div th:replace="~{footer :: footer}"></div>
|
||||
</body>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user