Compare commits
265 Commits
614533e2b0
...
k-oshita
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b207018db | |||
|
|
c470cc1970 | ||
|
|
edadbf86ec | ||
| 546a2927eb | |||
|
|
129d74a4df | ||
|
|
d3b76fb2cd | ||
|
|
67cc89d2a8 | ||
| 31b5e54023 | |||
| 1d34a2189d | |||
|
|
bbee55f58f | ||
|
|
f319fcb9f8 | ||
| c484d86c59 | |||
| 78d3042299 | |||
| ead133ba65 | |||
| 00c3041d95 | |||
|
|
65b4a9e54a | ||
|
|
515c789399 | ||
|
|
7299ee0d06 | ||
|
|
fa0bfa7c90 | ||
|
|
a911eaabc5 | ||
| d27d8afbb3 | |||
|
|
d291306599 | ||
| 4ef6079004 | |||
| 04b15c4397 | |||
|
|
5c87473e55 | ||
| e6b1e676a6 | |||
| cbfd8d34b4 | |||
| b666b32214 | |||
| fd469405bc | |||
| a995a41656 | |||
|
|
fd1b098e3c | ||
|
|
0b9eff82c5 | ||
|
|
52cf2b0a84 | ||
| 2a563d335c | |||
| 150b6287c4 | |||
|
|
000c1fa464 | ||
|
|
81b426b579 | ||
|
|
104fa5e319 | ||
|
|
fb031e5255 | ||
|
|
cb5d228db4 | ||
| 438ff59bc2 | |||
|
|
f5c410b352 | ||
|
|
18c51d3a65 | ||
|
|
0162f2f679 | ||
| 94b526a045 | |||
|
|
31d80388af | ||
| 4a9a1d0898 | |||
| 759df536a5 | |||
|
|
bce2d01e48 | ||
|
|
6ee8a3aa59 | ||
| 98ebb86673 | |||
|
|
84e55d7606 | ||
| 3a825196e1 | |||
|
|
aad285f9ba | ||
|
|
f1e48b02f9 | ||
| 718b90cee6 | |||
|
|
60e0694731 | ||
|
|
b09fd95c31 | ||
|
|
65282cdcb2 | ||
| 74b7032ffc | |||
|
|
0687a1837e | ||
|
|
2a4150c883 | ||
|
|
add6a85c64 | ||
|
|
fd74dee965 | ||
|
|
7aa8e31bfd | ||
|
|
e3af89a694 | ||
|
|
efdaacbb27 | ||
| 154e6787d4 | |||
| 75f2f7c8d0 | |||
| ac101172d2 | |||
|
|
d7a0aac355 | ||
|
|
a45045d008 | ||
|
|
17074c3132 | ||
|
|
34172aecc9 | ||
|
|
e5af64b53b | ||
|
|
b76be8f38a | ||
|
|
47185d8f26 | ||
|
|
0f800da9a3 | ||
|
|
546206317d | ||
|
|
d764da2ebf | ||
|
|
b83f360781 | ||
|
|
42c4d7c273 | ||
|
|
cfbf56cf4e | ||
|
|
503ac3f3db | ||
|
|
d5b18ae3ad | ||
|
|
efe93e010d | ||
|
|
054eeb7f7a | ||
|
|
5be30572cb | ||
|
|
6d0cad2454 | ||
|
|
04a6b6dedb | ||
|
|
2c445c1904 | ||
|
|
cd4321ef8c | ||
|
|
65bab96432 | ||
|
|
d911334107 | ||
|
|
b9bf0da507 | ||
|
|
2b3cecf55d | ||
|
|
9872405377 | ||
|
|
b9742d87c0 | ||
|
|
cdc5ea21c7 | ||
|
|
ff21efa943 | ||
|
|
a0ef7145d2 | ||
|
|
29749c444a | ||
|
|
073ee12f03 | ||
|
|
1438c94406 | ||
|
|
65290c0189 | ||
|
|
e0759c0f6b | ||
|
|
d526dc2e60 | ||
|
|
d7c9346b88 | ||
|
|
18eeb82cac | ||
|
|
b18ee5ee82 | ||
|
|
6fda1af754 | ||
|
|
90c5dbe8b2 | ||
|
|
29d879e3b7 | ||
|
|
f33d4412a7 | ||
|
|
573b7969b7 | ||
|
|
29d93d5453 | ||
| 907b7c1f9b | |||
| 3dba5e5322 | |||
|
|
1e0cc3a953 | ||
|
|
67906caf90 | ||
|
|
95bfd4ed0e | ||
|
|
3e6a7f5a74 | ||
|
|
4a574294b7 | ||
|
|
b8886fe47b | ||
|
|
c44a679213 | ||
|
|
0f057bcd36 | ||
|
|
fb9847a834 | ||
| d0e14ce2dc | |||
| ab2bb89d24 | |||
|
|
58da1fcbfc | ||
|
|
ec862f8271 | ||
|
|
918b7f7218 | ||
| e0b0109a2b | |||
|
|
76e3fc2345 | ||
| bcafdbe067 | |||
|
|
e9d3e16157 | ||
|
|
70ad3678a5 | ||
|
|
b2b290a998 | ||
|
|
1debde25f2 | ||
|
|
714ffba31f | ||
|
|
430f456866 | ||
|
|
003e03c0c1 | ||
|
|
060102d2b1 | ||
|
|
f5b88de9e6 | ||
|
|
68bfbc195d | ||
|
|
11a8fbf665 | ||
| 3760bf352d | |||
|
|
87fbc67a02 | ||
|
|
2139cad2b7 | ||
| 2fcc56b24b | |||
| 3b97d1f432 | |||
| 8fa363ad56 | |||
|
|
f10f9f83de | ||
|
|
6fb4ac0161 | ||
|
|
428cb0fd64 | ||
| 149f9b220c | |||
|
|
df28fa8ccd | ||
| 41aa5a5b7b | |||
|
|
5ca3226dfa | ||
| ff896c77cb | |||
|
|
65d80e6306 | ||
| 1197955f70 | |||
| 336adf0dec | |||
| 76e91f0bf0 | |||
|
|
642cd7ee69 | ||
| 52fe77a5b4 | |||
| ac85c2dc23 | |||
|
|
21ca1a72e2 | ||
|
|
56bb709921 | ||
|
|
e2ddffcc60 | ||
|
|
51310bae25 | ||
|
|
08c2c06f4a | ||
|
|
06c2d35512 | ||
|
|
4192faecc2 | ||
|
|
19218d868c | ||
| 8282331339 | |||
| 1759c45fea | |||
| 44ac862bdb | |||
|
|
5939e75f86 | ||
| ed7a3a67b7 | |||
|
|
41c5f6e99e | ||
|
|
af3e171006 | ||
|
|
31a6ce44a4 | ||
| 79b1abeac6 | |||
| 1d010dc02b | |||
|
|
d308f14df4 | ||
|
|
a36705d83f | ||
|
|
ab802cdb25 | ||
|
|
1160af5711 | ||
|
|
d2cf2e6e98 | ||
| 69213bcf9c | |||
| e0a7a3496f | |||
| f35a3e03d7 | |||
| 9a1d7144a8 | |||
|
|
d83559e937 | ||
|
|
db65afe184 | ||
|
|
34e9a17273 | ||
|
|
3378f81a2d | ||
| f588e29b46 | |||
| 11fbec6d8c | |||
| 2372c81ddd | |||
| 254286f14e | |||
| d8ea1acf2f | |||
| dfcc49ad94 | |||
|
|
9259a53bad | ||
|
|
ad1121d694 | ||
|
|
6ca5a9eeec | ||
| 709f5e14da | |||
| 6197b12ac4 | |||
| 18faec044e | |||
|
|
b49c9156a1 | ||
| 6b4ae5bd96 | |||
|
|
9cdf7b7767 | ||
|
|
6dd182ed0b | ||
|
|
04d62956f7 | ||
|
|
a5c9ab9abe | ||
|
|
200ebe2a61 | ||
|
|
2300aa3644 | ||
|
|
d415bf1ad5 | ||
|
|
12550c5b1d | ||
| a2b1922548 | |||
| 1386f4b886 | |||
| 15bf2949bc | |||
| be9abffeaa | |||
| d696d8f376 | |||
| 066d76148b | |||
| 603d0d083a | |||
| cbd5aa6a7d | |||
| 43740691b5 | |||
| 7719c002ff | |||
| 8884a74625 | |||
|
|
61da5163b0 | ||
| 30a2ef3e21 | |||
| 938574654f | |||
|
|
20b4366d91 | ||
|
|
952c6f69d8 | ||
| 2e427c8189 | |||
| 0558555315 | |||
|
|
ff65d8c045 | ||
| e43028c0ee | |||
|
|
594f09553a | ||
| 7ddebf7a4a | |||
|
|
52f2559cf7 | ||
|
|
039f416f49 | ||
| cb7a3f542b | |||
|
|
ed8e971368 | ||
| b48b3ae0bd | |||
|
|
8b6e20cb3a | ||
|
|
8f3ea4cd26 | ||
| 57749b6354 | |||
| a8c46cc9db | |||
| 702dd24d2e | |||
| d71194659b | |||
| f685b10d01 | |||
| 44ceb0ca07 | |||
|
|
f955667682 | ||
|
|
b062f64ea4 | ||
| 7e91071379 | |||
| abe5573c88 | |||
| 46fd6ee60c | |||
| e40c64c2a9 | |||
| 05dbbb4053 | |||
| aa2a511d2b | |||
| 6d494e1ac1 | |||
| 1c61909a48 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -31,3 +31,4 @@ build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
/bin/
|
||||
|
||||
5
pom.xml
5
pom.xml
@@ -83,6 +83,11 @@
|
||||
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mindrot</groupId>
|
||||
<artifactId>jbcrypt</artifactId>
|
||||
<version>0.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
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,42 @@
|
||||
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.app.presentation.controller.pageproperty.SessionKeyword;
|
||||
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(SessionKeyword.LOGIN_USER) == null) {
|
||||
throw new NoSessionException("不正なログインです");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
|
||||
import com.example.demo.app.presentation.controller.pageproperty.PageReturnAttributeKeyword;
|
||||
import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
|
||||
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(
|
||||
PageReturnAttributeKeyword.ERROR_MESSAGE,
|
||||
"システムエラーが発生しました。"
|
||||
+ "初めからやり直してください。");
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.LOGIN;
|
||||
|
||||
}
|
||||
|
||||
@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
|
||||
public String handleBadRequestException(Model model, Exception e, HttpSession session) {
|
||||
model.addAttribute(PageReturnAttributeKeyword.ERROR, SEVERE_ERROR_MESSAGE_BAD_REQUEST);
|
||||
model.addAttribute(PageReturnAttributeKeyword.STATUS, HttpStatus.BAD_REQUEST.value());
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE_ILLEGAL_TRANSITION, e);
|
||||
|
||||
System.out.println("session invalidated");
|
||||
session.invalidate();
|
||||
|
||||
return TransitionTargetPageNameKeyword.ERROR_HTML;
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public String AllException(Model model, Exception e, HttpSession session) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
System.out.println("session invalidated exception");
|
||||
session.invalidate();
|
||||
return TransitionTargetPageNameKeyword.ERROR_HTML;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,12 @@
|
||||
package com.example.demo.app.domain.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.infra.entity.AllocationEntity;
|
||||
import com.example.demo.app.infra.entity.CategoryEntity;
|
||||
import com.example.demo.app.infra.entity.CourseEntity;
|
||||
import com.example.demo.app.presentation.form.AllocationForm;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -11,4 +18,25 @@ public class AllocationModel {
|
||||
private Long courseId;
|
||||
private Integer allocationRatio;
|
||||
|
||||
public static AllocationModel convertFrom(AllocationEntity allocationEntity) {
|
||||
return new AllocationModel(allocationEntity.getCategoryEntity().getCategoryId(), allocationEntity.getCourseEntity().getCourseId(), allocationEntity.getAllocationRatio());
|
||||
}
|
||||
|
||||
public static List<AllocationModel> convertFrom(List<AllocationEntity> allocationEntityList){
|
||||
return allocationEntityList.stream().map(AllocationModel::convertFrom).toList();
|
||||
}
|
||||
|
||||
public static AllocationModel convertFrom1(AllocationForm allocationForm) {
|
||||
return new AllocationModel(allocationForm.getCategoryId(), allocationForm.getCourseId(), allocationForm.getAllocationRatio());
|
||||
}
|
||||
|
||||
public static List<AllocationModel> convertFrom1(List<AllocationForm> allocationFormList){
|
||||
return allocationFormList.stream().map(AllocationModel::convertFrom1).toList();
|
||||
}
|
||||
|
||||
public static AllocationEntity convertTo(CategoryEntity categoryEntity, CourseEntity courseEntity, Integer allocationRatio) {
|
||||
return new AllocationEntity(categoryEntity, courseEntity, allocationRatio);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.example.demo.app.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class AuthenticationModel {
|
||||
private Long userId;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.example.demo.app.domain.model;
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.infra.entity.CategoryEntity;
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -27,4 +28,15 @@ public class CategoryModel {
|
||||
return categoryEntityList.stream().map(CategoryModel::convertFrom).toList();
|
||||
}
|
||||
|
||||
public static CategoryEntity convertTo(CategoryModel categoryModel, UserEntity userEntity) {
|
||||
return new CategoryEntity(
|
||||
categoryModel.getCategoryId(),
|
||||
categoryModel.getCategoryName(),
|
||||
categoryModel.getTransactionType(),
|
||||
userEntity,
|
||||
0,
|
||||
null,
|
||||
null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,4 +25,11 @@ public class CourseModel {
|
||||
public static List<CourseModel> convertFrom(List<CourseEntity> courseEntityList) {
|
||||
return courseEntityList.stream().map(CourseModel::convertFrom).toList();
|
||||
}
|
||||
|
||||
public static CourseEntity convertTo(CourseModel courseModel) {
|
||||
return new CourseEntity(
|
||||
courseModel.getCourseId(),
|
||||
courseModel.getCourseName(),
|
||||
courseModel.getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.example.demo.app.domain.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.infra.entity.CategoryEntity;
|
||||
import com.example.demo.app.infra.entity.FixedCostEntity;
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class FixedCostModel {
|
||||
|
||||
private Long fixedCostId;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private Long categoryId;
|
||||
|
||||
private String fixedCostName;
|
||||
|
||||
private Integer amount;
|
||||
|
||||
|
||||
public static FixedCostModel convertFrom(FixedCostEntity fixedCostEntity) {
|
||||
return new FixedCostModel(
|
||||
fixedCostEntity.getFixedCostId(),
|
||||
fixedCostEntity.getUserEntity().getUserId(),
|
||||
fixedCostEntity.getCategoryEntity().getCategoryId(),
|
||||
fixedCostEntity.getFixedCostName(),
|
||||
fixedCostEntity.getAmount());
|
||||
}
|
||||
|
||||
public static List<FixedCostModel> convertFrom(List<FixedCostEntity> fixedCostEntityList) {
|
||||
return fixedCostEntityList.stream().map(FixedCostModel::convertFrom).toList();
|
||||
}
|
||||
|
||||
public static FixedCostEntity convertTo(FixedCostModel fixedCostModel, UserEntity userEntity, CategoryEntity categoryEntity) {
|
||||
return new FixedCostEntity(
|
||||
fixedCostModel.getFixedCostId(),
|
||||
userEntity,
|
||||
categoryEntity,
|
||||
fixedCostModel.getFixedCostName(),
|
||||
fixedCostModel.getAmount());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.example.demo.app.domain.model;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.infra.entity.GoalEntity;
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
import com.example.demo.app.presentation.form.GoalForm;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -24,25 +27,37 @@ public class GoalModel {
|
||||
|
||||
private Integer goalComplete;
|
||||
|
||||
public static GoalModel convertFrom(GoalEntity goalEntity) {
|
||||
private Integer achievementRate; // 達成率
|
||||
|
||||
private Integer currentAmount; // 現在の資産
|
||||
|
||||
private Long userId;
|
||||
|
||||
private List<Integer> savingList;
|
||||
|
||||
public static GoalModel convertFrom(GoalEntity goalEntity, int achievementRate, int currentAmount) {
|
||||
return new GoalModel(
|
||||
goalEntity.getGoalId(),
|
||||
goalEntity.getGoalTitle(),
|
||||
goalEntity.getGoalSubtitle(),
|
||||
goalEntity.getTargetAmount(),
|
||||
goalEntity.getDeadline(),
|
||||
goalEntity.getGoalComplete());
|
||||
goalEntity.getGoalComplete(),
|
||||
achievementRate,
|
||||
currentAmount,
|
||||
goalEntity.getUserEntity().getUserId(),
|
||||
new ArrayList<>());
|
||||
}
|
||||
|
||||
public static GoalEntity convertTo(GoalModel goalModel) {
|
||||
public static GoalEntity convertTo(GoalModel goalModel, UserEntity userEntity) {
|
||||
return new GoalEntity(
|
||||
goalModel.getGoalId(),
|
||||
goalModel.getGoalTitle(),
|
||||
goalModel.getGoalSubtitle(),
|
||||
goalModel.getTargetAmount(),
|
||||
goalModel.getDeadline(),
|
||||
goalModel.getGoalComplete(),
|
||||
null);
|
||||
0,
|
||||
userEntity);
|
||||
}
|
||||
|
||||
public static GoalModel convertFrom(GoalForm goalForm) {
|
||||
@@ -52,7 +67,10 @@ public class GoalModel {
|
||||
goalForm.getGoalSubtitle(),
|
||||
goalForm.getTargetAmount(),
|
||||
goalForm.getDeadline(),
|
||||
goalForm.getGoalComplete());
|
||||
goalForm.getGoalComplete()
|
||||
,null,null,
|
||||
goalForm.getUserId(),
|
||||
new ArrayList<>());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.example.demo.app.domain.model;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class ProfileModel {
|
||||
private Long userId;
|
||||
private String userName;
|
||||
private String mailAddress;
|
||||
private LocalDate birthDate;
|
||||
private Integer saving;
|
||||
private Integer annualIncome;
|
||||
private Integer monthlyBudget;
|
||||
}
|
||||
@@ -2,24 +2,41 @@ package com.example.demo.app.domain.model;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class UserModel {
|
||||
|
||||
private Long userId;
|
||||
private String userName;
|
||||
private String emailAddress;
|
||||
private String mailAddress;
|
||||
private String password;
|
||||
private Integer secretQuestionId;
|
||||
private Long secretQuestionId;
|
||||
private String secretAnswer;
|
||||
private LocalDate brithDate;
|
||||
private Integer saving;
|
||||
private Integer annualIncome;
|
||||
private Integer monthlyBudget;
|
||||
private Integer goalId;
|
||||
private Integer courseId;
|
||||
private Long courseId;
|
||||
private Integer deleteFlag;
|
||||
|
||||
public static UserModel convertFrom(UserEntity userEntity) {
|
||||
return new UserModel(
|
||||
userEntity.getUserId(),
|
||||
userEntity.getUserName(),
|
||||
userEntity.getMailAddress(),
|
||||
userEntity.getPassword(),
|
||||
userEntity.getQuestionEntity().getSecretQuestionId(),
|
||||
userEntity.getSecretQuestionAnswer(),
|
||||
userEntity.getBirthDate(),
|
||||
userEntity.getSaving(),
|
||||
userEntity.getAnnualIncome(),
|
||||
userEntity.getMonthlyBudget(),
|
||||
userEntity.getCourseEntity().getCourseId(),
|
||||
userEntity.getDeleteFlag()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.example.demo.app.domain.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.AllocationModel;
|
||||
|
||||
public interface AllocationService {
|
||||
|
||||
public List<AllocationModel> findAll();
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.example.demo.app.domain.service;
|
||||
|
||||
import com.example.demo.app.domain.model.AuthenticationModel;
|
||||
import com.example.demo.app.presentation.form.AuthenticationForm;
|
||||
|
||||
public interface AuthenticationService {
|
||||
|
||||
AuthenticationModel authenticate(AuthenticationForm authenticationForm);
|
||||
}
|
||||
@@ -11,4 +11,14 @@ public interface CategoryService {
|
||||
public CategoryModel findOne(Long categoryId);
|
||||
|
||||
public CategoryModel findOneByCategoryName(String categoryName);
|
||||
|
||||
public CategoryModel findByTransactionId(Long transactionId);
|
||||
|
||||
public List<CategoryModel> findAllByuserId(Long userId);
|
||||
|
||||
public void delete(Long categoryId);
|
||||
|
||||
public CategoryModel save(CategoryModel categoryModel, Long userId);
|
||||
|
||||
public List<CategoryModel> findAllExceptCustom();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.example.demo.app.domain.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.CourseInfoModel;
|
||||
|
||||
public interface CourseInfoService {
|
||||
|
||||
public List<CourseInfoModel> findAll();
|
||||
}
|
||||
@@ -3,9 +3,24 @@ package com.example.demo.app.domain.service;
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.CourseModel;
|
||||
import com.example.demo.app.presentation.form.AllocationFormList;
|
||||
|
||||
public interface CourseService {
|
||||
//
|
||||
|
||||
public List<CourseModel> findAll();
|
||||
|
||||
public CourseModel findById(Long courseId);
|
||||
|
||||
public Long findByName(String courName);
|
||||
|
||||
public CourseModel save(CourseModel courseModel, Long userId, AllocationFormList allocationFormList);
|
||||
|
||||
public List<CourseModel> findAllByUserId(Long userId);
|
||||
|
||||
public List<CourseModel> findAllByNull();
|
||||
|
||||
public String deleteCourse(Long courseId, Long userId);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.example.demo.app.domain.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.FixedCostModel;
|
||||
|
||||
public interface FixedCostService {
|
||||
|
||||
public List<FixedCostModel> findAllByUserId(Long userId);
|
||||
|
||||
public FixedCostModel save(FixedCostModel fixedCostModel);
|
||||
|
||||
public void delete(Long fixedCostId);
|
||||
|
||||
public FixedCostModel findById(Long fixedCostId);
|
||||
}
|
||||
@@ -1,14 +1,24 @@
|
||||
package com.example.demo.app.domain.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.GoalModel;
|
||||
|
||||
public interface GoalService {
|
||||
|
||||
GoalModel getGoalById(Long goalId);
|
||||
|
||||
GoalModel createGoal(GoalModel goalModel);
|
||||
public List<GoalModel> getGoalByUserId(Long userId);
|
||||
|
||||
GoalModel updateGoal(GoalModel goalModel);
|
||||
public GoalModel createGoal(GoalModel goalModel, Long userId);
|
||||
|
||||
GoalModel updateGoal(GoalModel goalModel, Long userId);
|
||||
|
||||
public void delete(Long goalId);
|
||||
|
||||
public void updateGoalComplete(Long userId);
|
||||
|
||||
public int getCurrentAmount(Long userId);
|
||||
|
||||
// void deleteGoal(Long goalId);
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package com.example.demo.app.domain.service;
|
||||
|
||||
import com.example.demo.app.presentation.form.PasswordResetForm;
|
||||
|
||||
public interface PasswordResetService {
|
||||
boolean resetPassword(Long userId, PasswordResetForm passwordResetForm);
|
||||
}
|
||||
@@ -0,0 +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);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.example.demo.app.domain.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.infra.entity.QuestionEntity;
|
||||
|
||||
public interface QuestionService {
|
||||
public List<QuestionEntity> findAll();
|
||||
}
|
||||
@@ -5,19 +5,31 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.example.demo.app.domain.model.TransactionModel;
|
||||
import com.example.demo.app.presentation.form.Expense;
|
||||
import com.example.demo.app.presentation.form.Income;
|
||||
|
||||
public interface TransactionService {
|
||||
|
||||
public TransactionModel findByTransactionId(Long transactionId);
|
||||
|
||||
public Map<LocalDate, List<TransactionModel>> findAllByDate(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
|
||||
public List<TransactionModel> findByUserIdAndDate(LocalDate todayDate, Long userId);
|
||||
|
||||
public int findTotalIncome(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
|
||||
public int findTotalexpense(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
public int findTotalExpense(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
|
||||
public int findMoneyRecord(Long transactionId);
|
||||
|
||||
public int createTransaction(TransactionModel transactionModel);
|
||||
|
||||
public int updateTransaction(TransactionModel transactionModel);
|
||||
|
||||
public void deleteTransaction(Long transactionId);
|
||||
|
||||
public List<Income> findTotalIncomeList(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
|
||||
public List<Expense> findTotalExpenseList(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.example.demo.app.domain.service;
|
||||
|
||||
import com.example.demo.app.domain.model.UserModel;
|
||||
import com.example.demo.app.presentation.form.UserForm;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
public void register(UserForm userForm, Long courseId);
|
||||
|
||||
public void updateCourse(Long userId, Long courseId);
|
||||
|
||||
public UserModel findByUserId(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.app.domain.model.AllocationModel;
|
||||
import com.example.demo.app.domain.service.AllocationService;
|
||||
import com.example.demo.app.infra.entity.AllocationEntity;
|
||||
import com.example.demo.app.infra.repository.AllocationRepository;
|
||||
import com.example.demo.app.infra.repository.CategoryRepository;
|
||||
import com.example.demo.app.infra.repository.CourseRepository;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AllocationServiceImpl implements AllocationService {
|
||||
|
||||
private final AllocationRepository allocationRepository;
|
||||
private final CategoryRepository categoryRepository;
|
||||
private final CourseRepository courseRepository;
|
||||
|
||||
public List<AllocationModel> findAll() {
|
||||
return AllocationEntity.createAllocationModelList(allocationRepository.findAll());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.app.domain.model.AuthenticationModel;
|
||||
import com.example.demo.app.domain.service.AuthenticationService;
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
import com.example.demo.app.presentation.form.AuthenticationForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class AuthenticationServiceImpl implements AuthenticationService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public AuthenticationModel authenticate(AuthenticationForm authenticationForm) {
|
||||
|
||||
UserEntity userEntity = userRepository.findByMailAddress(
|
||||
authenticationForm.getMailAddress())
|
||||
.orElse(null);
|
||||
|
||||
if (userEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!userEntity.getQuestionEntity().getSecretQuestionId()
|
||||
.equals(authenticationForm.getSecretQuestionId())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!userEntity.getSecretQuestionAnswer()
|
||||
.equals(authenticationForm.getSecretAnswer())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new AuthenticationModel(userEntity.getUserId());
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import com.example.demo.app.domain.model.CategoryModel;
|
||||
import com.example.demo.app.domain.service.CategoryService;
|
||||
import com.example.demo.app.infra.entity.CategoryEntity;
|
||||
import com.example.demo.app.infra.repository.CategoryRepository;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -17,6 +18,7 @@ import lombok.RequiredArgsConstructor;
|
||||
public class CategoryServiceImpl implements CategoryService {
|
||||
|
||||
private final CategoryRepository categoryRepository;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public List<CategoryModel> findAll() {
|
||||
|
||||
@@ -48,4 +50,33 @@ public class CategoryServiceImpl implements CategoryService {
|
||||
|
||||
}
|
||||
|
||||
public CategoryModel findByTransactionId(Long transactionId) {
|
||||
return CategoryModel.convertFrom(categoryRepository.findByTransactionId(transactionId));
|
||||
}
|
||||
|
||||
public List<CategoryModel> findAllByuserId(Long userId) {
|
||||
|
||||
return CategoryModel.convertFrom(categoryRepository.findByUserId(userId));
|
||||
|
||||
}
|
||||
|
||||
public void delete(Long categoryId) {
|
||||
|
||||
categoryRepository.deleteById(categoryId);
|
||||
|
||||
}
|
||||
|
||||
public CategoryModel save(CategoryModel categoryModel, Long userId) {
|
||||
|
||||
return CategoryModel.convertFrom(
|
||||
categoryRepository.save(CategoryModel.convertTo(categoryModel, userRepository.findById(userId).get())));
|
||||
|
||||
}
|
||||
|
||||
public List<CategoryModel> findAllExceptCustom() {
|
||||
|
||||
return CategoryModel.convertFrom(categoryRepository.findAllExceptCustom());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.app.domain.model.CourseInfoModel;
|
||||
import com.example.demo.app.domain.service.CourseInfoService;
|
||||
import com.example.demo.app.infra.repository.AllocationRepository;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class CourseInfoServiceImpl implements CourseInfoService {
|
||||
|
||||
private final AllocationRepository allocationRepository;
|
||||
|
||||
@Override
|
||||
public List<CourseInfoModel> findAll() {
|
||||
return allocationRepository.findAllJoinedAllocation();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,25 @@
|
||||
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.AllocationModel;
|
||||
import com.example.demo.app.domain.model.CourseModel;
|
||||
import com.example.demo.app.domain.service.CourseService;
|
||||
import com.example.demo.app.infra.entity.AllocationEntity;
|
||||
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.AllocationRepository;
|
||||
import com.example.demo.app.infra.repository.CategoryRepository;
|
||||
import com.example.demo.app.infra.repository.CourseOwnerRepository;
|
||||
import com.example.demo.app.infra.repository.CourseRepository;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
import com.example.demo.app.presentation.form.AllocationFormList;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -15,11 +27,123 @@ import lombok.RequiredArgsConstructor;
|
||||
@RequiredArgsConstructor
|
||||
public class CourseServiceImpl implements CourseService {
|
||||
|
||||
private final CourseRepository courseRepository;
|
||||
private final AllocationRepository allocationRepository;
|
||||
|
||||
public List<CourseModel> findAll(){
|
||||
private final CourseRepository courseRepository;
|
||||
private final UserRepository userRepository;
|
||||
private final CourseOwnerRepository courseOwnerRepository;
|
||||
private final CategoryRepository categoryRepository;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
public Long findByName(String courseName) {
|
||||
return courseRepository.findByCourseName(courseName).getCourseId();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public CourseModel save(CourseModel courseModel, Long userId, AllocationFormList allocationFormList) {
|
||||
|
||||
List<UserEntity> userEntityList = new ArrayList<>();
|
||||
userEntityList.add(userRepository.findById(userId).get());
|
||||
CourseEntity result = courseRepository.save(CourseModel.convertTo(courseModel));
|
||||
|
||||
List<AllocationModel> allocationModelList = new ArrayList<>();
|
||||
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId4(),
|
||||
result.getCourseId(),
|
||||
allocationFormList.getAllocationRatio4()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId5(),
|
||||
result.getCourseId(),
|
||||
allocationFormList.getAllocationRatio5()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId6(),
|
||||
result.getCourseId(),
|
||||
allocationFormList.getAllocationRatio6()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId7(),
|
||||
result.getCourseId(),
|
||||
allocationFormList.getAllocationRatio7()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId8(),
|
||||
result.getCourseId(),
|
||||
allocationFormList.getAllocationRatio8()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId9(),
|
||||
result.getCourseId(),
|
||||
allocationFormList.getAllocationRatio9()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId10(),
|
||||
result.getCourseId(),
|
||||
allocationFormList.getAllocationRatio10()));
|
||||
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId11(),
|
||||
result.getCourseId(),
|
||||
allocationFormList.getAllocationRatio11()));
|
||||
|
||||
allocationModelList.stream().forEach(allocation -> {
|
||||
System.out.println(allocation.getCourseId());
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
List<AllocationEntity> allocationEntityList = new ArrayList<>();
|
||||
|
||||
allocationModelList.forEach(allocationModel -> {
|
||||
allocationEntityList.add(
|
||||
AllocationModel.convertTo(
|
||||
categoryRepository.findById(allocationModel.getCategoryId()).get(),
|
||||
courseRepository.findById(allocationModel.getCourseId()).get(),
|
||||
allocationModel.getAllocationRatio()));
|
||||
|
||||
});
|
||||
|
||||
List<AllocationModel> resultList = new ArrayList<>();
|
||||
for (AllocationEntity allocationEntity : allocationEntityList) {
|
||||
resultList.add(AllocationModel.convertFrom(allocationRepository.save(allocationEntity)));
|
||||
}
|
||||
|
||||
return CourseModel.convertFrom(result);
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public String deleteCourse(Long courseId, Long userId) {
|
||||
|
||||
UserEntity userEntity = userRepository.findById(userId).orElse(null);
|
||||
System.out.println("***********************ここでエラー1");
|
||||
if (userEntity.getCourseEntity().getCourseId() == courseId) {
|
||||
return "selected";
|
||||
} else if (courseId <= 6) {
|
||||
return "original";
|
||||
}
|
||||
System.out.println("***********************ここでエラー2");
|
||||
allocationRepository.deleteByCourseId(courseId);
|
||||
System.out.println("***********************ここでエラー3");
|
||||
courseOwnerRepository.deleteByCourseId(courseId);
|
||||
System.out.println("***********************ここでエラー4");
|
||||
courseRepository.deleteById(courseId);
|
||||
System.out.println("***********************ここでエラー5");
|
||||
return "ok";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.app.domain.model.FixedCostModel;
|
||||
import com.example.demo.app.domain.service.FixedCostService;
|
||||
import com.example.demo.app.infra.repository.CategoryRepository;
|
||||
import com.example.demo.app.infra.repository.FixedCostRepository;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class FixedCostServiceImpl implements FixedCostService{
|
||||
|
||||
|
||||
private final FixedCostRepository fixedCostRepository;
|
||||
private final UserRepository userRepository;
|
||||
private final CategoryRepository categoryRepository;
|
||||
|
||||
|
||||
public List<FixedCostModel> findAllByUserId(Long userId) {
|
||||
|
||||
return FixedCostModel.convertFrom(fixedCostRepository.findByUserId(userId));
|
||||
|
||||
}
|
||||
|
||||
public FixedCostModel save(FixedCostModel fixedCostModel) {
|
||||
|
||||
return FixedCostModel.convertFrom(fixedCostRepository.save( FixedCostModel.convertTo(fixedCostModel, userRepository.findById(fixedCostModel.getUserId()).get(), categoryRepository.findById(fixedCostModel.getCategoryId()).get())));
|
||||
|
||||
}
|
||||
|
||||
public void delete(Long fixedCostId) {
|
||||
|
||||
fixedCostRepository.deleteById(fixedCostId);
|
||||
|
||||
}
|
||||
|
||||
public FixedCostModel findById(Long fixedCostId) {
|
||||
return FixedCostModel.convertFrom(fixedCostRepository.findById(fixedCostId).get());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,11 +1,19 @@
|
||||
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.GoalModel;
|
||||
import com.example.demo.app.domain.service.GoalService;
|
||||
import com.example.demo.app.infra.entity.GoalEntity;
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
import com.example.demo.app.infra.repository.GoalRepository;
|
||||
import com.example.demo.app.infra.repository.TransactionRepository;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -14,35 +22,121 @@ import lombok.RequiredArgsConstructor;
|
||||
public class GoalServiceImpl implements GoalService {
|
||||
|
||||
private final GoalRepository goalRepository;
|
||||
private final UserRepository userRepository;
|
||||
private final TransactionRepository transactionRepository;
|
||||
|
||||
@Override
|
||||
public GoalModel getGoalById(Long goalId) {
|
||||
|
||||
GoalEntity goalEntity = goalRepository.findById(goalId).orElse(null);
|
||||
|
||||
return GoalModel.convertFrom(goalEntity);
|
||||
|
||||
return GoalModel.convertFrom(goalEntity, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GoalModel createGoal(GoalModel goalModel) {
|
||||
public List<GoalModel> getGoalByUserId(Long userId) {
|
||||
|
||||
GoalEntity goalEntity = GoalModel.convertTo(goalModel);
|
||||
UserEntity userEntity = userRepository.findById(userId).orElseThrow();
|
||||
List<GoalEntity> goalEntityList = goalRepository.findAllByUserId(userId);
|
||||
|
||||
// 収支の合計を計算(収入はプラス、支出はマイナス)
|
||||
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;
|
||||
|
||||
// 達成率(%) = 現在の資産 ÷ 目標金額 × 100
|
||||
|
||||
List<GoalModel> goalModelList = new ArrayList<GoalModel>();
|
||||
|
||||
goalEntityList.stream()
|
||||
.forEach(goalEntity -> goalModelList.add(GoalModel.convertFrom(goalEntity,
|
||||
(goalEntity.getTargetAmount() == null)
|
||||
? 0
|
||||
: (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);
|
||||
|
||||
return GoalModel.convertFrom(savedGoalEntity);
|
||||
|
||||
return GoalModel.convertFrom(savedGoalEntity, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GoalModel updateGoal(GoalModel goalModel) {
|
||||
public GoalModel updateGoal(GoalModel goalModel, Long userId) {
|
||||
|
||||
GoalEntity goalEntity = GoalModel.convertTo(goalModel);
|
||||
GoalEntity goalEntity = GoalModel.convertTo(goalModel, userRepository.findById(userId).get());
|
||||
|
||||
GoalEntity updatedGoalEntity = goalRepository.save(goalEntity);
|
||||
|
||||
return GoalModel.convertFrom(updatedGoalEntity);
|
||||
return GoalModel.convertFrom(updatedGoalEntity, 0, 0);
|
||||
}
|
||||
|
||||
public void delete(Long goalId) {
|
||||
goalRepository.deleteById(goalId);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void updateGoalComplete(Long userId) {
|
||||
UserEntity userEntity = userRepository.findById(userId).orElseThrow();
|
||||
List<GoalEntity> goalEntityList = goalRepository.findAllByUserId(userId);
|
||||
|
||||
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;
|
||||
|
||||
goalEntityList.stream().forEach(goalEntity -> {
|
||||
if (goalEntity.getTargetAmount() <= currentAmount) {
|
||||
goalRepository.updateCompleteByGoalId(goalEntity.getGoalId());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import org.mindrot.jbcrypt.BCrypt;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.app.domain.model.LoginModel;
|
||||
@@ -18,14 +19,38 @@ public class LoginServiceImpl implements LoginService {
|
||||
@Override
|
||||
public LoginModel login(String mailAddress, String password) {
|
||||
|
||||
UserEntity userEntity = userRepository.findByMailAddressAndPassword(
|
||||
mailAddress,
|
||||
password).orElse(null);
|
||||
UserEntity userEntity = userRepository
|
||||
.findByMailAddress(mailAddress)
|
||||
.orElse(null);
|
||||
|
||||
if (userEntity == null) {
|
||||
return null;
|
||||
} else if (userEntity.getDeleteFlag() == 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
boolean isValidPassword = false;
|
||||
if (userEntity.getPassword().length() <= 24) {
|
||||
if (userEntity.getPassword().equals(password)) {
|
||||
|
||||
userEntity.setPassword(BCrypt.hashpw(password, BCrypt.gensalt()));
|
||||
userRepository.save(userEntity);
|
||||
isValidPassword = true;
|
||||
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
isValidPassword = BCrypt.checkpw(password, userEntity.getPassword());
|
||||
}
|
||||
|
||||
if (!isValidPassword) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new LoginModel(userEntity.getUserId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import org.mindrot.jbcrypt.BCrypt;
|
||||
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;
|
||||
}
|
||||
|
||||
String passwordHashed = BCrypt.hashpw(passwordResetForm.getPassword(), BCrypt.gensalt());
|
||||
|
||||
userEntity.setPassword(
|
||||
passwordHashed);
|
||||
|
||||
userRepository.save(userEntity);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
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;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ProfileServiceImpl implements ProfileService{
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Override
|
||||
public ProfileModel findOne(Long userId) {
|
||||
UserEntity userEntity = userRepository.findById(userId).orElse(null);
|
||||
|
||||
if(userEntity == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new ProfileModel(
|
||||
userEntity.getUserId(),
|
||||
userEntity.getUserName(),
|
||||
userEntity.getMailAddress(),
|
||||
userEntity.getBirthDate(),
|
||||
userEntity.getSaving(),
|
||||
userEntity.getAnnualIncome(),
|
||||
userEntity.getMonthlyBudget());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void withdraw(Long userId) {
|
||||
UserEntity userEntity = userRepository.findById(userId).orElse(null);
|
||||
|
||||
if (userEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
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());
|
||||
userEntity.setBirthDate(profileEditForm.getBirthDate());
|
||||
userRepository.save(userEntity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.app.domain.service.QuestionService;
|
||||
import com.example.demo.app.infra.entity.QuestionEntity;
|
||||
import com.example.demo.app.infra.repository.QuestionRepository;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class QuestionServiceImpl implements QuestionService{
|
||||
|
||||
private final QuestionRepository questionRepository;
|
||||
|
||||
public List<QuestionEntity> findAll() {
|
||||
return questionRepository.findAll();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,8 @@ import com.example.demo.app.infra.entity.UserEntity;
|
||||
import com.example.demo.app.infra.repository.CategoryRepository;
|
||||
import com.example.demo.app.infra.repository.TransactionRepository;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
import com.example.demo.app.presentation.form.Expense;
|
||||
import com.example.demo.app.presentation.form.Income;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -27,19 +29,45 @@ public class TransactionServiceImpl implements TransactionService {
|
||||
private final UserRepository userRepository;
|
||||
private final CategoryRepository categoryRepository;
|
||||
|
||||
public Map<LocalDate, List<TransactionModel>> findAllByDate(LocalDate startDate, LocalDate endDate, Long userId) {
|
||||
|
||||
public TransactionModel findByTransactionId(Long transactionId) {
|
||||
|
||||
return TransactionModel.convertFrom(transactionRepository.findById(transactionId).get());
|
||||
|
||||
}
|
||||
|
||||
public Map<LocalDate, List<TransactionModel>> findAllByDate(
|
||||
LocalDate startDate,
|
||||
LocalDate endDate,
|
||||
Long userId) {
|
||||
|
||||
System.out.println("========== findAllByDate ==========");
|
||||
System.out.println("startDate = " + startDate);
|
||||
System.out.println("endDate = " + endDate);
|
||||
System.out.println("userId = " + userId);
|
||||
|
||||
List<TransactionEntity> transactionEntityList = transactionRepository.findAllByDateAndUserId(startDate, endDate,
|
||||
userId);
|
||||
|
||||
List<TransactionModel> transactionModelList = TransactionModel
|
||||
.convertFrom(transactionEntityList);
|
||||
System.out.println("Entity count = " + transactionEntityList.size());
|
||||
|
||||
transactionEntityList.forEach(t -> {
|
||||
System.out.println(
|
||||
"date = " + t.getTransactionDate()
|
||||
+ ", amount = " + t.getAmount());
|
||||
});
|
||||
|
||||
List<TransactionModel> transactionModelList = TransactionModel.convertFrom(transactionEntityList);
|
||||
|
||||
System.out.println("Model count = " + transactionModelList.size());
|
||||
|
||||
Map<LocalDate, List<TransactionModel>> transactionModelMap = transactionModelList.stream()
|
||||
.collect(Collectors.groupingBy(TransactionModel::getTransactionDate));
|
||||
.collect(Collectors.groupingBy(
|
||||
TransactionModel::getTransactionDate));
|
||||
|
||||
System.out.println("Map = " + transactionModelMap);
|
||||
|
||||
return transactionModelMap;
|
||||
|
||||
}
|
||||
|
||||
public int findTotalIncome(LocalDate startDate, LocalDate endDate, Long userId) {
|
||||
@@ -48,9 +76,21 @@ public class TransactionServiceImpl implements TransactionService {
|
||||
|
||||
}
|
||||
|
||||
public int findTotalexpense(LocalDate startDate, LocalDate endDate, Long userId) {
|
||||
public int findTotalExpense(LocalDate startDate, LocalDate endDate, Long userId) {
|
||||
|
||||
return transactionRepository.findTotalIncome(startDate, endDate, userId);
|
||||
return transactionRepository.findTotalExpense(startDate, endDate, userId);
|
||||
|
||||
}
|
||||
|
||||
public List<Income> findTotalIncomeList(LocalDate startDate, LocalDate endDate, Long userId) {
|
||||
|
||||
return transactionRepository.findTotalIncomeList(startDate, endDate, userId);
|
||||
|
||||
}
|
||||
|
||||
public List<Expense> findTotalExpenseList(LocalDate startDate, LocalDate endDate, Long userId) {
|
||||
|
||||
return transactionRepository.findTotalExpenseList(startDate, endDate, userId);
|
||||
|
||||
}
|
||||
|
||||
@@ -60,6 +100,11 @@ public class TransactionServiceImpl implements TransactionService {
|
||||
|
||||
}
|
||||
|
||||
public int findMoneyRecord(Long transactionId) {
|
||||
return transactionRepository.findMoneyRecord(transactionId);
|
||||
}
|
||||
|
||||
|
||||
public int createTransaction(TransactionModel transactionModel) {
|
||||
|
||||
Optional<UserEntity> userEntityOptional = userRepository.findById(transactionModel.getUserId());
|
||||
@@ -115,4 +160,9 @@ public class TransactionServiceImpl implements TransactionService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void deleteTransaction(Long transactionId) {
|
||||
transactionRepository.deleteById(transactionId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.example.demo.app.domain.service.impl;
|
||||
|
||||
import org.mindrot.jbcrypt.BCrypt;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.app.domain.model.UserModel;
|
||||
import com.example.demo.app.domain.service.UserService;
|
||||
import com.example.demo.app.infra.entity.CourseEntity;
|
||||
import com.example.demo.app.infra.entity.GoalEntity;
|
||||
import com.example.demo.app.infra.entity.QuestionEntity;
|
||||
import com.example.demo.app.infra.entity.UserEntity;
|
||||
import com.example.demo.app.infra.repository.CourseRepository;
|
||||
import com.example.demo.app.infra.repository.GoalRepository;
|
||||
import com.example.demo.app.infra.repository.QuestionRepository;
|
||||
import com.example.demo.app.infra.repository.UserRepository;
|
||||
import com.example.demo.app.presentation.form.UserForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserServiceImpl implements UserService {
|
||||
private final UserRepository userRepository;
|
||||
private final QuestionRepository questionRepository;
|
||||
private final GoalRepository goalRepository;
|
||||
private final CourseRepository courseRepository;
|
||||
|
||||
@Override
|
||||
public void register(UserForm userForm, Long courseId) {
|
||||
|
||||
UserEntity userEntity = new UserEntity();
|
||||
|
||||
userEntity.setUserName(userForm.getUserName());
|
||||
userEntity.setMailAddress(userForm.getMailAddress());
|
||||
|
||||
String passwordHashed = BCrypt.hashpw(userForm.getPassword(), BCrypt.gensalt());
|
||||
|
||||
userEntity.setPassword(passwordHashed);
|
||||
userEntity.setSecretQuestionAnswer(userForm.getSecretAnswer());
|
||||
userEntity.setBirthDate(userForm.getBirthDate());
|
||||
userEntity.setSaving(userForm.getSaving());
|
||||
userEntity.setBirthDate(userForm.getBirthDate());
|
||||
userEntity.setSaving(userForm.getSaving());
|
||||
userEntity.setAnnualIncome(userForm.getAnnualIncome());
|
||||
userEntity.setMonthlyBudget(userForm.getMonthlyBudget());
|
||||
|
||||
QuestionEntity questionEntity = questionRepository.findById(userForm.getSecretQuestionId()).orElse(null);
|
||||
|
||||
GoalEntity goalEntity = new GoalEntity();
|
||||
goalEntity.setTargetAmount(Integer.parseInt(String.valueOf(userForm.getGoalId())));
|
||||
|
||||
CourseEntity courseEntity = courseRepository.findById(courseId).orElse(null);
|
||||
|
||||
userEntity.setQuestionEntity(questionEntity);
|
||||
|
||||
userEntity.setCourseEntity(courseEntity);
|
||||
|
||||
userEntity.setDeleteFlag(0);
|
||||
|
||||
goalEntity.setUserEntity(userRepository.save(userEntity));
|
||||
|
||||
goalRepository.save(goalEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCourse(Long userId, Long courseId) {
|
||||
UserEntity userEntity = userRepository.findById(userId).orElseThrow();
|
||||
|
||||
CourseEntity courseEntity = courseRepository.findById(courseId).orElseThrow();
|
||||
|
||||
userEntity.setCourseEntity(courseEntity);
|
||||
|
||||
userRepository.save(userEntity);
|
||||
}
|
||||
|
||||
public UserModel findByUserId(Long userId) {
|
||||
|
||||
return UserModel.convertFrom(userRepository.findById(userId).get());
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,12 @@ import java.util.List;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
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.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
@@ -26,12 +29,19 @@ public class CategoryEntity {
|
||||
@Column(name = "category_id")
|
||||
private Long categoryId;
|
||||
|
||||
@Column(name = "category_name", nullable = false)
|
||||
@Column(name = "category_name", nullable = false, length = 50)
|
||||
private String categoryName;
|
||||
|
||||
@Column(name = "transaction_type", nullable = false)
|
||||
private Integer transactionType;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id")
|
||||
private UserEntity userEntity;
|
||||
|
||||
@Column(name = "delete_flag")
|
||||
private Integer deleteFlag;
|
||||
|
||||
@OneToMany(mappedBy = "categoryEntity")
|
||||
private List<TransactionEntity> transactionEntity;
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -28,16 +27,13 @@ public class CourseEntity {
|
||||
@Column(name = "course_id")
|
||||
private Long courseId;
|
||||
|
||||
@Column(name = "course_name", nullable = false)
|
||||
@Column(name = "course_name", nullable = false, length = 50)
|
||||
private String courseName;
|
||||
|
||||
|
||||
@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;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.example.demo.app.infra.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
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.Table;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@Table(name = "fixed_cost_t")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FixedCostEntity {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "fixed_cost_id")
|
||||
private Long fixedCostId;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id")
|
||||
private UserEntity userEntity;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "category_id")
|
||||
private CategoryEntity categoryEntity;
|
||||
|
||||
@Column(name = "fixed_cost_name", nullable = false, length = 50)
|
||||
private String fixedCostName;
|
||||
|
||||
@Column(name = "amount", nullable = false)
|
||||
private Integer amount;
|
||||
}
|
||||
@@ -4,10 +4,12 @@ import java.time.LocalDate;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -27,21 +29,22 @@ public class GoalEntity {
|
||||
private Long goalId;
|
||||
|
||||
@Column(name = "goal_title", nullable = true)
|
||||
private String goalTitle;
|
||||
private String goalTitle = "名前を設定してください";
|
||||
|
||||
@Column(name = "goal_subtitle", nullable = true)
|
||||
private String goalSubtitle;
|
||||
private String goalSubtitle = "説明を書いてください";
|
||||
|
||||
@Column(name = "target_amount", nullable = false)
|
||||
@Column(name = "target_amount", nullable = true)
|
||||
private Integer targetAmount;
|
||||
|
||||
@Column(name = "deadline", nullable = false)
|
||||
private LocalDate deadline;
|
||||
@Column(name = "deadline", nullable = true)
|
||||
private LocalDate deadline = LocalDate.now().plusYears(1L);
|
||||
|
||||
@Column(name = "goal_complete", nullable = false)
|
||||
private Integer goalComplete;
|
||||
private Integer goalComplete = 0;
|
||||
|
||||
@OneToOne(mappedBy = "goalEntity")
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "user_id")
|
||||
private UserEntity userEntity;
|
||||
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -31,7 +30,7 @@ public class UserEntity {
|
||||
@Column(name = "user_id")
|
||||
private Long userId;
|
||||
|
||||
@Column(name = "user_name", nullable = false)
|
||||
@Column(name = "user_name", nullable = false, length = 100)
|
||||
private String userName;
|
||||
|
||||
@Column(name = "mail_address", nullable = false)
|
||||
@@ -40,7 +39,7 @@ public class UserEntity {
|
||||
@Column(name = "password", nullable = false)
|
||||
private String password;
|
||||
|
||||
@Column(name = "secret_answer", nullable = false)
|
||||
@Column(name = "secret_answer", nullable = false, length = 100)
|
||||
private String secretQuestionAnswer;
|
||||
|
||||
@Column(name = "birth_date", nullable = false)
|
||||
@@ -65,9 +64,8 @@ public class UserEntity {
|
||||
@JoinColumn(name = "secret_question_id")
|
||||
private QuestionEntity questionEntity;
|
||||
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "goal_id")
|
||||
private GoalEntity goalEntity;
|
||||
@OneToMany(mappedBy = "userEntity")
|
||||
private List<GoalEntity> goalEntityList;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "course_id")
|
||||
|
||||
@@ -3,6 +3,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.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import com.example.demo.app.domain.model.CourseInfoModel;
|
||||
@@ -29,4 +30,8 @@ public interface AllocationRepository extends JpaRepository<AllocationEntity, Al
|
||||
+ " a.categoryEntity.categoryId ASC ")
|
||||
List<CourseInfoModel> findAllJoinedAllocation();
|
||||
|
||||
@Modifying
|
||||
@Query("delete from AllocationEntity a where a.courseEntity.courseId = :courseId")
|
||||
void deleteByCourseId(Long courseId);
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
@@ -12,4 +14,13 @@ public interface CategoryRepository extends JpaRepository<CategoryEntity, Long>
|
||||
@Query("select c from CategoryEntity c where c.categoryName = :categoryName")
|
||||
public CategoryEntity findByCategoryName(@Param("categoryName") String categoryName);
|
||||
|
||||
@Query("select c from CategoryEntity c inner join TransactionEntity t on c.categoryId = t.categoryEntity.categoryId where t.transactionId = :transactionId")
|
||||
public CategoryEntity findByTransactionId(Long transactionId);
|
||||
|
||||
@Query("select c from CategoryEntity c where c.userEntity.userId = :userId")
|
||||
public List<CategoryEntity> findByUserId(Long userId);
|
||||
|
||||
@Query("select c from CategoryEntity c where c.userEntity.userId is null")
|
||||
public List<CategoryEntity> findAllExceptCustom();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.example.demo.app.infra.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import com.example.demo.app.infra.entity.CourseOwnerEntity;
|
||||
|
||||
public interface CourseOwnerRepository extends JpaRepository<CourseOwnerEntity, Long>{
|
||||
|
||||
@Modifying
|
||||
@Query("delete from CourseOwnerEntity c where c.courseEntity.courseId = :courseId")
|
||||
public void deleteByCourseId(Long courseId);
|
||||
|
||||
}
|
||||
@@ -1,9 +1,24 @@
|
||||
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;
|
||||
|
||||
import com.example.demo.app.infra.entity.CourseEntity;
|
||||
|
||||
public interface CourseRepository extends JpaRepository<CourseEntity, Long> {
|
||||
|
||||
@Query("SELECT c FROM CourseEntity c WHERE c.courseId = :courseId ")
|
||||
public CourseEntity findByCourseId(Long courseId);
|
||||
|
||||
@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();
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
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;
|
||||
|
||||
import com.example.demo.app.infra.entity.FixedCostEntity;
|
||||
|
||||
public interface FixedCostRepository extends JpaRepository<FixedCostEntity, Long> {
|
||||
|
||||
@Query("select f from FixedCostEntity f where f.userEntity.userId = :userId")
|
||||
public List<FixedCostEntity> findByUserId(Long userId);
|
||||
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.example.demo.app.infra.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.example.demo.app.infra.entity.GoalEntity;
|
||||
@@ -8,4 +12,11 @@ import com.example.demo.app.infra.entity.GoalEntity;
|
||||
@Repository
|
||||
public interface GoalRepository extends JpaRepository<GoalEntity, Long> {
|
||||
|
||||
@Query("select g from GoalEntity g where g.userEntity.userId = :userId")
|
||||
public List<GoalEntity> findAllByUserId(Long userId);
|
||||
|
||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||
@Query("update GoalEntity g set g.goalComplete = 1 where g.goalId = :goalId")
|
||||
public int updateCompleteByGoalId(Long goalId);
|
||||
|
||||
}
|
||||
@@ -7,21 +7,33 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import com.example.demo.app.infra.entity.TransactionEntity;
|
||||
import com.example.demo.app.presentation.form.Expense;
|
||||
import com.example.demo.app.presentation.form.Income;
|
||||
|
||||
public interface TransactionRepository extends JpaRepository<TransactionEntity, Long> {
|
||||
|
||||
@Query("select t from TransactionEntity t where t.userEntity.userId = :userId and t.transactionDate = :transactionDate")
|
||||
@Query("select t from TransactionEntity t where t.userEntity.userId = :userId and t.transactionDate = :todayDate")
|
||||
public List<TransactionEntity> findByUserIdAndDate(LocalDate todayDate, Long userId);
|
||||
|
||||
@Query("select t from TransactionEntity t where (t.transactionDate between :startDate and :endDate) and (t.userEntity.userId = :userId) order by t.transactionDate asc")
|
||||
public List<TransactionEntity> findAllByDateAndUserId(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
|
||||
@Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryEntity.categoryId = c.categoryId where (t.userEntity.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 0")
|
||||
@Query("select coalesce(sum(t.amount), 0) from TransactionEntity t inner join CategoryEntity c on t.categoryEntity.categoryId = c.categoryId where (t.userEntity.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 0")
|
||||
public Integer findTotalExpense(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
|
||||
@Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryEntity.categoryId = c.categoryId where (t.userEntity.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 1")
|
||||
@Query("select coalesce(sum(t.amount), 0) from TransactionEntity t inner join CategoryEntity c on t.categoryEntity.categoryId = c.categoryId where (t.userEntity.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 1")
|
||||
public Integer findTotalIncome(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
|
||||
@Query("select sum(t.amount) from TransactionEntity t where t.userEntity.userId = :userId and t.categoryEntity.categoryId = :categoryId and t.transactionDate between :startDate and :endDate")
|
||||
@Query("select coalesce(sum(t.amount), 0) from TransactionEntity t where t.userEntity.userId = :userId and t.categoryEntity.categoryId = :categoryId and t.transactionDate between :startDate and :endDate")
|
||||
public Integer findCategoryExpense(LocalDate startDate, LocalDate endDate, Long userId, Long categoryId);
|
||||
|
||||
@Query("select new com.example.demo.app.presentation.form.Expense(t.transactionDate, coalesce(sum(t.amount), 0)) from TransactionEntity t inner join CategoryEntity c on t.categoryEntity.categoryId = c.categoryId where (t.userEntity.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 0 group by t.transactionDate order by t.transactionDate asc")
|
||||
public List<Expense> findTotalExpenseList(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
|
||||
@Query("select new com.example.demo.app.presentation.form.Income(t.transactionDate, coalesce(sum(t.amount), 0)) from TransactionEntity t inner join CategoryEntity c on t.categoryEntity.categoryId = c.categoryId where (t.userEntity.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 1 group by t.transactionDate order by t.transactionDate asc")
|
||||
public List<Income> findTotalIncomeList(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
|
||||
@Query("select coalesce(t.amount, 0) from TransactionEntity t where t.transactionId = :transactionId")
|
||||
public Integer findMoneyRecord(Long transactionId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,21 @@
|
||||
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;
|
||||
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;
|
||||
@@ -20,21 +27,49 @@ public class AnalysisController {
|
||||
|
||||
private final AnalysisService analysisService;
|
||||
|
||||
@GetMapping("/analysis")
|
||||
public String showAnalysis(Model model, HttpSession session) {
|
||||
@SessionCheck
|
||||
@GetMapping(TransitionTargetPageNameKeyword.ANALYSIS)
|
||||
public String showAnalysis(
|
||||
@RequestParam(required = false) Integer year,
|
||||
@RequestParam(required = false) Integer month,
|
||||
Model model,
|
||||
HttpSession session) {
|
||||
|
||||
//ログインユーザーの取得(セッション)
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
//初期年月表示
|
||||
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(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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import com.example.demo.app.domain.model.AuthenticationModel;
|
||||
import com.example.demo.app.domain.service.AuthenticationService;
|
||||
import com.example.demo.app.infra.repository.QuestionRepository;
|
||||
import com.example.demo.app.presentation.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;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class AuthenticationController {
|
||||
|
||||
private final AuthenticationService authenticationService;
|
||||
private final QuestionRepository questionRepository;
|
||||
|
||||
@GetMapping(TransitionTargetPageNameKeyword.AUTHENTICATION)
|
||||
public String showAuthentication(Model model) {
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.AUTHENTICATION_FORM, new AuthenticationForm());
|
||||
model.addAttribute(PageReturnAttributeKeyword.QUESTION_LIST, questionRepository.findAll());
|
||||
|
||||
return TransitionTargetPageNameKeyword.AUTHENTICATION_HTML;
|
||||
}
|
||||
|
||||
@PostMapping(TransitionTargetPageNameKeyword.AUTHENTICATION)
|
||||
public String authenticate(
|
||||
AuthenticationForm authenticationForm,
|
||||
Model model,
|
||||
HttpSession session) {
|
||||
|
||||
AuthenticationModel authenticationModel =
|
||||
authenticationService.authenticate(authenticationForm);
|
||||
|
||||
if (authenticationModel == null) {
|
||||
model.addAttribute(PageReturnAttributeKeyword.ERROR_MESSAGE, "認証情報が正しくありません。");
|
||||
model.addAttribute(PageReturnAttributeKeyword.QUESTION_LIST, questionRepository.findAll());
|
||||
|
||||
return TransitionTargetPageNameKeyword.AUTHENTICATION_HTML;
|
||||
}
|
||||
|
||||
session.setAttribute(
|
||||
PageReturnAttributeKeyword.PASSWOR_RESET_USER_ID,
|
||||
authenticationModel.getUserId());
|
||||
|
||||
model.addAttribute(
|
||||
PageReturnAttributeKeyword.PASSWOR_RESET_FORM,
|
||||
new PasswordResetForm());
|
||||
|
||||
return TransitionTargetPageNameKeyword.PASSWORD_RESET_HTML;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import com.example.demo.app.domain.model.LoginModel;
|
||||
import com.example.demo.app.domain.service.CategoryService;
|
||||
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 lombok.RequiredArgsConstructor;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class CategoryController {
|
||||
|
||||
private final CategoryService categoryService;
|
||||
|
||||
|
||||
@GetMapping(TransitionTargetPageNameKeyword.CATEGORY_LIST)
|
||||
public String categoryListGet(Model model, HttpSession session) {
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
List<CategoryForm> categoryFormList = CategoryForm.convertFrom(categoryService.findAllByuserId(loginUser.getUserId()));
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.CATEGORY_FORM_LIST, categoryFormList);
|
||||
|
||||
return TransitionTargetPageNameKeyword.CATEGORY_LIST_HTML;
|
||||
}
|
||||
|
||||
@GetMapping(TransitionTargetPageNameKeyword.CATEGORY_CREATE)
|
||||
public String categoryCreateGet(@ModelAttribute CategoryForm categoryForm) {
|
||||
|
||||
return TransitionTargetPageNameKeyword.CATEGORY_CREATE_HTML;
|
||||
}
|
||||
|
||||
@PostMapping(TransitionTargetPageNameKeyword.CATEGORY_CREATE)
|
||||
public String categoryCreatePost(@ModelAttribute CategoryForm categoryForm, HttpSession session) {
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
|
||||
categoryService.save(CategoryForm.convertTo(categoryForm), loginUser.getUserId());
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.CATEGORY_LIST;
|
||||
}
|
||||
|
||||
@GetMapping(TransitionTargetPageNameKeyword.CATEGORY_UPDATE)
|
||||
public String categoryUpdateGet(Model model, Long categoryId) {
|
||||
|
||||
CategoryForm categoryForm = CategoryForm.convertFrom(categoryService.findOne(categoryId));
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.CATEGORY_ID, categoryId);
|
||||
model.addAttribute(PageReturnAttributeKeyword.CATEGORY_FORM, categoryForm);
|
||||
|
||||
return TransitionTargetPageNameKeyword.CATEGORY_UPDATE_HTML;
|
||||
}
|
||||
|
||||
@PostMapping(TransitionTargetPageNameKeyword.CATEGORY_UPDATE)
|
||||
public String categoryUpdatePost(@ModelAttribute CategoryForm categoryForm, HttpSession session, Long categoryId) {
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
categoryForm.setCategoryId(categoryId);
|
||||
|
||||
categoryService.save(CategoryForm.convertTo(categoryForm), loginUser.getUserId());
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.CATEGORY_LIST;
|
||||
}
|
||||
|
||||
@PostMapping(TransitionTargetPageNameKeyword.CATEGORY_DELETE)
|
||||
public String categoryDeletePost(Long categoryId) {
|
||||
|
||||
categoryService.delete(categoryId);
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.CATEGORY_LIST;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,52 +1,157 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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 org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import com.example.demo.aop.aspect.SessionCheck;
|
||||
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;
|
||||
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.AllocationFormList;
|
||||
import com.example.demo.app.presentation.form.CourseForm;
|
||||
import com.example.demo.app.presentation.form.CourseInfoForm;
|
||||
import com.example.demo.app.presentation.form.UserForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class CourseController {
|
||||
|
||||
private final static Logger LOGGER = Logger.getLogger(CourseController.class.getName());
|
||||
// エラーメッセージ用の定数フィールド
|
||||
private final static String SEVERE_ERROR_MESSAGE = "エラーが発生しました!";
|
||||
|
||||
// private final HttpSession httpSession;
|
||||
private final CourseService courseService;
|
||||
private final CourseInfoService courseInfoService;
|
||||
private final UserService userService;
|
||||
private final AllocationService allocationService;
|
||||
|
||||
@PostMapping(TransitionTargetPageNameKeyword.SHOW_SELECT_COURSE)
|
||||
public String showSelectCourse(@ModelAttribute UserForm userForm, Model model, HttpSession session) {
|
||||
|
||||
final String MODE = "regist";
|
||||
final String DEFAULT = "バランスコース";
|
||||
|
||||
@GetMapping("/select-course")
|
||||
public String select(Model model) {
|
||||
session.setAttribute(PageReturnAttributeKeyword.USER_FORM, userForm);
|
||||
model.addAttribute(PageReturnAttributeKeyword.MODE, MODE);
|
||||
model.addAttribute(PageReturnAttributeKeyword.CURRENT_COURSE_ID, courseService.findByName(DEFAULT));
|
||||
|
||||
//try {
|
||||
model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll()));
|
||||
model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
||||
model.addAttribute(PageReturnAttributeKeyword.COURSE_LIST,
|
||||
CourseForm.convertFrom(courseService.findAllByNull()));
|
||||
model.addAttribute(PageReturnAttributeKeyword.COURSE_INFO_LIST,
|
||||
CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
||||
|
||||
return "select_course";
|
||||
return TransitionTargetPageNameKeyword.SELECT_COURSE_HTML;
|
||||
|
||||
//} catch (Exception e) {
|
||||
// // ログイン情報の破棄
|
||||
// httpSession.invalidate();
|
||||
//
|
||||
// e.printStackTrace();
|
||||
//
|
||||
// // エラーログ出力
|
||||
// LOGGER.log(Level.SEVERE, SEVERE_ERROR_MESSAGE, e);
|
||||
// // エラー画面遷移
|
||||
// return null;
|
||||
// }
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping(TransitionTargetPageNameKeyword.COURSE)
|
||||
public String showChangeCourse(Model model, HttpSession session) {
|
||||
|
||||
final String MODE = "change";
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
Long userId = loginUser.getUserId();
|
||||
|
||||
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(courseModelList));
|
||||
model.addAttribute(PageReturnAttributeKeyword.COURSE_INFO_LIST,
|
||||
CourseInfoForm.convertFrom(courseInfoService.findAll()));
|
||||
|
||||
return TransitionTargetPageNameKeyword.SELECT_COURSE_HTML;
|
||||
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping(TransitionTargetPageNameKeyword.CHANGE)
|
||||
public String changeCourse(@RequestParam Long courseId, HttpSession httpSession) {
|
||||
|
||||
LoginModel loginUser = (LoginModel) httpSession.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
userService.updateCourse(loginUser.getUserId(), courseId);
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.MENU;
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping(TransitionTargetPageNameKeyword.COURSE_CREATE)
|
||||
public String createCourseGet(@ModelAttribute CourseForm courseForm, HttpSession session) {
|
||||
|
||||
return TransitionTargetPageNameKeyword.COURSE_CREATE_HTML;
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping(TransitionTargetPageNameKeyword.COURSE_CREATE_RATIO)
|
||||
public String createCourse(@ModelAttribute CourseForm courseForm,
|
||||
@ModelAttribute AllocationFormList allocationFormList,
|
||||
HttpSession session, Model model) {
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
model.addAttribute("courseForm", courseForm);
|
||||
|
||||
return TransitionTargetPageNameKeyword.COURSE_CREATE_RATIO_HTML;
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping(TransitionTargetPageNameKeyword.COURSE_CREATE)
|
||||
public String createCoursePost(@ModelAttribute CourseForm courseForm,
|
||||
@ModelAttribute AllocationFormList allocationFormList, HttpSession session) {
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
courseService.save(CourseForm.convertTo(courseForm), loginUser.getUserId(), allocationFormList);
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.COURSE;
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping("/course/delete")
|
||||
public String createCoursePost(@RequestParam Long courseId, HttpSession session, Model model) {
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
System.out.println("**********************cousrId: " + courseId);
|
||||
String condition = courseService.deleteCourse(courseId, loginUser.getUserId());
|
||||
|
||||
if (condition.equals("selected")) {
|
||||
|
||||
model.addAttribute("message", "適用中のコースは選べません");
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.COURSE;
|
||||
|
||||
} else if (condition.equals("original")) {
|
||||
model.addAttribute("message", "既存のデータは削除できません");
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.COURSE;
|
||||
} else if (condition.equals("ok")) {
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.COURSE;
|
||||
}
|
||||
model.addAttribute("message", "エラーが発生しました");
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.COURSE;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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(TransitionTargetPageNameKeyword.ERROR)
|
||||
public String showError() {
|
||||
return TransitionTargetPageNameKeyword.ERROR_HTML;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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.service.CategoryService;
|
||||
import com.example.demo.app.domain.service.FixedCostService;
|
||||
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.FixedCostForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class FixedCostController {
|
||||
|
||||
private final FixedCostService fixedCostService;
|
||||
private final CategoryService categoryService;
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping(TransitionTargetPageNameKeyword.FIXED_COST_LIST)
|
||||
public String getFixedCostList(
|
||||
HttpSession session, Model model, LocalDate today) {
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
if (today == null) {
|
||||
today = (LocalDate) session.getAttribute(PageReturnAttributeKeyword.TODAY);
|
||||
}
|
||||
|
||||
List<FixedCostForm> fixedCostFormList = FixedCostForm.convertFrom(fixedCostService.findAllByUserId(loginUser.getUserId()));
|
||||
|
||||
fixedCostFormList.forEach(fixedCostForm -> fixedCostForm.setCategoryName(categoryService.findOne(fixedCostForm.getCategoryId()).getCategoryName()));
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.FIXED_COST_FORM_LIST, fixedCostFormList);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.TODAY, today);
|
||||
|
||||
return TransitionTargetPageNameKeyword.FIXED_COST_HTML;
|
||||
}
|
||||
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping(TransitionTargetPageNameKeyword.FIXED_COST_CREATE)
|
||||
public String getFixedCostCreate(
|
||||
HttpSession session, @ModelAttribute FixedCostForm fixedCostForm, Model model, LocalDate today) {
|
||||
|
||||
List<CategoryForm> categoryFormList = CategoryForm.convertFrom(categoryService.findAll());
|
||||
|
||||
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.TODAY, today);
|
||||
|
||||
|
||||
return TransitionTargetPageNameKeyword.FIXED_COST_CREATE_HTML;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping(TransitionTargetPageNameKeyword.FIXED_COST_CREATE)
|
||||
public String postFixedCostCreate(
|
||||
HttpSession session, @ModelAttribute FixedCostForm fixedCostForm, Model model, LocalDate today) {
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
fixedCostForm.setUserId(loginUser.getUserId());
|
||||
|
||||
fixedCostService.save(FixedCostForm.convertTo(fixedCostForm));
|
||||
|
||||
session.setAttribute(PageReturnAttributeKeyword.TODAY, today);
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.FIXED_COST_LIST;
|
||||
}
|
||||
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping(TransitionTargetPageNameKeyword.FIXED_COST_DELETE)
|
||||
public String postFixedCostDelete(Long fixedCostId, LocalDate today, HttpSession session) {
|
||||
|
||||
fixedCostService.delete(fixedCostId);
|
||||
|
||||
session.setAttribute(PageReturnAttributeKeyword.TODAY, today);
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.FIXED_COST_LIST;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,61 +1,351 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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.PathVariable;
|
||||
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.CategoryService;
|
||||
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.GoalForm;
|
||||
import com.example.demo.app.presentation.form.MonthlyAchievementForm;
|
||||
import com.example.demo.app.presentation.form.MonthlySavingForm;
|
||||
import com.example.demo.app.presentation.form.TransactionForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/goal")
|
||||
@RequestMapping(TransitionTargetPageNameKeyword.GOAL)
|
||||
public class GoalController {
|
||||
|
||||
private final GoalService goalService;
|
||||
private final TransactionService transactionService;
|
||||
private final UserService userService;
|
||||
private final CategoryService categoryService;
|
||||
|
||||
@GetMapping("/{goalId}")
|
||||
public String getGoal(@PathVariable Long goalId, Model model) {
|
||||
@SessionCheck
|
||||
@GetMapping("")
|
||||
public String getGoal(
|
||||
Model model,
|
||||
HttpSession session,
|
||||
Long goalId) {
|
||||
|
||||
GoalModel goalModel = goalService.getGoalById(goalId);
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
GoalForm goalForm = GoalForm.convertFrom(goalModel);
|
||||
Long userId = loginUser.getUserId();
|
||||
|
||||
model.addAttribute("goalForm", goalForm);
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
return "goal_view";
|
||||
goalService.updateGoalComplete(userId);
|
||||
|
||||
List<GoalModel> goalModelList = goalService.getGoalByUserId(userId);
|
||||
|
||||
List<GoalForm> goalFormList1 = GoalForm.convertFrom(goalModelList);
|
||||
|
||||
List<GoalForm> goalFormList = goalFormList1.stream()
|
||||
.filter(goalForm -> goalForm.getGoalComplete() == 0
|
||||
&& !goalForm.getDeadline().isBefore(today))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
model.addAttribute(
|
||||
PageReturnAttributeKeyword.GOAL_FORM_LIST,
|
||||
goalFormList);
|
||||
|
||||
model.addAttribute(
|
||||
PageReturnAttributeKeyword.ACHIEVEMENT_LIST,
|
||||
new ArrayList<MonthlyAchievementForm>());
|
||||
|
||||
if (goalFormList.isEmpty()) {
|
||||
return TransitionTargetPageNameKeyword.GOAL_VIEW_HTML;
|
||||
}
|
||||
|
||||
GoalForm graphGoal;
|
||||
|
||||
if (goalId == null) {
|
||||
|
||||
graphGoal = goalFormList.getFirst();
|
||||
|
||||
} else {
|
||||
|
||||
graphGoal = goalFormList.stream()
|
||||
.filter(goal -> goal.getGoalId().equals(goalId))
|
||||
.findFirst()
|
||||
.orElse(
|
||||
goalFormList.getFirst());
|
||||
}
|
||||
|
||||
model.addAttribute(
|
||||
PageReturnAttributeKeyword.GRAPH_GOAL,
|
||||
graphGoal);
|
||||
|
||||
int currentAmount = graphGoal.getCurrentAmount();
|
||||
|
||||
int targetAmount = graphGoal.getTargetAmount();
|
||||
|
||||
LocalDate startDate = LocalDate.of(
|
||||
LocalDate.now().getYear(),
|
||||
1,
|
||||
1);
|
||||
|
||||
Map<LocalDate, List<TransactionForm>> transactionFormMap = new HashMap<>();
|
||||
|
||||
transactionService
|
||||
.findAllByDate(
|
||||
startDate,
|
||||
today,
|
||||
userId)
|
||||
.forEach((date, list) -> {
|
||||
|
||||
List<TransactionForm> transactionFormList = list.stream()
|
||||
.map(transaction -> {
|
||||
|
||||
CategoryForm categoryForm = CategoryForm.convertFrom(
|
||||
categoryService.findOne(
|
||||
transaction.getCategoryId()));
|
||||
|
||||
return TransactionForm.convertFrom(
|
||||
transaction,
|
||||
categoryForm.getCategoryName(),
|
||||
transactionService.findTotalExpense(
|
||||
startDate,
|
||||
today,
|
||||
loginUser.getUserId()),
|
||||
transactionService.findTotalIncome(
|
||||
startDate,
|
||||
today,
|
||||
loginUser.getUserId()),
|
||||
categoryForm.getTransactionType());
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
transactionFormMap.put(
|
||||
date,
|
||||
transactionFormList);
|
||||
});
|
||||
|
||||
List<MonthlySavingForm> monthlySavingList = new ArrayList<>();
|
||||
|
||||
YearMonth startMonth = YearMonth.from(startDate);
|
||||
|
||||
YearMonth currentMonth = YearMonth.now();
|
||||
|
||||
YearMonth month = currentMonth;
|
||||
|
||||
while (!month.isBefore(startMonth)) {
|
||||
|
||||
int income = 0;
|
||||
int expense = 0;
|
||||
|
||||
for (Map.Entry<LocalDate, List<TransactionForm>> entry : transactionFormMap.entrySet()) {
|
||||
|
||||
YearMonth transactionMonth = YearMonth.from(entry.getKey());
|
||||
|
||||
if (!transactionMonth.equals(month)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (TransactionForm transaction : entry.getValue()) {
|
||||
|
||||
if (transaction.getAmount() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (transaction.getTransactionType() == 1) {
|
||||
|
||||
income += transaction.getAmount();
|
||||
|
||||
} else if (transaction.getTransactionType() == 0) {
|
||||
|
||||
expense += transaction.getAmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
monthlySavingList.add(
|
||||
new MonthlySavingForm(
|
||||
month,
|
||||
income,
|
||||
expense,
|
||||
currentAmount));
|
||||
|
||||
currentAmount = currentAmount
|
||||
- income
|
||||
+ expense;
|
||||
|
||||
month = month.minusMonths(1);
|
||||
}
|
||||
|
||||
Collections.reverse(
|
||||
monthlySavingList);
|
||||
|
||||
List<MonthlyAchievementForm> achievementList = new ArrayList<>();
|
||||
|
||||
for (MonthlySavingForm monthlySaving : monthlySavingList) {
|
||||
|
||||
int savingAmount = monthlySaving.getSaving();
|
||||
|
||||
int achievementRate = 0;
|
||||
|
||||
if (targetAmount > 0) {
|
||||
|
||||
achievementRate = (int) ((double) savingAmount
|
||||
/ targetAmount
|
||||
* 100);
|
||||
}
|
||||
|
||||
achievementList.add(
|
||||
new MonthlyAchievementForm(
|
||||
monthlySaving.getMonth(),
|
||||
savingAmount,
|
||||
achievementRate));
|
||||
}
|
||||
|
||||
model.addAttribute(
|
||||
PageReturnAttributeKeyword.ACHIEVEMENT_LIST,
|
||||
achievementList);
|
||||
|
||||
return TransitionTargetPageNameKeyword.GOAL_VIEW_HTML;
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping(TransitionTargetPageNameKeyword.EDIT)
|
||||
public String editGoal(Model model, HttpSession session, Long goalId) {
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
Long userId = loginUser.getUserId();
|
||||
|
||||
GoalForm goalForm = GoalForm.convertFrom(goalService.getGoalById(goalId));
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.GOAL_FORM, goalForm);
|
||||
return TransitionTargetPageNameKeyword.GOAL_EDIT_HTML;
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/{goalId}/edit")
|
||||
public String editGoal(@PathVariable Long goalId, Model model) {
|
||||
@SessionCheck
|
||||
@PostMapping(TransitionTargetPageNameKeyword.UPDATE)
|
||||
public String updateGoal(@ModelAttribute GoalForm goalForm, HttpSession session) {
|
||||
|
||||
GoalModel goalModel = goalService.getGoalById(goalId);
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
GoalForm goalForm = GoalForm.convertFrom(goalModel);
|
||||
Long userId = loginUser.getUserId();
|
||||
|
||||
model.addAttribute("goalForm", goalForm);
|
||||
|
||||
return "goal_edit";
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/update")
|
||||
public String updateGoal(@ModelAttribute GoalForm goalForm) {
|
||||
// // 本人の目標かどうかを確認してから更新する
|
||||
// GoalModel currentGoal = goalService.getGoalByUserId(userId);
|
||||
//
|
||||
// if (!currentGoal.getGoalId().equals(goalForm.getGoalId())) {
|
||||
// return "redirect:/goal"; // 他人のデータを更新しようとしたら弾く
|
||||
// }
|
||||
|
||||
GoalModel goalModel = GoalModel.convertFrom(goalForm);
|
||||
goalService.updateGoal(goalModel, userId);
|
||||
|
||||
goalService.updateGoal(goalModel);
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.GOAL;
|
||||
}
|
||||
|
||||
return "redirect:/goal/" + goalForm.getGoalId();
|
||||
@SessionCheck
|
||||
@GetMapping(TransitionTargetPageNameKeyword.CREATE)
|
||||
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);
|
||||
|
||||
System.out.println("************************currentAmount : " + currentAmount);
|
||||
|
||||
session.setAttribute(PageReturnAttributeKeyword.CURRENT_AMOUNT, currentAmount);
|
||||
|
||||
return TransitionTargetPageNameKeyword.GOAL_CREATE_HTML;
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping(TransitionTargetPageNameKeyword.CREATE)
|
||||
public String createGoalPost(@ModelAttribute GoalForm goalForm, HttpSession session, Model model) {
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
Long userId = loginUser.getUserId();
|
||||
|
||||
if (goalService.createGoal(GoalModel.convertFrom(goalForm), userId) == null) {
|
||||
model.addAttribute(PageReturnAttributeKeyword.MESSAGE, "現在所持金より高い金額を設定してください。");
|
||||
return TransitionTargetPageNameKeyword.GOAL_CREATE_HTML;
|
||||
}
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.GOAL;
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping(TransitionTargetPageNameKeyword.DELETE) // フラグ考慮してないため、今度修正必要
|
||||
public String deleteGoal(Long goalId, Long record) {
|
||||
|
||||
goalService.delete(goalId);
|
||||
|
||||
if (record == null) {
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.GOAL;
|
||||
} else {
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.GOAL
|
||||
+ TransitionTargetPageNameKeyword.RECORD;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping(TransitionTargetPageNameKeyword.RECORD)
|
||||
public String getRecord(HttpSession session, Model model) {
|
||||
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
Long userId = loginUser.getUserId();
|
||||
goalService.updateGoalComplete(userId);
|
||||
List<GoalModel> goalModelList = goalService.getGoalByUserId(userId);
|
||||
|
||||
List<GoalForm> goalFormList = GoalForm.convertFrom(goalModelList);
|
||||
|
||||
List<GoalForm> goalCompleteFormList = new ArrayList<>();
|
||||
|
||||
goalFormList.stream().forEach(goalForm -> {
|
||||
if (goalForm.getGoalComplete() == 1 || goalForm.getDeadline().isBefore(today)) {
|
||||
|
||||
goalForm.setStatus(
|
||||
goalForm.getGoalComplete() == 1
|
||||
? "達成"
|
||||
: "未達成");
|
||||
|
||||
goalCompleteFormList.add(goalForm);
|
||||
}
|
||||
});
|
||||
|
||||
model.addAttribute(
|
||||
PageReturnAttributeKeyword.GOAL_COMPLETE_FORM_LIST,
|
||||
goalCompleteFormList);
|
||||
|
||||
return TransitionTargetPageNameKeyword.GOAL_RECORD_HTML;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,17 +23,18 @@ public class LoginController {
|
||||
|
||||
private final LoginService loginService;
|
||||
|
||||
@GetMapping("/login")
|
||||
public String showLogin(Model model) {
|
||||
@GetMapping(TransitionTargetPageNameKeyword.LOGIN)
|
||||
public String showLogin(@ModelAttribute LoginForm loginForm, HttpSession session) {
|
||||
|
||||
model.addAttribute(
|
||||
"loginForm",
|
||||
new LoginForm());
|
||||
|
||||
return "login";
|
||||
if (session.getAttribute(SessionKeyword.LOGIN_USER) != null) {
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.MENU;
|
||||
}
|
||||
|
||||
@PostMapping("/login")
|
||||
return TransitionTargetPageNameKeyword.LOGIN_HTML;
|
||||
|
||||
}
|
||||
|
||||
@PostMapping(TransitionTargetPageNameKeyword.LOGIN)
|
||||
public String login(
|
||||
@ModelAttribute LoginForm loginForm,
|
||||
Model model,
|
||||
@@ -42,14 +46,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 "menu";
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.MENU;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import com.example.demo.app.domain.model.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;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class PasswordResetController {
|
||||
private final PasswordResetService passwordResetService;
|
||||
|
||||
@GetMapping(TransitionTargetPageNameKeyword.PASSWORD_RESET)
|
||||
public String showPasswordReset(Model model) {
|
||||
model.addAttribute(PageReturnAttributeKeyword.PASSWOR_RESET_FORM, new PasswordResetForm());
|
||||
return TransitionTargetPageNameKeyword.PASSWORD_RESET_HTML;
|
||||
}
|
||||
|
||||
@PostMapping(TransitionTargetPageNameKeyword.PASSWORD_RESET)
|
||||
public String resetPassword(
|
||||
PasswordResetForm passwordResetForm,
|
||||
Model model,
|
||||
HttpSession session) {
|
||||
|
||||
Long userId = (Long) session.getAttribute(PageReturnAttributeKeyword.PASSWOR_RESET_USER_ID);
|
||||
|
||||
if (userId == null) {
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
if (loginUser != null) {
|
||||
userId = loginUser.getUserId();
|
||||
}
|
||||
}
|
||||
|
||||
if (userId == null) {
|
||||
return TransitionTargetPageNameKeyword.REDIRECT +
|
||||
TransitionTargetPageNameKeyword.LOGIN;
|
||||
}
|
||||
|
||||
boolean isReset = passwordResetService.resetPassword(userId, passwordResetForm);
|
||||
|
||||
if (!isReset) {
|
||||
model.addAttribute(PageReturnAttributeKeyword.MESSAGE, "パスワードが一致しません。");
|
||||
return TransitionTargetPageNameKeyword.PASSWORD_RESET_HTML;
|
||||
}
|
||||
|
||||
session.removeAttribute(PageReturnAttributeKeyword.PASSWOR_RESET_USER_ID);
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
if (loginUser != null) {
|
||||
return TransitionTargetPageNameKeyword.REDIRECT +
|
||||
TransitionTargetPageNameKeyword.PROFILE;
|
||||
}
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT +
|
||||
TransitionTargetPageNameKeyword.LOGIN;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import com.example.demo.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;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class ProfileController {
|
||||
private final ProfileService profileService;
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping(TransitionTargetPageNameKeyword.PROFILE)
|
||||
public String profile(Model model, HttpSession session) {
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
ProfileModel profileModel = profileService.findOne(loginUser.getUserId());
|
||||
|
||||
ProfileForm profileForm = ProfileForm.convertForm(profileModel);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.PROFILE_FORM, profileForm);
|
||||
return TransitionTargetPageNameKeyword.PROFILE_HTML;
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@GetMapping(TransitionTargetPageNameKeyword.PROFILE_EDIT)
|
||||
public String showEditProfile(
|
||||
Model model,
|
||||
HttpSession session) {
|
||||
|
||||
LoginModel loginUser =
|
||||
(LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
ProfileModel profileModel =
|
||||
profileService.findOne(loginUser.getUserId());
|
||||
|
||||
ProfileEditForm profileEditForm =
|
||||
new ProfileEditForm(
|
||||
profileModel.getUserName(),
|
||||
profileModel.getMailAddress(),
|
||||
profileModel.getBirthDate(),
|
||||
profileModel.getSaving(),
|
||||
profileModel.getAnnualIncome(),
|
||||
profileModel.getMonthlyBudget());
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.PROFILE_EDIT_FORM, profileEditForm);
|
||||
return TransitionTargetPageNameKeyword.PROFILE_EDIT_HTML;
|
||||
}
|
||||
|
||||
@PostMapping(TransitionTargetPageNameKeyword.PROFILE_EDIT)
|
||||
public String updateProfile(
|
||||
@ModelAttribute ProfileEditForm profileEditForm,
|
||||
HttpSession session) {
|
||||
|
||||
LoginModel loginUser =
|
||||
(LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
profileService.update(
|
||||
loginUser.getUserId(),
|
||||
profileEditForm);
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.PROFILE;
|
||||
}
|
||||
|
||||
@PostMapping(TransitionTargetPageNameKeyword.WITHDRAW)
|
||||
public String withdraw(HttpSession session) {
|
||||
|
||||
LoginModel loginUser =
|
||||
(LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
profileService.withdraw(loginUser.getUserId());
|
||||
|
||||
session.invalidate();
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.LOGIN;
|
||||
}
|
||||
|
||||
|
||||
@PostMapping(TransitionTargetPageNameKeyword.LOGOUT)
|
||||
public String logout(HttpSession session) {
|
||||
session.invalidate();
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.LOGIN;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -15,11 +18,23 @@ 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.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;
|
||||
import com.example.demo.app.presentation.form.GoalForm;
|
||||
import com.example.demo.app.presentation.form.Income;
|
||||
import com.example.demo.app.presentation.form.TransactionForm;
|
||||
import com.example.demo.app.presentation.form.UserForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -29,102 +44,422 @@ public class TransactionController {
|
||||
|
||||
private final TransactionService transactionService;
|
||||
private final CategoryService categoryService;
|
||||
// 一覧画面
|
||||
private final GoalService goalService;
|
||||
private final UserService userService;
|
||||
private final FixedCostService fixedCostService;
|
||||
|
||||
@GetMapping("/transaction/list")
|
||||
public String transactionList(@RequestParam(required = false) LocalDate startDates,
|
||||
@RequestParam(required = false) LocalDate endDates, Model model,
|
||||
// 一覧画面
|
||||
@SessionCheck
|
||||
@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) {
|
||||
|
||||
LocalDate startDate = (startDates == null) ? LocalDate.now().withDayOfMonth(1) : startDates;
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
LocalDate endDate = (endDates == null) ? LocalDate.now().withDayOfMonth(LocalDate.now().lengthOfMonth())
|
||||
: endDates;
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
|
||||
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 -> {
|
||||
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());
|
||||
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("transactionFormMap", transactionFormMap);
|
||||
model.addAttribute(PageReturnAttributeKeyword.YEAR, year);
|
||||
model.addAttribute(PageReturnAttributeKeyword.MONTH, month);
|
||||
|
||||
return "transaction_list";
|
||||
model.addAttribute(PageReturnAttributeKeyword.PREVIOUS_YEAR, previousYear);
|
||||
model.addAttribute(PageReturnAttributeKeyword.PREVIOUS_MONTH, previousMonth);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.NEXT_YEAR, nextYear);
|
||||
model.addAttribute(PageReturnAttributeKeyword.NEXT_MONTH, nextMonth);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.TRANSACTION_FORM_MAP, transactionFormMap);
|
||||
|
||||
return TransitionTargetPageNameKeyword.TRANSACTION_LIST_HTML;
|
||||
}
|
||||
|
||||
// 詳細画面
|
||||
@GetMapping("/transaction/detail")
|
||||
@SessionCheck
|
||||
@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()
|
||||
.map(transaction -> {
|
||||
TransactionForm transactionForm = TransactionForm.convertFrom(
|
||||
|
||||
int type = CategoryForm.convertFrom(categoryService.findOne(transaction.getCategoryId()))
|
||||
.getTransactionType();
|
||||
|
||||
TransactionForm transactionForm;
|
||||
if (type == 1) {
|
||||
|
||||
transactionForm = TransactionForm.convertFrom(
|
||||
transaction,
|
||||
CategoryForm.convertFrom(categoryService.findOne(transaction.getCategoryId()))
|
||||
.getCategoryName(),
|
||||
transactionService.findTotalexpense(todayDate, todayDate, loginUser.getUserId()),
|
||||
transactionService.findTotalIncome(todayDate, todayDate, loginUser.getUserId()),
|
||||
0,
|
||||
transactionService.findMoneyRecord(transaction.getTransactionId()),
|
||||
type);
|
||||
|
||||
} else if (type == 0) {
|
||||
transactionForm = TransactionForm.convertFrom(
|
||||
transaction,
|
||||
CategoryForm.convertFrom(categoryService.findOne(transaction.getCategoryId()))
|
||||
.getTransactionType());
|
||||
.getCategoryName(),
|
||||
transactionService.findMoneyRecord(transaction.getTransactionId()),
|
||||
0,
|
||||
type);
|
||||
} else {
|
||||
transactionForm = TransactionForm.convertFrom(
|
||||
transaction,
|
||||
CategoryForm.convertFrom(categoryService.findOne(transaction.getCategoryId()))
|
||||
.getCategoryName(),
|
||||
0,
|
||||
0,
|
||||
type);
|
||||
}
|
||||
|
||||
return transactionForm;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
model.addAttribute("transactionFormList", transactionFormList);
|
||||
model.addAttribute(PageReturnAttributeKeyword.TODAY, todayDate);
|
||||
model.addAttribute(PageReturnAttributeKeyword.TRANSACTION_FORM_LIST, transactionFormList);
|
||||
|
||||
return "";
|
||||
return TransitionTargetPageNameKeyword.TRANSACTION_DETAIL_HTML;
|
||||
}
|
||||
|
||||
@GetMapping("/transaction/create")
|
||||
public String createOneGet(@ModelAttribute TransactionForm transactionForm) {
|
||||
@SessionCheck
|
||||
@GetMapping(TransitionTargetPageNameKeyword.TRANSACTION_CREATE)
|
||||
public String createOneGet(@RequestParam(defaultValue = "") LocalDate today,
|
||||
Long fixedCostId,
|
||||
Model model, HttpSession session) {
|
||||
|
||||
return "";
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
if (today == null) {
|
||||
today = LocalDate.now();
|
||||
}
|
||||
TransactionForm transactionForm = new TransactionForm();
|
||||
transactionForm.setTransactionDate(today);
|
||||
if (fixedCostId != null) {
|
||||
FixedCostForm fixedCostForm = FixedCostForm.convertFrom(fixedCostService.findById(fixedCostId));
|
||||
transactionForm.setCategoryId(fixedCostForm.getCategoryId());
|
||||
transactionForm.setAmount(fixedCostForm.getAmount());
|
||||
transactionForm.setTransactionType(CategoryForm
|
||||
.convertFrom(categoryService.findOne(fixedCostForm.getCategoryId())).getTransactionType());
|
||||
}
|
||||
|
||||
@PostMapping("/transaction/create")
|
||||
public String createOnePost(@ModelAttribute TransactionForm transactionForm, Model model) {
|
||||
List<CategoryForm> categoryFormList = new ArrayList<>(
|
||||
CategoryForm.convertFrom(categoryService.findAllExceptCustom()));
|
||||
|
||||
List<CategoryForm> categoryFormCustomList = CategoryForm
|
||||
.convertFrom(categoryService.findAllByuserId(loginUser.getUserId()));
|
||||
|
||||
if (!categoryFormCustomList.isEmpty()) {
|
||||
for (CategoryForm form : categoryFormCustomList) {
|
||||
categoryFormList.add(form);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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(SessionKeyword.T_TYPE, String.valueOf(transactionForm.getTransactionType()));
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.CATEGORY_FORM_LIST, categoryFormList);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.TODAY, today.format(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||
|
||||
return TransitionTargetPageNameKeyword.TRANSACTION_CREATE_HTML;
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping(TransitionTargetPageNameKeyword.TRANSACTION_CREATE)
|
||||
public String createOnePost(@ModelAttribute TransactionForm transactionForm, @RequestParam LocalDate today,
|
||||
Model model,
|
||||
HttpSession session) {
|
||||
|
||||
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 "";
|
||||
return TransitionTargetPageNameKeyword.REDIRECT +
|
||||
TransitionTargetPageNameKeyword.TRANSACTION_DETAIL +
|
||||
TransitionTargetPageNameKeyword.INTERROGATION +
|
||||
TransitionTargetPageNameKeyword.TODAY_DATES +
|
||||
TransitionTargetPageNameKeyword.EQUAL +
|
||||
transactionForm.getTransactionDate();
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("/transaction/update")
|
||||
public String updateOneGet(@ModelAttribute TransactionForm transactionForm) {
|
||||
@SessionCheck
|
||||
@GetMapping(TransitionTargetPageNameKeyword.TRANSACTION_UPDATE)
|
||||
public String updateOneGet(@RequestParam Long transactionId, @RequestParam(defaultValue = "") LocalDate today,
|
||||
Model model, HttpSession session) {
|
||||
|
||||
return "";
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
if (today == null) {
|
||||
today = LocalDate.now();
|
||||
}
|
||||
|
||||
@PostMapping("/transaction/update")
|
||||
public String updateOnePost(@ModelAttribute TransactionForm transactionForm, Model model) {
|
||||
List<CategoryForm> categoryFormList = new ArrayList<>(
|
||||
CategoryForm.convertFrom(categoryService.findAllExceptCustom()));
|
||||
|
||||
List<CategoryForm> categoryFormCustomList = CategoryForm
|
||||
.convertFrom(categoryService.findAllByuserId(loginUser.getUserId()));
|
||||
|
||||
if (!categoryFormCustomList.isEmpty()) {
|
||||
for (CategoryForm form : categoryFormCustomList) {
|
||||
categoryFormList.add(form);
|
||||
}
|
||||
}
|
||||
|
||||
TransactionForm transactionForm = TransactionForm.convertFrom(
|
||||
transactionService.findByTransactionId(transactionId),
|
||||
CategoryForm.convertFrom(categoryService.findByTransactionId(transactionId)).getCategoryName(),
|
||||
transactionService.findMoneyRecord(transactionId),
|
||||
transactionService.findMoneyRecord(transactionId),
|
||||
CategoryForm.convertFrom(categoryService.findByTransactionId(transactionId)).getTransactionType());
|
||||
|
||||
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_ID, transactionId);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.TRANSACTION_FORM, transactionForm);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.CATEGORY_FORM_LIST, categoryFormList);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.TODAY, today);
|
||||
|
||||
session.setAttribute(SessionKeyword.T_TYPE, transactionForm.getTransactionType());
|
||||
|
||||
return TransitionTargetPageNameKeyword.TRANSACTION_UPDATE_HTML;
|
||||
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping(TransitionTargetPageNameKeyword.TRANSACTION_UPDATE)
|
||||
public String updateOnePost(@RequestParam Long transactionId, @ModelAttribute TransactionForm transactionForm,
|
||||
@RequestParam LocalDate today, Model model,
|
||||
HttpSession session) {
|
||||
|
||||
LoginModel loginUser = (LoginModel) session.getAttribute(SessionKeyword.LOGIN_USER);
|
||||
|
||||
transactionForm.setUserId(loginUser.getUserId());
|
||||
transactionForm.setTransactionId(transactionId);
|
||||
|
||||
if (transactionService.updateTransaction(TransactionForm.convertTo(transactionForm)) != 0) {
|
||||
return "error";
|
||||
return TransitionTargetPageNameKeyword.ERROR_HTML;
|
||||
}
|
||||
|
||||
return "";
|
||||
return TransitionTargetPageNameKeyword.REDIRECT +
|
||||
TransitionTargetPageNameKeyword.TRANSACTION_DETAIL +
|
||||
TransitionTargetPageNameKeyword.INTERROGATION +
|
||||
TransitionTargetPageNameKeyword.TODAY_DATES +
|
||||
TransitionTargetPageNameKeyword.EQUAL +
|
||||
transactionForm.getTransactionDate();
|
||||
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@PostMapping(TransitionTargetPageNameKeyword.TRANSACTION_DELETE)
|
||||
public String deleteOne(@RequestParam Long transactionId, @RequestParam LocalDate today) {
|
||||
|
||||
transactionService.deleteTransaction(transactionId);
|
||||
return TransitionTargetPageNameKeyword.REDIRECT +
|
||||
TransitionTargetPageNameKeyword.TRANSACTION_DETAIL +
|
||||
TransitionTargetPageNameKeyword.INTERROGATION +
|
||||
TransitionTargetPageNameKeyword.TODAY_DATES +
|
||||
TransitionTargetPageNameKeyword.EQUAL +
|
||||
today;
|
||||
}
|
||||
|
||||
@SessionCheck
|
||||
@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(SessionKeyword.LOGIN_USER);
|
||||
|
||||
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);
|
||||
|
||||
int lastDay = yearMonth.lengthOfMonth();
|
||||
|
||||
int firstDayOfWeek = yearMonth.atDay(1).getDayOfWeek().getValue() % 7;
|
||||
|
||||
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();
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.YEAR, year);
|
||||
model.addAttribute(PageReturnAttributeKeyword.MONTH, month);
|
||||
model.addAttribute(PageReturnAttributeKeyword.DAY, today.getDayOfMonth());
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.LAST_DAY, lastDay);
|
||||
model.addAttribute(PageReturnAttributeKeyword.FIRST_DAY_OF_WEEK, firstDayOfWeek);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.PREVIOUS_YEAR, previousYear);
|
||||
model.addAttribute(PageReturnAttributeKeyword.PREVIOUS_MONTH, previousMonth);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.NEXT_YEAR, nextYear);
|
||||
model.addAttribute(PageReturnAttributeKeyword.NEXT_MONTH, nextMonth);
|
||||
|
||||
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());
|
||||
|
||||
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(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()));
|
||||
|
||||
List<GoalForm> resultList = goalForm.stream().filter(goal -> goal.getGoalComplete() == 0 && goal.getDeadline().isAfter(today) )
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!resultList.isEmpty()) {
|
||||
GoalForm result = resultList.getFirst();
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.ACHIEVEMENT_RATE, result.getAchievementRate());
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.CURRENT_AMOUNT, result.getCurrentAmount());
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.TARGET_AMOUNT, result.getTargetAmount());
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.SAVING, userForm.getSaving());
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.DEADLINE, result.getDeadline());
|
||||
|
||||
} else {
|
||||
final String MESSAGE = "目標を設定してください";
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.ACHIEVEMENT_RATE, MESSAGE);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.CURRENT_AMOUNT, MESSAGE);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.TARGET_AMOUNT, MESSAGE);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.SAVING, userForm.getSaving());
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.DEADLINE, MESSAGE);
|
||||
}
|
||||
|
||||
return TransitionTargetPageNameKeyword.MENU_HTML;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package com.example.demo.app.presentation.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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 org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
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.SessionKeyword;
|
||||
import com.example.demo.app.presentation.controller.pageproperty.TransitionTargetPageNameKeyword;
|
||||
import com.example.demo.app.presentation.form.UserForm;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
private final CourseService courseService;
|
||||
|
||||
private final QuestionService questionService;
|
||||
|
||||
|
||||
@GetMapping(TransitionTargetPageNameKeyword.USER_RESISTER)
|
||||
public String showRegister(Model model, HttpSession session) {
|
||||
UserForm userForm = new UserForm();
|
||||
|
||||
List<QuestionEntity> questionList = questionService.findAll();
|
||||
|
||||
session.setAttribute(PageReturnAttributeKeyword.QUESTION_LIST, questionList);
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.USER_FORM, userForm);
|
||||
return TransitionTargetPageNameKeyword.USER_RESISTER_HTML;
|
||||
}
|
||||
|
||||
@PostMapping(TransitionTargetPageNameKeyword.USER_RESISTER_RETURN)
|
||||
public String showRegisterReturn(@RequestParam(required = false) Long courseId, Model model, HttpSession session) {
|
||||
|
||||
UserForm userForm = (UserForm) session.getAttribute(PageReturnAttributeKeyword.USER_FORM);
|
||||
|
||||
if (userForm.getUserName().equals("")) {
|
||||
userForm = new UserForm();
|
||||
userForm.setCourseId(courseId);
|
||||
}
|
||||
|
||||
if (courseId != null) {
|
||||
model.addAttribute(PageReturnAttributeKeyword.SELECTED_COURSE_NAME, courseService.findById(courseId).getCourseName());
|
||||
}
|
||||
|
||||
session.setAttribute(SessionKeyword.SELECTED_COURSE_NAME, courseService.findById(courseId).getCourseName());
|
||||
model.addAttribute(PageReturnAttributeKeyword.COURSE_ID, courseId);
|
||||
model.addAttribute(PageReturnAttributeKeyword.USER_FORM, userForm);
|
||||
|
||||
return TransitionTargetPageNameKeyword.USER_RESISTER_RETURN_HTML;
|
||||
}
|
||||
|
||||
@GetMapping(TransitionTargetPageNameKeyword.USER_RESISTER_CONFIRM)
|
||||
public String confirmRegisterGet(@ModelAttribute UserForm userForm,
|
||||
String selectedCourseName, Model model,
|
||||
HttpSession session) {
|
||||
|
||||
model.addAttribute(PageReturnAttributeKeyword.SELECTED_COURSE_NAME, (String) session.getAttribute(SessionKeyword.SELECTED_COURSE_NAME));
|
||||
|
||||
session.setAttribute(SessionKeyword.QUESTION_ID, userForm.getSecretQuestionId());
|
||||
|
||||
return TransitionTargetPageNameKeyword.USER_RESISTER_CONFIRM_HTML;
|
||||
|
||||
}
|
||||
|
||||
@PostMapping(TransitionTargetPageNameKeyword.USER_RESISTER_COMPLETE)
|
||||
public String confirmRegister(
|
||||
@ModelAttribute UserForm userForm,
|
||||
Model model,
|
||||
HttpSession session) {
|
||||
|
||||
Long courseId = courseService.findByName((String) session.getAttribute(SessionKeyword.SELECTED_COURSE_NAME));
|
||||
|
||||
Long questionId = (Long) session.getAttribute(SessionKeyword.QUESTION_ID);
|
||||
|
||||
userForm.setSecretQuestionId(questionId);
|
||||
|
||||
userService.register(userForm, courseId);
|
||||
|
||||
return TransitionTargetPageNameKeyword.REDIRECT + TransitionTargetPageNameKeyword.LOGIN;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.example.demo.app.presentation.controller.pageproperty;
|
||||
|
||||
public class PageReturnAttributeKeyword {
|
||||
|
||||
public static final String ERROR_MESSAGE = "errorMessage";
|
||||
public static final String MESSAGE = "message";
|
||||
public static final String ERROR = "error";
|
||||
public static final String STATUS = "status";
|
||||
|
||||
public static final String QUESTION_LIST = "questionList";
|
||||
public static final String USER_FORM = "userForm";
|
||||
public static final String SELECTED_COURSE_NAME = "selectedCourseName";
|
||||
public static final String COURSE_ID = "courseId";
|
||||
|
||||
public static final String PASSWOR_RESET_FORM = "passwordResetForm";
|
||||
public static final String PASSWOR_RESET_USER_ID = "passwordResetUserId";
|
||||
|
||||
public static final String AUTHENTICATION_FORM = "authenticationForm";
|
||||
|
||||
public static final String PROFILE_FORM = "profileForm";
|
||||
public static final String PROFILE_EDIT_FORM = "profileEditForm";
|
||||
|
||||
public static final String MODE = "mode";
|
||||
public static final String CURRENT_COURSE_ID = "currentCourseId";
|
||||
public static final String COURSE_LIST = "courseList";
|
||||
public static final String COURSE_INFO_LIST = "courseInfoList";
|
||||
|
||||
public static final String YEAR = "year";
|
||||
public static final String MONTH = "month";
|
||||
public static final String DAY = "day";
|
||||
public static final String PREVIOUS_YEAR = "previousYear";
|
||||
public static final String PREVIOUS_MONTH = "previousMonth";
|
||||
public static final String LAST_DAY = "lastDay";
|
||||
public static final String FIRST_DAY_OF_WEEK = "firstDayOfWeek";
|
||||
public static final String NEXT_YEAR = "nextYear";
|
||||
public static final String NEXT_MONTH = "nextMonth";
|
||||
public static final String TODAY = "today";
|
||||
public static final String TRANSACTION_FORM_MAP = "transactionFormMap";
|
||||
public static final String TRANSACTION_FORM_LIST = "transactionFormList";
|
||||
public static final String TRANSACTION_FORM = "transactionForm";
|
||||
public static final String TRANSACTION_ID = "transactionId";
|
||||
public static final String CATEGORY_FORM_LIST = "categoryFormList";
|
||||
public static final String INCOME_LIST = "incomeList";
|
||||
public static final String EXPENSE_LIST = "expenseList";
|
||||
public static final String TOTAL_INCOME = "totalIncome";
|
||||
public static final String TOTAL_EXPENSE = "totalExpense";
|
||||
public static final String ACHIEVEMENT_RATE = "achievementRate";
|
||||
public static final String CURRENT_AMOUNT = "currentAmount";
|
||||
public static final String TARGET_AMOUNT = "targetAmount";
|
||||
public static final String SAVING = "saving";
|
||||
public static final String DEADLINE = "deadline";
|
||||
|
||||
public static final String ANALYSIS_FORM = "analysisForm";
|
||||
|
||||
public static final String GOAL_FORM = "goalForm";
|
||||
public static final String GOAL_FORM_LIST = "goalFormList";
|
||||
public static final String ACHIEVEMENT_LIST = "achievementList";
|
||||
public static final String GRAPH_GOAL = "graphGoal";
|
||||
public static final String GOAL_COMPLETE_FORM_LIST = "goalCompleteFormList";
|
||||
|
||||
public static final String CATEGORY_ID = "categoryId";
|
||||
public static final String CATEGORY_FORM = "categoryForm";
|
||||
|
||||
public static final String FIXED_COST_FORM_LIST = "fixedCostFormList";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.example.demo.app.presentation.controller.pageproperty;
|
||||
|
||||
public class SessionKeyword {
|
||||
// SESSION情報として格納したいログイン者の情報
|
||||
public static final String LOGIN_USER = "loginUser";
|
||||
|
||||
public static final String SELECTED_COURSE_NAME = "selectedCourseName";
|
||||
|
||||
public static final String QUESTION_ID = "questionId";
|
||||
|
||||
public static final String T_TYPE = "tType";
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.example.demo.app.presentation.controller.pageproperty;
|
||||
|
||||
public class TransitionTargetPageNameKeyword {
|
||||
|
||||
// HTML
|
||||
public static final String ERROR_HTML = "error";
|
||||
|
||||
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 = "password_reset";
|
||||
|
||||
public static final String AUTHENTICATION_HTML = "authentication";
|
||||
|
||||
public static final String MENU_HTML = "menu";
|
||||
|
||||
public static final String PROFILE_HTML = "profile";
|
||||
public static final String PROFILE_EDIT_HTML = "profile_edit";
|
||||
|
||||
public static final String SELECT_COURSE_HTML = "select_course";
|
||||
public static final String COURSE_CREATE_HTML = "course_create";
|
||||
public static final String COURSE_CREATE_RATIO_HTML = "course_create_ratio";
|
||||
|
||||
public static final String TRANSACTION_LIST_HTML = "transaction_list";
|
||||
public static final String TRANSACTION_DETAIL_HTML = "transaction_detail";
|
||||
public static final String TRANSACTION_CREATE_HTML = "transaction_create";
|
||||
public static final String TRANSACTION_UPDATE_HTML = "transaction_update";
|
||||
|
||||
public static final String ANALYSIS_HTML = "analysis";
|
||||
|
||||
public static final String GOAL_VIEW_HTML = "goal_view";
|
||||
public static final String GOAL_EDIT_HTML = "goal_edit";
|
||||
public static final String GOAL_CREATE_HTML = "goal_create";
|
||||
public static final String GOAL_RECORD_HTML = "goal_record";
|
||||
|
||||
public static final String CATEGORY_LIST_HTML = "category_list";
|
||||
public static final String CATEGORY_CREATE_HTML = "category_create";
|
||||
public static final String CATEGORY_UPDATE_HTML = "category_update";
|
||||
|
||||
public static final String FIXED_COST_HTML = "fixed_cost";
|
||||
public static final String FIXED_COST_CREATE_HTML = "fixed_cost_create";
|
||||
|
||||
// Countroller
|
||||
public static final String ERROR = "/error";
|
||||
|
||||
public static final String USER_RESISTER = "/user/register";
|
||||
public static final String USER_RESISTER_RETURN = "/user/register/return";
|
||||
public static final String USER_RESISTER_CONFIRM = "/user/register/confirm";
|
||||
public static final String USER_RESISTER_COMPLETE = "/user/register/complete";
|
||||
|
||||
|
||||
public static final String REDIRECT = "redirect:";
|
||||
public static final String LOGIN = "/login";
|
||||
public static final String LOGOUT = "/logout";
|
||||
|
||||
public static final String AUTHENTICATION = "/authentication";
|
||||
|
||||
public static final String PASSWORD_RESET = "/password/reset";
|
||||
|
||||
public static final String MENU = "/menu";
|
||||
|
||||
public static final String PROFILE = "/profile";
|
||||
public static final String PROFILE_EDIT = "/profile/edit";
|
||||
public static final String WITHDRAW = "/withdraw";
|
||||
|
||||
public static final String SHOW_SELECT_COURSE = "/user/register/course";
|
||||
public static final String COURSE = "/course";
|
||||
public static final String CHANGE = "/change";
|
||||
public static final String COURSE_CREATE = "/course/create";
|
||||
public static final String COURSE_CREATE_RATIO = "/course/create/ratio";
|
||||
|
||||
|
||||
public static final String INTERROGATION = "?";
|
||||
public static final String EQUAL = "=";
|
||||
public static final String TRANSACTION_LIST = "/transaction/list";
|
||||
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 EDIT = "/edit";
|
||||
public static final String UPDATE = "/update";
|
||||
public static final String CREATE = "/create";
|
||||
public static final String DELETE = "/delete";
|
||||
public static final String RECORD = "/record";
|
||||
|
||||
public static final String CATEGORY_LIST = "/category/list";
|
||||
public static final String CATEGORY_CREATE = "/category/create";
|
||||
public static final String CATEGORY_UPDATE = "/category/update";
|
||||
public static final String CATEGORY_DELETE = "/category/delete";
|
||||
|
||||
public static final String FIXED_COST_LIST = "/fixed-cost/list";
|
||||
public static final String FIXED_COST_CREATE = "/fixed-cost/create";
|
||||
public static final String FIXED_COST_DELETE = "/fixed-cost/delete";
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.AllocationModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AllocationForm {
|
||||
|
||||
private Long categoryId;
|
||||
private Long courseId;
|
||||
private Integer allocationRatio;
|
||||
|
||||
public static AllocationForm convertFrom(AllocationModel allocationModel) {
|
||||
return new AllocationForm(allocationModel.getCategoryId(), allocationModel.getCourseId(), allocationModel.getAllocationRatio());
|
||||
}
|
||||
|
||||
public static List<AllocationForm> convertFrom(List<AllocationModel> allocationModelList){
|
||||
return allocationModelList.stream().map(AllocationForm::convertFrom).toList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AllocationFormList {
|
||||
|
||||
private Long categoryId1 = 1L;
|
||||
private Integer allocationRatio1;
|
||||
|
||||
private Long categoryId2 = 2L;
|
||||
private Integer allocationRatio2;
|
||||
|
||||
private Long categoryId3 = 3L;
|
||||
private Integer allocationRatio3;
|
||||
|
||||
private Long categoryId4 = 4L;
|
||||
private Integer allocationRatio4;
|
||||
|
||||
private Long categoryId5 = 5L;
|
||||
private Integer allocationRatio5;
|
||||
|
||||
private Long categoryId6 = 6L;
|
||||
private Integer allocationRatio6;
|
||||
|
||||
private Long categoryId7 = 7L;
|
||||
private Integer allocationRatio7;
|
||||
|
||||
private Long categoryId8 = 8L;
|
||||
private Integer allocationRatio8;
|
||||
|
||||
private Long categoryId9 = 9L;
|
||||
private Integer allocationRatio9;
|
||||
|
||||
private Long categoryId10 = 10L;
|
||||
private Integer allocationRatio10;
|
||||
|
||||
private Long categoryId11 = 11L;
|
||||
private Integer allocationRatio11;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.AnalysisModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AnalysisForm {
|
||||
|
||||
private Integer currentMonthTotalAmount;
|
||||
|
||||
private Integer previousMonthTotalAmount;
|
||||
|
||||
private Integer totalDifferenceAmount;
|
||||
|
||||
private List<CategoryAnalysisForm>
|
||||
categoryAnalysisFormList;
|
||||
|
||||
public static AnalysisForm convertFrom(
|
||||
AnalysisModel analysisModel) {
|
||||
|
||||
return new AnalysisForm(
|
||||
analysisModel.getCurrentMonthTotalAmount(),
|
||||
analysisModel.getPreviousMonthTotalAmount(),
|
||||
analysisModel.getTotalDifferenceAmount(),
|
||||
CategoryAnalysisForm.convertFrom(
|
||||
analysisModel.getCategoryAnalysisModelList()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AuthenticationForm {
|
||||
private String mailAddress;
|
||||
private Long secretQuestionId;
|
||||
private String secretAnswer;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.CategoryAnalysisModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CategoryAnalysisForm {
|
||||
|
||||
private String categoryName;
|
||||
|
||||
private Integer currentMonthAmount;
|
||||
|
||||
private Integer previousMonthAmount;
|
||||
|
||||
private Integer monthDifferenceAmount;
|
||||
|
||||
private Integer courseLimitAmount;
|
||||
|
||||
private Integer courseDifferenceAmount;
|
||||
|
||||
public static CategoryAnalysisForm convertFrom(
|
||||
CategoryAnalysisModel categoryAnalysisModel) {
|
||||
|
||||
return new CategoryAnalysisForm(
|
||||
categoryAnalysisModel.getCategoryName(),
|
||||
categoryAnalysisModel.getCurrentMonthAmount(),
|
||||
categoryAnalysisModel.getPreviousMonthAmount(),
|
||||
categoryAnalysisModel.getMonthDifferenceAmount(),
|
||||
categoryAnalysisModel.getCourseLimitAmount(),
|
||||
categoryAnalysisModel.getCourseDifferenceAmount());
|
||||
}
|
||||
|
||||
public static List<CategoryAnalysisForm> convertFrom(
|
||||
List<CategoryAnalysisModel> categoryAnalysisModelList) {
|
||||
|
||||
return categoryAnalysisModelList.stream()
|
||||
.map(CategoryAnalysisForm::convertFrom)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -25,4 +25,11 @@ public class CategoryForm {
|
||||
return categoryModelList.stream().map(CategoryForm::convertFrom).toList();
|
||||
}
|
||||
|
||||
public static CategoryModel convertTo(CategoryForm categoryForm) {
|
||||
return new CategoryModel(
|
||||
categoryForm.getCategoryId(),
|
||||
categoryForm.getCategoryName(),
|
||||
categoryForm.getTransactionType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,4 +30,12 @@ public class CourseForm {
|
||||
return courseModelList.stream().map(CourseForm::convertFrom).toList();
|
||||
}
|
||||
|
||||
public static CourseModel convertTo(CourseForm courseForm) {
|
||||
return new CourseModel(
|
||||
courseForm.getCourseId(),
|
||||
courseForm.getCourseName(),
|
||||
courseForm.getDescription()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class CourseInfoForm {
|
||||
|
||||
|
||||
public static CourseInfoForm convertFrom(CourseInfoModel courseInfoModel ) {
|
||||
return new CourseInfoForm(courseInfoModel.getCategoryId(), courseInfoModel.getCourseName(), courseInfoModel.getCategoryId(), courseInfoModel.getCategoryName(), courseInfoModel.getAllocationRatio());
|
||||
return new CourseInfoForm(courseInfoModel.getCourseId(), courseInfoModel.getCourseName(), courseInfoModel.getCategoryId(), courseInfoModel.getCategoryName(), courseInfoModel.getAllocationRatio());
|
||||
}
|
||||
|
||||
public static List<CourseInfoForm> convertFrom(List<CourseInfoModel> courseInfoModelList ) {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Expense {
|
||||
|
||||
private LocalDate date;
|
||||
private Long amount;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.FixedCostModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class FixedCostForm {
|
||||
|
||||
private Long fixedCostId;
|
||||
|
||||
private Long userId;
|
||||
|
||||
private Long categoryId;
|
||||
|
||||
private String fixedCostName;
|
||||
|
||||
private Integer amount;
|
||||
|
||||
private String categoryName;
|
||||
|
||||
|
||||
public static FixedCostForm convertFrom(FixedCostModel fixedCostModel) {
|
||||
return new FixedCostForm(
|
||||
fixedCostModel.getFixedCostId(),
|
||||
fixedCostModel.getUserId(),
|
||||
fixedCostModel.getCategoryId(),
|
||||
fixedCostModel.getFixedCostName(),
|
||||
fixedCostModel.getAmount(),
|
||||
"");
|
||||
}
|
||||
|
||||
|
||||
public static List<FixedCostForm> convertFrom(List<FixedCostModel> fixedCostModelList) {
|
||||
return fixedCostModelList.stream().map(fixedCostModel -> FixedCostForm.convertFrom(fixedCostModel)).toList();
|
||||
}
|
||||
|
||||
public static FixedCostModel convertTo(FixedCostForm fixedCostForm) {
|
||||
return new FixedCostModel(
|
||||
fixedCostForm.getFixedCostId(),
|
||||
fixedCostForm.getUserId(),
|
||||
fixedCostForm.getCategoryId(),
|
||||
fixedCostForm.getFixedCostName(),
|
||||
fixedCostForm.getAmount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import com.example.demo.app.domain.model.GoalModel;
|
||||
|
||||
@@ -21,10 +24,19 @@ public class GoalForm {
|
||||
|
||||
private Integer targetAmount;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
private LocalDate deadline;
|
||||
|
||||
private Integer goalComplete;
|
||||
|
||||
private String status;
|
||||
|
||||
private Integer achievementRate; // 達成率
|
||||
|
||||
private Integer currentAmount; // 現在の資産
|
||||
|
||||
private Long userId;
|
||||
|
||||
public static GoalForm convertFrom(GoalModel goalModel) {
|
||||
return new GoalForm(
|
||||
goalModel.getGoalId(),
|
||||
@@ -32,11 +44,15 @@ public class GoalForm {
|
||||
goalModel.getGoalSubtitle(),
|
||||
goalModel.getTargetAmount(),
|
||||
goalModel.getDeadline(),
|
||||
goalModel.getGoalComplete());
|
||||
goalModel.getGoalComplete(),
|
||||
null,
|
||||
goalModel.getAchievementRate(),
|
||||
goalModel.getCurrentAmount(),
|
||||
goalModel.getUserId());
|
||||
}
|
||||
|
||||
// public static List<GoalForm> convertFrom(List<GoalModel> goalModelList) {
|
||||
// return goalModelList.stream().map(GoalForm::convertFrom).toList();
|
||||
// }
|
||||
public static List<GoalForm> convertFrom(List<GoalModel> goalModelList) {
|
||||
return goalModelList.stream().map(GoalForm::convertFrom).toList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Income {
|
||||
|
||||
private LocalDate date;
|
||||
private Long amount;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.time.YearMonth;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class MonthlyAchievementForm {
|
||||
|
||||
private YearMonth month;
|
||||
|
||||
private Integer saving;
|
||||
|
||||
private Integer achievementRate;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.time.YearMonth;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class MonthlySavingForm {
|
||||
|
||||
private YearMonth month;
|
||||
|
||||
private Integer income;
|
||||
|
||||
private Integer expense;
|
||||
|
||||
private Integer saving;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PasswordResetForm{
|
||||
private String password;
|
||||
private String passwordConfirm;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ProfileEditForm {
|
||||
private String userName;
|
||||
private String mailAddress;
|
||||
private LocalDate birthDate;
|
||||
private Integer saving;
|
||||
private Integer annualIncome;
|
||||
private Integer monthlyBudget;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import com.example.demo.app.domain.model.ProfileModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ProfileForm {
|
||||
private Long userId;
|
||||
private String userName;
|
||||
private String mailAddress;
|
||||
private LocalDate birthDate;
|
||||
private Integer saving;
|
||||
private Integer annualIncome;
|
||||
private Integer monthlyBudget;
|
||||
|
||||
public static ProfileForm convertForm(ProfileModel profileModel) {
|
||||
return new ProfileForm(
|
||||
profileModel.getUserId(),
|
||||
profileModel.getUserName(),
|
||||
profileModel.getMailAddress(),
|
||||
profileModel.getBirthDate(),
|
||||
profileModel.getSaving(),
|
||||
profileModel.getAnnualIncome(),
|
||||
profileModel.getMonthlyBudget());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import com.example.demo.app.domain.model.UserModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class UserForm {
|
||||
private String userName;
|
||||
private String mailAddress;
|
||||
private LocalDate birthDate;
|
||||
private String password;
|
||||
private Long secretQuestionId;
|
||||
private String secretAnswer;
|
||||
private Integer saving;
|
||||
private Integer annualIncome;
|
||||
private Integer monthlyBudget;
|
||||
private Long goalId;
|
||||
private Long courseId;
|
||||
|
||||
|
||||
public static UserForm convertFrom(UserModel userModel) {
|
||||
return new UserForm(
|
||||
userModel.getUserName(),
|
||||
userModel.getMailAddress(),
|
||||
userModel.getBrithDate(),
|
||||
userModel.getPassword(),
|
||||
userModel.getSecretQuestionId(),
|
||||
userModel.getSecretAnswer(),
|
||||
userModel.getSaving(),
|
||||
userModel.getAnnualIncome(),
|
||||
userModel.getMonthlyBudget(),
|
||||
0L,
|
||||
userModel.getCourseId()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
112
src/main/resources/static/css/menu.css
Normal file
112
src/main/resources/static/css/menu.css
Normal file
@@ -0,0 +1,112 @@
|
||||
body {
|
||||
margin: 0;
|
||||
padding-top:80px;
|
||||
padding-bottom:120px;
|
||||
}
|
||||
|
||||
#calendar {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
}
|
||||
|
||||
#calendar th,
|
||||
#calendar td {
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
th {
|
||||
font-weight: bold;
|
||||
height: 35px;
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
td {
|
||||
width: 14%;
|
||||
height: 70px;
|
||||
padding: 5px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
td:hover {
|
||||
background-color: lightblue;
|
||||
}
|
||||
|
||||
.holiday {
|
||||
color: red;
|
||||
}
|
||||
|
||||
#today {
|
||||
font-weight: bold;
|
||||
background-color: bisque;
|
||||
}
|
||||
|
||||
.calendar-title {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
gap: 30px;
|
||||
|
||||
margin: 15px 10px;
|
||||
}
|
||||
|
||||
.calendar-date {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.year {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.month {
|
||||
font-size: 30px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.month-button {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
|
||||
font-size: 28px;
|
||||
text-decoration: none;
|
||||
color: #333;
|
||||
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.month-button:hover {
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
.date {
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.income {
|
||||
color: blue;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.expense {
|
||||
color: red;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.total {
|
||||
margin: 15px 10px;
|
||||
padding: 10px;
|
||||
border-top: 1px solid #ddd;
|
||||
|
||||
font-size: 16px;
|
||||
text-align: right;
|
||||
}
|
||||
226
src/main/resources/static/css/style.css
Normal file
226
src/main/resources/static/css/style.css
Normal file
@@ -0,0 +1,226 @@
|
||||
/* =======================
|
||||
全体
|
||||
======================= */
|
||||
body {
|
||||
padding-top: 80px;
|
||||
padding-bottom: 80px;
|
||||
background-color: #f8f9fa;
|
||||
}
|
||||
|
||||
/* =======================
|
||||
コンテンツ
|
||||
======================= */
|
||||
.main-container {
|
||||
max-width: 480px;
|
||||
margin: 0 auto;
|
||||
padding: 0 12px;
|
||||
}
|
||||
|
||||
/* =======================
|
||||
タイトル
|
||||
======================= */
|
||||
.page-title {
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* =======================
|
||||
ヘッダー
|
||||
======================= */
|
||||
.app-header {
|
||||
background-color: #E3F2FD;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.app-logo {
|
||||
font-size: 1.2rem;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* =======================
|
||||
フッター
|
||||
======================= */
|
||||
.app-footer {
|
||||
background-color: #E3F2FD;
|
||||
border-top: 1px solid #d0d7de;
|
||||
}
|
||||
|
||||
.a-footer {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* =======================
|
||||
カード
|
||||
======================= */
|
||||
.app-card {
|
||||
background-color: #ffffff;
|
||||
border-radius: 12px;
|
||||
padding: 15px;
|
||||
margin-bottom: 15px;
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.08);
|
||||
}
|
||||
|
||||
.card {
|
||||
border-radius: 12px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.card-body {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
/* =======================
|
||||
カレンダー
|
||||
======================= */
|
||||
|
||||
#calendar {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
table-layout: fixed;
|
||||
}
|
||||
|
||||
#calendar th,
|
||||
#calendar td {
|
||||
border: 1px solid black;
|
||||
}
|
||||
|
||||
th {
|
||||
font-weight: bold;
|
||||
height: 35px;
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
td {
|
||||
width: 14%;
|
||||
height: 70px;
|
||||
padding: 5px;
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
td:hover {
|
||||
background-color: lightblue;
|
||||
}
|
||||
|
||||
.holiday {
|
||||
color: red;
|
||||
}
|
||||
|
||||
#today {
|
||||
font-weight: bold;
|
||||
background-color: bisque;
|
||||
}
|
||||
|
||||
.calendar-title {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto 1fr;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.calendar-date {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.year {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.month {
|
||||
font-size: 30px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.month-button {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
|
||||
font-size: 28px;
|
||||
text-decoration: none;
|
||||
color: #333;
|
||||
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.month-button:hover {
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
.month-button:last-child {
|
||||
justify-self: end;
|
||||
}
|
||||
|
||||
.date {
|
||||
font-size: 13px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.income {
|
||||
color: blue;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.expense {
|
||||
color: red;
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.total {
|
||||
margin: 15px 10px;
|
||||
padding: 10px;
|
||||
border-top: 1px solid #ddd;
|
||||
|
||||
font-size: 16px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.a-calender {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* =======================
|
||||
金額表示
|
||||
======================= */
|
||||
.plus {
|
||||
color: #dc3545;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.minus {
|
||||
color: #0d6efd;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* =======================
|
||||
テーブル
|
||||
======================= */
|
||||
.table {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.table th {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.table td {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.goal {
|
||||
min-width: 300px;
|
||||
}
|
||||
|
||||
/* =======================
|
||||
ボタン
|
||||
======================= */
|
||||
.btn {
|
||||
border-radius: 10px;
|
||||
}
|
||||
15
src/main/resources/static/css/transaction_detail.css
Normal file
15
src/main/resources/static/css/transaction_detail.css
Normal file
@@ -0,0 +1,15 @@
|
||||
.transaction-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.transaction-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
.transaction-buttons form {
|
||||
margin: 0;
|
||||
}
|
||||
@@ -1,13 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" http-equiv="Content-Type">
|
||||
<title>分析画面</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<h2 class="text-center">支出分析</h2>
|
||||
<div th:replace="~{header :: header}">
|
||||
</div>
|
||||
|
||||
<div class="main-container">
|
||||
<h2 class="page-title">支出分析</h2>
|
||||
|
||||
<div class="calendar-title">
|
||||
|
||||
<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>
|
||||
@@ -24,11 +47,11 @@
|
||||
0
|
||||
</td>
|
||||
<td th:text="${analysisForm.totalDifferenceAmount >= 0}
|
||||
? '+' + ${analysisForm.totalDifferenceAmount}
|
||||
? '+' + ${analysisForm.totalDifferenceAmount}
|
||||
: ${analysisForm.totalDifferenceAmount}"
|
||||
th:class="${analysisForm.totalDifferenceAmount >= 0}
|
||||
? 'color-danger;'
|
||||
: 'color-primary;'">
|
||||
? 'text-danger'
|
||||
: 'text-primary'">
|
||||
0
|
||||
</td>
|
||||
</tr>
|
||||
@@ -42,11 +65,7 @@
|
||||
<tr>
|
||||
<th scope="col">カテゴリ別</th>
|
||||
<th scope="col">支出</th>
|
||||
<th scope="col">
|
||||
前月比
|
||||
<br>
|
||||
コース比
|
||||
</th>
|
||||
<th scope="col">前月比<br>コース比</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -54,34 +73,37 @@
|
||||
|
||||
<th scope="row"
|
||||
th:text="${category.categoryName}">
|
||||
食費
|
||||
</th>
|
||||
|
||||
<td th:text="'¥' + ${category.currentMonthAmount}">
|
||||
0
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<span th:text="${category.monthDifferenceAmount >= 0}
|
||||
? '+' + ${category.monthDifferenceAmount}
|
||||
? '+' + ${category.monthDifferenceAmount}
|
||||
: ${category.monthDifferenceAmount}"
|
||||
th:class="${category.monthDifferenceAmount >= 0}
|
||||
? 'color-danger;'
|
||||
: 'color-primary;'">
|
||||
? 'text-danger'
|
||||
: 'text-primary'">
|
||||
</span>
|
||||
<br>
|
||||
<span th:text="${category.courseDifferenceAmount >= 0}
|
||||
? '+' + ${category.courseDifferenceAmount}
|
||||
? '+' + ${category.courseDifferenceAmount}
|
||||
: ${category.courseDifferenceAmount}"
|
||||
th:class="${category.courseDifferenceAmount >= 0}
|
||||
? 'color-danger;'
|
||||
: 'color-primary;'">
|
||||
? 'text-danger'
|
||||
: 'text-primary'">
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
|
||||
<div th:replace="~{footer :: footer}">
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
123
src/main/resources/templates/authentication.html
Normal file
123
src/main/resources/templates/authentication.html
Normal file
@@ -0,0 +1,123 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" http-equiv="Content-Type">
|
||||
<title>認証</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
|
||||
</head>
|
||||
|
||||
<body style="padding-top:80px; padding-bottom:80px;">
|
||||
|
||||
<div th:replace="~{header :: header}">
|
||||
</div>
|
||||
|
||||
<div class="main-container">
|
||||
|
||||
<h1 class="page-title">
|
||||
本人認証
|
||||
</h1>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
|
||||
<div class="card-body">
|
||||
|
||||
<form th:action="@{/authentication}"
|
||||
th:object="${authenticationForm}"
|
||||
method="post">
|
||||
|
||||
<div class="mb-3">
|
||||
|
||||
<label for="mailAddress"
|
||||
class="form-label">
|
||||
メールアドレス
|
||||
</label>
|
||||
|
||||
<input type="email"
|
||||
id="mailAddress"
|
||||
class="form-control"
|
||||
th:field="*{mailAddress}"
|
||||
required>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
|
||||
<label for="secretQuestionId"
|
||||
class="form-label">
|
||||
秘密の質問
|
||||
</label>
|
||||
|
||||
<select id="secretQuestionId"
|
||||
class="form-select"
|
||||
th:field="*{secretQuestionId}">
|
||||
|
||||
<option value="">
|
||||
選択してください
|
||||
</option>
|
||||
|
||||
<option th:each="question : ${questionList}"
|
||||
th:value="${question.secretQuestionId}"
|
||||
th:text="${question.questionText}">
|
||||
</option>
|
||||
|
||||
</select>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
|
||||
<label for="secretAnswer"
|
||||
class="form-label">
|
||||
秘密の質問の回答
|
||||
</label>
|
||||
|
||||
<input type="text"
|
||||
id="secretAnswer"
|
||||
class="form-control"
|
||||
th:field="*{secretAnswer}"
|
||||
required>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="d-grid gap-2">
|
||||
|
||||
<button type="submit"
|
||||
class="btn btn-primary">
|
||||
確認
|
||||
</button>
|
||||
|
||||
</div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="d-grid mt-3">
|
||||
|
||||
<form th:action="@{/login}"
|
||||
method="get">
|
||||
|
||||
<button type="submit"
|
||||
class="btn btn-outline-secondary w-100">
|
||||
戻る
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script th:if="${errorMessage}"
|
||||
th:inline="javascript">
|
||||
alert(/*[[${errorMessage}]]*/);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
59
src/main/resources/templates/category_create.html
Normal file
59
src/main/resources/templates/category_create.html
Normal file
@@ -0,0 +1,59 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" http-equiv="Content-Type">
|
||||
<title>カテゴリ登録</title>
|
||||
<link rel="stylesheet" th:href="@{/css/menu.css}">
|
||||
|
||||
<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;">
|
||||
|
||||
<div th:replace="~{header :: header}"></div>
|
||||
|
||||
<div class="main-container">
|
||||
<h1 class="page-title">カテゴリ登録</h1>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
|
||||
<form th:action="@{/category/create}" th:object="${categoryForm}" method="post">
|
||||
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="categoryName">カテゴリ名</label>
|
||||
|
||||
<input class="form-control" type="text" id="categoryName" th:field="*{categoryName}" required>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="transactionType">収入・支出</label>
|
||||
|
||||
<select class="form-select" id="transactionType" th:field="*{transactionType}" required>
|
||||
|
||||
<option value="">選択してください</option>
|
||||
<option value="0">支出</option>
|
||||
<option value="1">収入</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary">登録</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div th:replace="~{footer :: footer}"></div>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
79
src/main/resources/templates/category_list.html
Normal file
79
src/main/resources/templates/category_list.html
Normal file
@@ -0,0 +1,79 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" http-equiv="Content-Type">
|
||||
<title>カテゴリ一覧</title>
|
||||
<link rel="stylesheet" th:href="@{/css/transaction_detail.css}">
|
||||
<link rel="stylesheet" th:href="@{/css/style.css}">
|
||||
<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;">
|
||||
|
||||
<div th:replace="~{header :: header}"></div>
|
||||
<div class="main-container">
|
||||
|
||||
<div>
|
||||
<ul class="list-unstyled p-0 m-0">
|
||||
<li class="card shadow-sm mb-3" th:each="categoryForm : ${categoryFormList}">
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between">
|
||||
<p>
|
||||
カテゴリ名:
|
||||
<span class="fw-bold" th:text="${categoryForm.categoryName}"></span>
|
||||
<br>
|
||||
収支区分:
|
||||
<span class="fw-bold" th:if="${categoryForm.transactionType == 0}"
|
||||
th:text="|支出|"></span>
|
||||
<span class="fw-bold" th:if="${categoryForm.transactionType == 1}"
|
||||
th:text="|収入|"></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="d-flex justify-content-end gap-2 mt-3">
|
||||
|
||||
<form th:action="@{/category/update}" method="get">
|
||||
<input type="hidden" name="today" th:value="${today}">
|
||||
<input type="hidden" name="categoryId" th:value="${categoryForm.categoryId}">
|
||||
<button type="submit" class="btn btn-sm btn-primary">編集</button>
|
||||
</form>
|
||||
|
||||
<form th:action="@{/category/delete}" method="post">
|
||||
<input type="hidden" name="today" th:value="${today}">
|
||||
<input type="hidden" name="categoryId" th:value="${categoryForm.categoryId}">
|
||||
<button type="submit" class="btn btn-sm btn-danger">削除</button>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="d-grid mt-4">
|
||||
|
||||
<form th:action="@{/category/create}" method="get">
|
||||
|
||||
<input type="hidden"
|
||||
name="today"
|
||||
id="today"
|
||||
th:value="${today}">
|
||||
|
||||
<button class="btn btn-success w-100" type="submit">
|
||||
新規登録
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div th:replace="~{footer :: footer}"></div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
62
src/main/resources/templates/category_update.html
Normal file
62
src/main/resources/templates/category_update.html
Normal file
@@ -0,0 +1,62 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" http-equiv="Content-Type">
|
||||
<title>カテゴリ登録</title>
|
||||
<link rel="stylesheet" th:href="@{/css/menu.css}">
|
||||
|
||||
<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;">
|
||||
|
||||
<div th:replace="~{header :: header}"></div>
|
||||
|
||||
<div class="main-container">
|
||||
<h1 class="page-title">カテゴリ編集</h1>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
|
||||
<form th:action="@{/category/update}" th:object="${categoryForm}" method="post">
|
||||
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="categoryName">カテゴリ名</label>
|
||||
|
||||
<input class="form-control" type="text" id="categoryName" th:field="*{categoryName}" required>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="transactionType">収入・支出</label>
|
||||
|
||||
<select class="form-select" id="transactionType" th:field="*{transactionType}" required>
|
||||
|
||||
<option value="">選択してください</option>
|
||||
<option value="0">支出</option>
|
||||
<option value="1">収入</option>
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<input type="hidden" name="categoryId" th:value="${categoryId}">
|
||||
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary">更新</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div th:replace="~{footer :: footer}"></div>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
54
src/main/resources/templates/course_create.html
Normal file
54
src/main/resources/templates/course_create.html
Normal file
@@ -0,0 +1,54 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" http-equiv="Content-Type">
|
||||
<title>コース登録</title>
|
||||
<link rel="stylesheet" th:href="@{/css/menu.css}">
|
||||
|
||||
<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;">
|
||||
|
||||
<div th:replace="~{header :: header}"></div>
|
||||
<div class="main-container">
|
||||
<h1 class="page-title">コース登録</h1>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<form th:action="@{/course/create/ratio}" th:object="${courseForm}" method="post">
|
||||
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="courseName">コース名</label>
|
||||
|
||||
<input class="form-control" type="text" id="courseName" th:field="*{courseName}" required>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="description">説明</label>
|
||||
|
||||
<textarea class="form-control" id="description" th:field="*{description}"
|
||||
placeholder="説明を入力してください">
|
||||
</textarea>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary">登録</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div th:replace="~{footer :: footer}"></div>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
135
src/main/resources/templates/course_create_ratio.html
Normal file
135
src/main/resources/templates/course_create_ratio.html
Normal file
@@ -0,0 +1,135 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" http-equiv="Content-Type">
|
||||
<title>コース登録</title>
|
||||
<link rel="stylesheet" th:href="@{/css/menu.css}">
|
||||
|
||||
<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:120px;">
|
||||
|
||||
<div th:replace="~{header :: header}"></div>
|
||||
|
||||
<div class="main-container">
|
||||
|
||||
<h1 class="page-title">コース登録</h1>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<form th:action="@{/course/create}" th:object="${allocationFormList}" method="post">
|
||||
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="allocationRatio4">固定費</label>
|
||||
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
|
||||
id="allocationRatio4" th:field="*{allocationRatio4}" required>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="allocationRatio5">食費</label>
|
||||
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
|
||||
id="allocationRatio5" th:field="*{allocationRatio5}" required>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="allocationRatio6">交通費</label>
|
||||
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
|
||||
id="allocationRatio6" th:field="*{allocationRatio6}" required>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="allocationRatio7">日用品費</label>
|
||||
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
|
||||
id="allocationRatio7" th:field="*{allocationRatio7}" required>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="allocationRatio8">被服/美容費</label>
|
||||
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
|
||||
id="allocationRatio8" th:field="*{allocationRatio8}" required>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="allocationRatio9">医療費</label>
|
||||
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
|
||||
id="allocationRatio9" th:field="*{allocationRatio9}" required>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="allocationRatio10">趣味/娯楽費</label>
|
||||
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
|
||||
id="allocationRatio10" th:field="*{allocationRatio10}" required>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="allocationRatio11">その他</label>
|
||||
<input class="form-control" type="number" min="0" max="100" onchange="inputChange()"
|
||||
id="allocationRatio11" th:field="*{allocationRatio11}" required>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="allocationRatioTotal">合計(%)</label>
|
||||
<input class="form-control" type="number" value="0" id="allocationRatioTotal" readonly>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
<div class="d-grid">
|
||||
<button type="submit" class="btn btn-primary" id="submit" disabled="true">登録</button>
|
||||
|
||||
</div>
|
||||
|
||||
<span th:object="${courseForm}">
|
||||
|
||||
<input type="hidden" id="courseName" th:field="*{courseName}" required>
|
||||
<br>
|
||||
|
||||
<input type="hidden" id="description" th:field="*{description}">
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div th:replace="~{footer :: footer}"></div>
|
||||
|
||||
<script>
|
||||
|
||||
function inputChange() {
|
||||
let total = 0;
|
||||
|
||||
for (let i = 4; i <= 11; i++) {
|
||||
total += Number(document.getElementById(`allocationRatio${i}`).value || 0);
|
||||
if (total == 100) {
|
||||
document.getElementById('submit').disabled = false;
|
||||
} else {
|
||||
document.getElementById('submit').disabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
document.getElementById("allocationRatioTotal").value = total;
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
29
src/main/resources/templates/error.html
Normal file
29
src/main/resources/templates/error.html
Normal file
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1">
|
||||
<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}">
|
||||
</div>
|
||||
|
||||
<div class="container text-center mt-5">
|
||||
|
||||
<h2 class="text-danger">
|
||||
エラーが発生しました
|
||||
</h2>
|
||||
|
||||
<p th:text="${errorMessage}"></p>
|
||||
|
||||
<a class="btn btn-primary" th:href="@{/login}">
|
||||
ログイン画面へ
|
||||
</a>
|
||||
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user