34 Commits

Author SHA1 Message Date
c3dae348bf no message 2026-09-25 13:38:58 +09:00
ea1e18ad93 Merge branch 'k-kobayashi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into s-morimto 2026-09-25 13:35:56 +09:00
bb3b8965b2 Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into s-morimto
# Conflicts:
#	src/main/resources/templates/menu.html
#	src/main/resources/templates/select_course.html
#	src/main/resources/templates/transaction_detail.html
2026-09-25 13:28:04 +09:00
3b239d07bd Merge branch 'k-kobayashi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into s-morimto 2026-09-25 13:17:12 +09:00
0c54a42b97 Merge branch 'k-oshita' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into s-morimto
# Conflicts:
#	src/main/resources/templates/menu.html
#	src/main/resources/templates/transaction_detail.html
2026-09-25 13:14:52 +09:00
s-choi
29d879e3b7 Merge branch 's-morimto' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into s-choi 2026-09-25 12:52:48 +09:00
s-choi
f33d4412a7 Merge branch 'k-oshita' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into s-choi 2026-09-25 12:52:17 +09:00
s-choi
573b7969b7 Merge branch 'k-kobayashi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into s-choi
# Conflicts:
#	src/main/resources/templates/goal_view.html
#	src/main/resources/templates/menu.html
#	src/main/resources/templates/select_course.html
#	src/main/resources/templates/transaction_detail.html
2026-09-25 12:51:53 +09:00
s-choi
29d93d5453 [UPDATE] 2次機能を実装しました。 2026-09-25 12:41:52 +09:00
s-choi
95bfd4ed0e [ADD] カテゴリの一覧・作成・修正画面を作成しました。 2026-09-24 15:34:43 +09:00
s-choi
3e6a7f5a74 [EDIT] CategoryのCRUD機能を追加しました。 2026-09-24 15:34:18 +09:00
s-choi
4a574294b7 [EDIT] デフォルトカテゴリ・カスタムカテゴリ両方取得できるように変更しました。 2026-09-24 15:33:37 +09:00
s-choi
b8886fe47b [EDIT] Category一覧への遷移ボタンを追加しました。 2026-09-24 15:32:57 +09:00
s-choi
c44a679213 [EDIT] categoryテーブルにUser・削除フラグを追加しました 2026-09-24 15:32:34 +09:00
s-choi
fb9847a834 Merge branch 'k-kobayashi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into s-choi 2026-09-24 15:24:09 +09:00
s-choi
58da1fcbfc [ADD] 目標作成画面の追加及び遷移ボタン追加 2026-09-24 14:10:12 +09:00
s-choi
ec862f8271 [FIX] デフォルトで目標達成現状を0に明示化 2026-09-24 14:09:52 +09:00
s-choi
918b7f7218 [EDIT] 目標の一覧を受け取るように修正・作成と削除機能の追加 2026-09-24 14:09:22 +09:00
e0b0109a2b Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-oshita 2026-09-24 13:39:17 +09:00
s-choi
76e3fc2345 [FIX] Goalテーブルの変更に合わせてUserメソッドの修正をおこないました。 2026-09-24 13:32:23 +09:00
bcafdbe067 Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-oshita 2026-09-24 13:22:18 +09:00
s-choi
e9d3e16157 [EDIT] 変更したテーブルに合わせてメソッドを修正しました。 2026-09-24 13:20:14 +09:00
s-choi
70ad3678a5 [EDIT] Userテーブルを修正しました。 2026-09-24 13:19:53 +09:00
s-choi
b2b290a998 [EDIT] 目標テーブルを修正しました。 2026-09-24 13:19:23 +09:00
s-choi
1debde25f2 [EDIT] menu画面での目標表示を削除しました。 2026-09-24 13:19:04 +09:00
s-choi
714ffba31f [EDIT] ショートカット機能を適用しました。 2026-09-24 12:43:45 +09:00
s-choi
430f456866 [ADD] ショートカット機能のCRDを作成しました。 2026-09-24 12:43:19 +09:00
s-choi
003e03c0c1 [ADD] ショートカットのためのサービスとレポジトリを作成しました。 2026-09-24 12:42:50 +09:00
s-choi
060102d2b1 [ADD] 固定費登録画面を追加しました。 2026-09-24 12:42:22 +09:00
s-choi
f5b88de9e6 [ADD] 固定費一覧画面を追加しました。 2026-09-24 12:42:14 +09:00
s-choi
68bfbc195d [EDIT] 固定費一覧への遷移ボタンを追加しました。 2026-09-24 12:42:02 +09:00
s-choi
11a8fbf665 [ADD] ショートカット機能のためのEntity/Model/Formを追加しました。 2026-09-24 12:41:31 +09:00
3760bf352d Merge branch 'k-kobayashi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-oshita 2026-09-24 12:30:04 +09:00
76e91f0bf0 Merge branch 's-choi' of https://gitea.it-college.co.jp/2026_09_5H_Spring_KIZAKI/Monegement into k-oshita 2026-09-24 10:19:55 +09:00
55 changed files with 2064 additions and 197 deletions

View File

@@ -1,5 +1,12 @@
package com.example.demo.app.domain.model; 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.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@@ -11,4 +18,25 @@ public class AllocationModel {
private Long courseId; private Long courseId;
private Integer allocationRatio; 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);
}
} }

View File

@@ -3,6 +3,7 @@ package com.example.demo.app.domain.model;
import java.util.List; import java.util.List;
import com.example.demo.app.infra.entity.CategoryEntity; import com.example.demo.app.infra.entity.CategoryEntity;
import com.example.demo.app.infra.entity.UserEntity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@@ -27,4 +28,15 @@ public class CategoryModel {
return categoryEntityList.stream().map(CategoryModel::convertFrom).toList(); 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);
}
} }

View File

@@ -3,6 +3,7 @@ package com.example.demo.app.domain.model;
import java.util.List; import java.util.List;
import com.example.demo.app.infra.entity.CourseEntity; import com.example.demo.app.infra.entity.CourseEntity;
import com.example.demo.app.infra.entity.UserEntity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@@ -25,4 +26,12 @@ public class CourseModel {
public static List<CourseModel> convertFrom(List<CourseEntity> courseEntityList) { public static List<CourseModel> convertFrom(List<CourseEntity> courseEntityList) {
return courseEntityList.stream().map(CourseModel::convertFrom).toList(); return courseEntityList.stream().map(CourseModel::convertFrom).toList();
} }
public static CourseEntity convertTo(CourseModel courseModel, List<UserEntity> userEntityList) {
return new CourseEntity(
courseModel.getCourseId(),
courseModel.getCourseName(),
courseModel.getDescription(),
userEntityList);
}
} }

View File

@@ -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());
}
}

View File

@@ -1,8 +1,11 @@
package com.example.demo.app.domain.model; package com.example.demo.app.domain.model;
import java.time.LocalDate; 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.GoalEntity;
import com.example.demo.app.infra.entity.UserEntity;
import com.example.demo.app.presentation.form.GoalForm; import com.example.demo.app.presentation.form.GoalForm;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@@ -28,7 +31,11 @@ public class GoalModel {
private Integer currentAmount; // 現在の資産 private Integer currentAmount; // 現在の資産
public static GoalModel convertFrom(GoalEntity goalEntity) { private Long userId;
private List<Integer> savingList;
public static GoalModel convertFrom(GoalEntity goalEntity, int achievementRate, int currentAmount) {
return new GoalModel( return new GoalModel(
goalEntity.getGoalId(), goalEntity.getGoalId(),
goalEntity.getGoalTitle(), goalEntity.getGoalTitle(),
@@ -36,18 +43,21 @@ public class GoalModel {
goalEntity.getTargetAmount(), goalEntity.getTargetAmount(),
goalEntity.getDeadline(), goalEntity.getDeadline(),
goalEntity.getGoalComplete(), goalEntity.getGoalComplete(),
null,null); achievementRate,
currentAmount,
goalEntity.getUserEntity().getUserId(),
new ArrayList<>());
} }
public static GoalEntity convertTo(GoalModel goalModel) { public static GoalEntity convertTo(GoalModel goalModel, UserEntity userEntity) {
return new GoalEntity( return new GoalEntity(
goalModel.getGoalId(), goalModel.getGoalId(),
goalModel.getGoalTitle(), goalModel.getGoalTitle(),
goalModel.getGoalSubtitle(), goalModel.getGoalSubtitle(),
goalModel.getTargetAmount(), goalModel.getTargetAmount(),
goalModel.getDeadline(), goalModel.getDeadline(),
goalModel.getGoalComplete(), 0,
null); userEntity, 0);
} }
public static GoalModel convertFrom(GoalForm goalForm) { public static GoalModel convertFrom(GoalForm goalForm) {
@@ -58,7 +68,9 @@ public class GoalModel {
goalForm.getTargetAmount(), goalForm.getTargetAmount(),
goalForm.getDeadline(), goalForm.getDeadline(),
goalForm.getGoalComplete() goalForm.getGoalComplete()
,null,null); ,null,null,
goalForm.getUserId(),
new ArrayList<>());
} }
} }

View File

@@ -20,7 +20,6 @@ public class UserModel {
private Integer saving; private Integer saving;
private Integer annualIncome; private Integer annualIncome;
private Integer monthlyBudget; private Integer monthlyBudget;
private Long goalId;
private Long courseId; private Long courseId;
private Integer deleteFlag; private Integer deleteFlag;
@@ -36,7 +35,6 @@ public class UserModel {
userEntity.getSaving(), userEntity.getSaving(),
userEntity.getAnnualIncome(), userEntity.getAnnualIncome(),
userEntity.getMonthlyBudget(), userEntity.getMonthlyBudget(),
userEntity.getGoalEntity().getGoalId(),
userEntity.getCourseEntity().getCourseId(), userEntity.getCourseEntity().getCourseId(),
userEntity.getDeleteFlag() userEntity.getDeleteFlag()
); );

View File

@@ -8,4 +8,6 @@ public interface AllocationService {
public List<AllocationModel> findAll(); public List<AllocationModel> findAll();
public List<AllocationModel> save(List<AllocationModel> allocationModelList);
} }

View File

@@ -13,4 +13,12 @@ public interface CategoryService {
public CategoryModel findOneByCategoryName(String categoryName); public CategoryModel findOneByCategoryName(String categoryName);
public CategoryModel findByTransactionId(Long transactionId); 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();
} }

View File

@@ -11,4 +11,6 @@ public interface CourseService {
public CourseModel findById(Long courseId); public CourseModel findById(Long courseId);
public Long findByName(String courName); public Long findByName(String courName);
public CourseModel save(CourseModel courseModel, Long userId);
} }

View File

@@ -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);
}

View File

@@ -1,16 +1,22 @@
package com.example.demo.app.domain.service; package com.example.demo.app.domain.service;
import java.util.List;
import com.example.demo.app.domain.model.GoalModel; import com.example.demo.app.domain.model.GoalModel;
public interface GoalService { public interface GoalService {
GoalModel getGoalById(Long goalId); GoalModel getGoalById(Long goalId);
GoalModel getGoalByUserId(Long userId); public List<GoalModel> getGoalByUserId(Long userId);
GoalModel createGoal(GoalModel goalModel); public GoalModel createGoal(GoalModel goalModel, Long userId);
GoalModel updateGoal(GoalModel goalModel); GoalModel updateGoal(GoalModel goalModel, Long userId);
public void delete(Long goalId);
public void updateGoalComplete(Long userId);
// void deleteGoal(Long goalId); // void deleteGoal(Long goalId);

View File

@@ -5,7 +5,7 @@ import com.example.demo.app.presentation.form.UserForm;
public interface UserService { public interface UserService {
void register(UserForm userForm, Long courseId); public void register(UserForm userForm, Long courseId, Long userId);
public void updateCourse(Long userId, Long courseId); public void updateCourse(Long userId, Long courseId);

View File

@@ -1,5 +1,6 @@
package com.example.demo.app.domain.service.impl; package com.example.demo.app.domain.service.impl;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -8,6 +9,8 @@ import com.example.demo.app.domain.model.AllocationModel;
import com.example.demo.app.domain.service.AllocationService; import com.example.demo.app.domain.service.AllocationService;
import com.example.demo.app.infra.entity.AllocationEntity; import com.example.demo.app.infra.entity.AllocationEntity;
import com.example.demo.app.infra.repository.AllocationRepository; 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; import lombok.RequiredArgsConstructor;
@@ -15,10 +18,34 @@ import lombok.RequiredArgsConstructor;
@RequiredArgsConstructor @RequiredArgsConstructor
public class AllocationServiceImpl implements AllocationService { public class AllocationServiceImpl implements AllocationService {
AllocationRepository allocationRepository; private final AllocationRepository allocationRepository;
private final CategoryRepository categoryRepository;
private final CourseRepository courseRepository;
public List<AllocationModel> findAll(){ public List<AllocationModel> findAll() {
return AllocationEntity.createAllocationModelList(allocationRepository.findAll()); return AllocationEntity.createAllocationModelList(allocationRepository.findAll());
} }
public List<AllocationModel> save(List<AllocationModel> allocationModelList) {
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> result = new ArrayList<>();
for (AllocationEntity allocationEntity : allocationEntityList) {
result.add(AllocationModel.convertFrom(allocationRepository.save(allocationEntity)));
}
return result;
}
} }

View File

@@ -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.domain.service.CategoryService;
import com.example.demo.app.infra.entity.CategoryEntity; import com.example.demo.app.infra.entity.CategoryEntity;
import com.example.demo.app.infra.repository.CategoryRepository; import com.example.demo.app.infra.repository.CategoryRepository;
import com.example.demo.app.infra.repository.UserRepository;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -17,6 +18,7 @@ import lombok.RequiredArgsConstructor;
public class CategoryServiceImpl implements CategoryService { public class CategoryServiceImpl implements CategoryService {
private final CategoryRepository categoryRepository; private final CategoryRepository categoryRepository;
private final UserRepository userRepository;
public List<CategoryModel> findAll() { public List<CategoryModel> findAll() {
@@ -52,5 +54,29 @@ public class CategoryServiceImpl implements CategoryService {
return CategoryModel.convertFrom(categoryRepository.findByTransactionId(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());
}
} }

View File

@@ -1,5 +1,6 @@
package com.example.demo.app.domain.service.impl; package com.example.demo.app.domain.service.impl;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -7,7 +8,9 @@ import org.springframework.stereotype.Service;
import com.example.demo.app.domain.model.CourseModel; import com.example.demo.app.domain.model.CourseModel;
import com.example.demo.app.domain.service.CourseService; import com.example.demo.app.domain.service.CourseService;
import com.example.demo.app.infra.entity.CourseEntity; import com.example.demo.app.infra.entity.CourseEntity;
import com.example.demo.app.infra.entity.UserEntity;
import com.example.demo.app.infra.repository.CourseRepository; import com.example.demo.app.infra.repository.CourseRepository;
import com.example.demo.app.infra.repository.UserRepository;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -16,6 +19,7 @@ import lombok.RequiredArgsConstructor;
public class CourseServiceImpl implements CourseService { public class CourseServiceImpl implements CourseService {
private final CourseRepository courseRepository; private final CourseRepository courseRepository;
private final UserRepository userRepository;
public List<CourseModel> findAll(){ public List<CourseModel> findAll(){
@@ -29,4 +33,13 @@ public class CourseServiceImpl implements CourseService {
public Long findByName(String courseName) { public Long findByName(String courseName) {
return courseRepository.findByCourseName(courseName).getCourseId(); return courseRepository.findByCourseName(courseName).getCourseId();
} }
public CourseModel save(CourseModel courseModel, Long userId) {
List<UserEntity> userEntityList = new ArrayList<>();
userEntityList.add(userRepository.findById(userId).get());
return CourseModel.convertFrom( courseRepository.save( CourseModel.convertTo(courseModel, userEntityList)));
}
} }

View File

@@ -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());
}
}

View File

@@ -1,5 +1,10 @@
package com.example.demo.app.domain.service.impl; 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 org.springframework.stereotype.Service;
import com.example.demo.app.domain.model.GoalModel; import com.example.demo.app.domain.model.GoalModel;
@@ -7,6 +12,7 @@ import com.example.demo.app.domain.service.GoalService;
import com.example.demo.app.infra.entity.GoalEntity; import com.example.demo.app.infra.entity.GoalEntity;
import com.example.demo.app.infra.entity.UserEntity; import com.example.demo.app.infra.entity.UserEntity;
import com.example.demo.app.infra.repository.GoalRepository; 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 com.example.demo.app.infra.repository.UserRepository;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -17,18 +23,19 @@ public class GoalServiceImpl implements GoalService {
private final GoalRepository goalRepository; private final GoalRepository goalRepository;
private final UserRepository userRepository; private final UserRepository userRepository;
private final TransactionRepository transactionRepository;
@Override @Override
public GoalModel getGoalById(Long goalId) { public GoalModel getGoalById(Long goalId) {
GoalEntity goalEntity = goalRepository.findById(goalId).orElse(null); GoalEntity goalEntity = goalRepository.findById(goalId).orElse(null);
return GoalModel.convertFrom(goalEntity); return GoalModel.convertFrom(goalEntity, 0, 0);
} }
@Override @Override
public GoalModel getGoalByUserId(Long userId) { public List<GoalModel> getGoalByUserId(Long userId) {
UserEntity userEntity = userRepository.findById(userId).orElseThrow(); UserEntity userEntity = userRepository.findById(userId).orElseThrow();
GoalEntity goalEntity = userEntity.getGoalEntity(); List<GoalEntity> goalEntityList = goalRepository.findAllByUserId(userId);
// 収支の合計を計算(収入はプラス、支出はマイナス) // 収支の合計を計算(収入はプラス、支出はマイナス)
int transactionTotal = userEntity.getTransactionEntityList().stream() int transactionTotal = userEntity.getTransactionEntityList().stream()
@@ -42,42 +49,63 @@ public class GoalServiceImpl implements GoalService {
int currentAmount = userEntity.getSaving() + transactionTotal; int currentAmount = userEntity.getSaving() + transactionTotal;
// 達成率(%) = 現在の資産 ÷ 目標金額 × 100 // 達成率(%) = 現在の資産 ÷ 目標金額 × 100
int achievementRate =
(goalEntity.getTargetAmount() == null)
? 0 :
(int) ((currentAmount * 100.0) / goalEntity.getTargetAmount());
GoalModel goalModel = GoalModel.convertFrom(goalEntity); List<GoalModel> goalModelList = new ArrayList<GoalModel>();
return new GoalModel( goalEntityList.stream()
goalModel.getGoalId(), .forEach(goalEntity -> goalModelList.add(GoalModel.convertFrom(goalEntity,
goalModel.getGoalTitle(), (goalEntity.getTargetAmount() == null)
goalModel.getGoalSubtitle(), ? 0
goalModel.getTargetAmount(), : (int) ((currentAmount * 100.0) / goalEntity.getTargetAmount()),
goalModel.getDeadline(), currentAmount)));
goalModel.getGoalComplete(),
achievementRate,
currentAmount); return goalModelList;
} }
@Override @Override
public GoalModel createGoal(GoalModel goalModel) { public GoalModel createGoal(GoalModel goalModel, Long userId) {
GoalEntity goalEntity = GoalModel.convertTo(goalModel); GoalEntity goalEntity = GoalModel.convertTo(goalModel, userRepository.findById(userId).get());
GoalEntity savedGoalEntity = goalRepository.save(goalEntity); GoalEntity savedGoalEntity = goalRepository.save(goalEntity);
return GoalModel.convertFrom(savedGoalEntity); return GoalModel.convertFrom(savedGoalEntity, 0, 0);
} }
@Override @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); 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());
}
});
} }
} }

View File

@@ -25,7 +25,7 @@ public class UserServiceImpl implements UserService {
private final CourseRepository courseRepository; private final CourseRepository courseRepository;
@Override @Override
public void register(UserForm userForm, Long courseId) { public void register(UserForm userForm, Long courseId, Long userId) {
UserEntity userEntity = new UserEntity(); UserEntity userEntity = new UserEntity();
@@ -44,12 +44,11 @@ public class UserServiceImpl implements UserService {
GoalEntity goalEntity = new GoalEntity(); GoalEntity goalEntity = new GoalEntity();
goalEntity.setTargetAmount(Integer.parseInt(String.valueOf(userForm.getGoalId()))); goalEntity.setTargetAmount(Integer.parseInt(String.valueOf(userForm.getGoalId())));
goalEntity.setUserEntity(userRepository.findById(userId).get());
CourseEntity courseEntity = courseRepository.findById(courseId).orElse(null); CourseEntity courseEntity = courseRepository.findById(courseId).orElse(null);
userEntity.setQuestionEntity(questionEntity); userEntity.setQuestionEntity(questionEntity);
userEntity.setGoalEntity(goalRepository.save(
goalEntity));
userEntity.setCourseEntity(courseEntity); userEntity.setCourseEntity(courseEntity);
userEntity.setDeleteFlag(0); userEntity.setDeleteFlag(0);

View File

@@ -4,9 +4,12 @@ import java.util.List;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType; import jakarta.persistence.GenerationType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import jakarta.persistence.Table; import jakarta.persistence.Table;
@@ -32,6 +35,13 @@ public class CategoryEntity {
@Column(name = "transaction_type", nullable = false) @Column(name = "transaction_type", nullable = false)
private Integer transactionType; private Integer transactionType;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private UserEntity userEntity;
@Column(name = "delete_flag")
private Integer deleteFlag;
@OneToMany(mappedBy = "categoryEntity") @OneToMany(mappedBy = "categoryEntity")
private List<TransactionEntity> transactionEntity; private List<TransactionEntity> transactionEntity;

View File

@@ -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)
private String fixedCostName;
@Column(name = "amount", nullable = false)
private Integer amount;
}

View File

@@ -4,10 +4,12 @@ import java.time.LocalDate;
import jakarta.persistence.Column; import jakarta.persistence.Column;
import jakarta.persistence.Entity; import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue; import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType; import jakarta.persistence.GenerationType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.OneToOne; import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@@ -41,7 +43,10 @@ public class GoalEntity {
@Column(name = "goal_complete", nullable = false) @Column(name = "goal_complete", nullable = false)
private Integer goalComplete = 0; private Integer goalComplete = 0;
@OneToOne(mappedBy = "goalEntity") @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private UserEntity userEntity; private UserEntity userEntity;
private Integer deleteFlag;
} }

View File

@@ -1,5 +0,0 @@
package com.example.demo.app.infra.entity;
public class TestController6 {
}

View File

@@ -12,7 +12,6 @@ import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne; import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany; import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@@ -65,9 +64,8 @@ public class UserEntity {
@JoinColumn(name = "secret_question_id") @JoinColumn(name = "secret_question_id")
private QuestionEntity questionEntity; private QuestionEntity questionEntity;
@OneToOne(fetch = FetchType.LAZY) @OneToMany(mappedBy = "userEntity")
@JoinColumn(name = "goal_id") private List<GoalEntity> goalEntityList;
private GoalEntity goalEntity;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "course_id") @JoinColumn(name = "course_id")

View File

@@ -1,5 +1,7 @@
package com.example.demo.app.infra.repository; package com.example.demo.app.infra.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
@@ -15,4 +17,10 @@ public interface CategoryRepository extends JpaRepository<CategoryEntity, Long>
@Query("select c from CategoryEntity c inner join TransactionEntity t on c.categoryId = t.categoryEntity.categoryId where t.transactionId = :transactionId") @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); 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();
} }

View File

@@ -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);
}

View File

@@ -1,6 +1,10 @@
package com.example.demo.app.infra.repository; package com.example.demo.app.infra.repository;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository; 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 org.springframework.stereotype.Repository;
import com.example.demo.app.infra.entity.GoalEntity; import com.example.demo.app.infra.entity.GoalEntity;
@@ -8,4 +12,11 @@ import com.example.demo.app.infra.entity.GoalEntity;
@Repository @Repository
public interface GoalRepository extends JpaRepository<GoalEntity, Long> { 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);
} }

View File

@@ -0,0 +1,87 @@
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.form.CategoryForm;
import lombok.RequiredArgsConstructor;
@Controller
@RequiredArgsConstructor
public class CategoryController {
private final CategoryService categoryService;
@GetMapping("/category/list")
public String categoryListGet(Model model, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
List<CategoryForm> categoryFormList = CategoryForm.convertFrom(categoryService.findAllByuserId(loginUser.getUserId()));
model.addAttribute("categoryFormList", categoryFormList);
return "category-list";
}
@GetMapping("/category/create")
public String categoryCreateGet(@ModelAttribute CategoryForm categoryForm) {
return "category-create";
}
@PostMapping("/category/create")
public String categoryCreatePost(@ModelAttribute CategoryForm categoryForm, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
categoryService.save(CategoryForm.convertTo(categoryForm), loginUser.getUserId());
return "redirect:/category/list";
}
@GetMapping("/category/update")
public String categoryUpdateGet(Model model, Long categoryId) {
CategoryForm categoryForm = CategoryForm.convertFrom(categoryService.findOne(categoryId));
model.addAttribute("categoryId", categoryId);
model.addAttribute("categoryForm", categoryForm);
return "category-update";
}
@PostMapping("/category/update")
public String categoryUpdatePost(@ModelAttribute CategoryForm categoryForm, HttpSession session, Long categoryId) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
categoryForm.setCategoryId(categoryId);
categoryService.save(CategoryForm.convertTo(categoryForm), loginUser.getUserId());
return "redirect:/category/list";
}
@PostMapping("/category/delete")
public String categoryDeletePost(Long categoryId) {
categoryService.delete(categoryId);
return "redirect:/category/list";
}
}

View File

@@ -1,5 +1,8 @@
package com.example.demo.app.presentation.controller; package com.example.demo.app.presentation.controller;
import java.util.ArrayList;
import java.util.List;
import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@@ -10,30 +13,31 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.aop.aspect.SessionCheck; import com.example.demo.aop.aspect.SessionCheck;
import com.example.demo.app.domain.model.AllocationModel;
import com.example.demo.app.domain.model.LoginModel; 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.CourseInfoService;
import com.example.demo.app.domain.service.CourseService; import com.example.demo.app.domain.service.CourseService;
import com.example.demo.app.domain.service.UserService; import com.example.demo.app.domain.service.UserService;
import com.example.demo.app.presentation.form.AllocationFormList;
import com.example.demo.app.presentation.form.CourseForm; import com.example.demo.app.presentation.form.CourseForm;
import com.example.demo.app.presentation.form.CourseInfoForm; import com.example.demo.app.presentation.form.CourseInfoForm;
import com.example.demo.app.presentation.form.UserForm; import com.example.demo.app.presentation.form.UserForm;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@Controller @Controller
@RequiredArgsConstructor @RequiredArgsConstructor
public class CourseController { public class CourseController {
private final CourseService courseService; private final CourseService courseService;
private final CourseInfoService courseInfoService; private final CourseInfoService courseInfoService;
private final UserService userService; private final UserService userService;
private final AllocationService allocationService;
@PostMapping("/user/register/course")
public String showSelectCourse(@ModelAttribute UserForm userForm, Model model, HttpSession session) {
@PostMapping("/user/register/course")
public String showSelectCourse(@ModelAttribute UserForm userForm, Model model, HttpSession session) {
session.setAttribute("userForm", userForm); session.setAttribute("userForm", userForm);
model.addAttribute("mode", "regist"); model.addAttribute("mode", "regist");
@@ -41,15 +45,13 @@ public class CourseController {
model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll())); model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll()));
model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll())); model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll()));
return "select_course"; return "select_course";
}
} @SessionCheck
@GetMapping("/course")
@SessionCheck public String showChangeCourse(Model model, HttpSession session) {
@GetMapping("/course")
public String showChangeCourse(Model model, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
Long userId = loginUser.getUserId(); Long userId = loginUser.getUserId();
@@ -60,22 +62,64 @@ public class CourseController {
model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll())); model.addAttribute("courseList", CourseForm.convertFrom(courseService.findAll()));
model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll())); model.addAttribute("courseInfoList", CourseInfoForm.convertFrom(courseInfoService.findAll()));
return "select_course"; return "select_course";
}
} @SessionCheck
@PostMapping("/change")
public String changeCourse(@RequestParam Long courseId, HttpSession httpSession) {
@SessionCheck LoginModel loginUser = (LoginModel) httpSession.getAttribute("loginUser");
@PostMapping("/change")
public String changeCourse(@RequestParam Long courseId, HttpSession httpSession) {
LoginModel loginUser = (LoginModel) httpSession.getAttribute("loginUser"); userService.updateCourse(loginUser.getUserId(), courseId);
userService.updateCourse(loginUser.getUserId(), courseId); return "redirect:/menu";
}
return "redirect:/menu"; @SessionCheck
} @GetMapping("/course/create")
public String createCourseGet(@ModelAttribute CourseForm courseForm, HttpSession session) {
return "course_create";
}
@SessionCheck
@PostMapping("/course/create/ratio")
public String createCourse(@ModelAttribute CourseForm courseForm, @ModelAttribute AllocationFormList allocationFormList,
HttpSession session, Model model) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
CourseForm form = CourseForm.convertFrom(courseService.save(CourseForm.convertTo(courseForm), loginUser.getUserId()));
session.setAttribute("courseId", form.getCourseId());
return "course_create_ratio";
}
@SessionCheck
@PostMapping("/course/create")
public String createCoursePost(@ModelAttribute AllocationFormList allocationFormList, HttpSession session) {
List<AllocationModel> allocationModelList = new ArrayList<>();
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId1(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio1()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId2(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio2()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId3(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio3()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId4(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio4()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId5(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio5()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId6(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio6()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId7(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio7()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId8(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio8()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId9(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio9()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId10(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio10()));
allocationModelList.add(new AllocationModel(allocationFormList.getCategoryId11(), (Long) session.getAttribute("courseId"), allocationFormList.getAllocationRatio11()));
allocationService.save(allocationModelList);
return "redirect:/course";
}
} }

View File

@@ -0,0 +1,120 @@
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.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("/fixed-cost/list")
public String getFixedCostList(
HttpSession session, Model model, LocalDate today) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
if (today == null) {
today = (LocalDate) session.getAttribute("today");
}
List<FixedCostForm> fixedCostFormList = FixedCostForm.convertFrom(fixedCostService.findAllByUserId(loginUser.getUserId()));
fixedCostFormList.forEach(fixedCostForm -> fixedCostForm.setCategoryName(categoryService.findOne(fixedCostForm.getCategoryId()).getCategoryName()));
model.addAttribute("fixedCostFormList", fixedCostFormList);
model.addAttribute("today", today);
return "fixed_cost";
}
@SessionCheck
@GetMapping("/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("expenseList", expenseList);
model.addAttribute("incomeList", incomeList);
model.addAttribute("today", today);
return "fixed_cost_create";
}
@SessionCheck
@PostMapping("/fixed-cost/create")
public String postFixedCostCreate(
HttpSession session, @ModelAttribute FixedCostForm fixedCostForm, Model model, LocalDate today) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
fixedCostForm.setUserId(loginUser.getUserId());
fixedCostService.save(FixedCostForm.convertTo(fixedCostForm));
session.setAttribute("today", today);
return "redirect:/fixed-cost/list";
}
@SessionCheck
@PostMapping("/fixed-cost/delete")
public String postFixedCostDelete(Long fixedCostId, LocalDate today, HttpSession session) {
fixedCostService.delete(fixedCostId);
session.setAttribute("today", today);
return "redirect:/fixed-cost/list";
}
}

View File

@@ -1,5 +1,14 @@
package com.example.demo.app.presentation.controller; 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 jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@@ -12,8 +21,15 @@ import org.springframework.web.bind.annotation.RequestMapping;
import com.example.demo.aop.aspect.SessionCheck; import com.example.demo.aop.aspect.SessionCheck;
import com.example.demo.app.domain.model.GoalModel; import com.example.demo.app.domain.model.GoalModel;
import com.example.demo.app.domain.model.LoginModel; 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.GoalService;
import com.example.demo.app.domain.service.TransactionService;
import com.example.demo.app.domain.service.UserService;
import com.example.demo.app.presentation.form.CategoryForm;
import com.example.demo.app.presentation.form.GoalForm; 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; import lombok.RequiredArgsConstructor;
@@ -23,31 +39,194 @@ import lombok.RequiredArgsConstructor;
public class GoalController { public class GoalController {
private final GoalService goalService; private final GoalService goalService;
private final TransactionService transactionService;
private final UserService userService;
private final CategoryService categoryService;
@SessionCheck @SessionCheck
@GetMapping("") @GetMapping("")
public String getGoal(Model model, HttpSession session) { public String getGoal(
Model model,
HttpSession session,
Long goalId) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
Long userId = loginUser.getUserId(); Long userId = loginUser.getUserId();
goalService.updateGoalComplete(userId);
List<GoalModel> goalModelList = goalService.getGoalByUserId(userId);
GoalModel goalModel = goalService.getGoalByUserId(userId); List<GoalForm> goalFormList1 = GoalForm.convertFrom(goalModelList);
GoalForm goalForm = GoalForm.convertFrom(goalModel);
List<GoalForm> goalFormList = goalFormList1.stream()
.filter(goalForm -> goalForm.getGoalComplete() == 0)
.collect(Collectors.toList());
model.addAttribute(
"goalFormList",
goalFormList);
if (goalFormList.isEmpty()) {
return "goal_view";
}
GoalForm graphGoal;
if (goalId == null) {
graphGoal = goalFormList.getFirst();
} else {
graphGoal = goalFormList.stream()
.filter(goal -> goal.getGoalId().equals(goalId))
.findFirst()
.orElse(
goalFormList.getFirst());
}
model.addAttribute(
"graphGoal",
graphGoal);
int currentAmount = graphGoal.getCurrentAmount();
int targetAmount = graphGoal.getTargetAmount();
LocalDate startDate = LocalDate.of(
LocalDate.now().getYear(),
1,
1);
LocalDate today = LocalDate.now();
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(
"achievementList",
achievementList);
model.addAttribute("goalForm", goalForm);
return "goal_view"; return "goal_view";
} }
@SessionCheck @SessionCheck
@GetMapping("/edit") @GetMapping("/edit")
public String editGoal(Model model, HttpSession session) { public String editGoal(Model model, HttpSession session, Long goalId) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser"); LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
Long userId = loginUser.getUserId(); Long userId = loginUser.getUserId();
GoalModel goalModel = goalService.getGoalByUserId(userId); GoalForm goalForm = GoalForm.convertFrom(goalService.getGoalById(goalId));
GoalForm goalForm = GoalForm.convertFrom(goalModel);
model.addAttribute("goalForm", goalForm); model.addAttribute("goalForm", goalForm);
return "goal_edit"; return "goal_edit";
@@ -61,17 +240,78 @@ public class GoalController {
Long userId = loginUser.getUserId(); Long userId = loginUser.getUserId();
// 本人の目標かどうかを確認してから更新する // // 本人の目標かどうかを確認してから更新する
GoalModel currentGoal = goalService.getGoalByUserId(userId); // GoalModel currentGoal = goalService.getGoalByUserId(userId);
//
if (!currentGoal.getGoalId().equals(goalForm.getGoalId())) { // if (!currentGoal.getGoalId().equals(goalForm.getGoalId())) {
return "redirect:/goal"; // 他人のデータを更新しようとしたら弾く // return "redirect:/goal"; // 他人のデータを更新しようとしたら弾く
} // }
GoalModel goalModel = GoalModel.convertFrom(goalForm); GoalModel goalModel = GoalModel.convertFrom(goalForm);
goalService.updateGoal(goalModel); goalService.updateGoal(goalModel, userId);
return "redirect:/goal"; return "redirect:/goal";
} }
@SessionCheck
@GetMapping("/create")
public String createGoalGet(@ModelAttribute GoalForm goalForm, HttpSession session) {
return "goal_create";
}
@SessionCheck
@PostMapping("/create")
public String createGoalPost(@ModelAttribute GoalForm goalForm, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
Long userId = loginUser.getUserId();
goalService.createGoal(GoalModel.convertFrom(goalForm), userId);
return "redirect:/goal";
}
@SessionCheck
@PostMapping("/delete") // フラグ考慮してないため、今度修正必要
public String deleteGoal(Long goalId, Long record) {
goalService.delete(goalId);
if (record == null) {
return "redirect:/goal";
} else {
return "redirect:/goal/record";
}
}
@SessionCheck
@GetMapping("/record")
public String getRecord(HttpSession session, Model model) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
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) {
goalCompleteFormList.add(goalForm);
}
});
model.addAttribute(
"goalCompleteFormList",
goalCompleteFormList);
return "goal_record";
}
} }

View File

@@ -3,6 +3,7 @@ package com.example.demo.app.presentation.controller;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.YearMonth; import java.time.YearMonth;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -20,12 +21,13 @@ import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.aop.aspect.SessionCheck; import com.example.demo.aop.aspect.SessionCheck;
import com.example.demo.app.domain.model.LoginModel; import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.service.CategoryService; 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.GoalService;
import com.example.demo.app.domain.service.TransactionService; import com.example.demo.app.domain.service.TransactionService;
import com.example.demo.app.domain.service.UserService; import com.example.demo.app.domain.service.UserService;
import com.example.demo.app.presentation.form.CategoryForm; import com.example.demo.app.presentation.form.CategoryForm;
import com.example.demo.app.presentation.form.Expense; import com.example.demo.app.presentation.form.Expense;
import com.example.demo.app.presentation.form.GoalForm; import com.example.demo.app.presentation.form.FixedCostForm;
import com.example.demo.app.presentation.form.Income; import com.example.demo.app.presentation.form.Income;
import com.example.demo.app.presentation.form.TransactionForm; import com.example.demo.app.presentation.form.TransactionForm;
import com.example.demo.app.presentation.form.UserForm; import com.example.demo.app.presentation.form.UserForm;
@@ -40,6 +42,7 @@ public class TransactionController {
private final CategoryService categoryService; private final CategoryService categoryService;
private final GoalService goalService; private final GoalService goalService;
private final UserService userService; private final UserService userService;
private final FixedCostService fixedCostService;
// 一覧画面 // 一覧画面
@SessionCheck @SessionCheck
@@ -182,16 +185,34 @@ public class TransactionController {
@SessionCheck @SessionCheck
@GetMapping("/transaction/create") @GetMapping("/transaction/create")
public String createOneGet(@RequestParam(defaultValue = "") LocalDate today, public String createOneGet(@RequestParam(defaultValue = "") LocalDate today,
Model model) { Long fixedCostId,
Model model, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
if (today == null) { if (today == null) {
today = LocalDate.now(); today = LocalDate.now();
} }
List<CategoryForm> categoryFormList = CategoryForm.convertFrom(categoryService.findAll());
TransactionForm transactionForm = new TransactionForm(); TransactionForm transactionForm = new TransactionForm();
transactionForm.setTransactionDate(today); 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());
}
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);
}
}
System.out.println(transactionForm.getCategoryName() + " " + transactionForm.getAmount()); System.out.println(transactionForm.getCategoryName() + " " + transactionForm.getAmount());
@@ -223,13 +244,24 @@ public class TransactionController {
@SessionCheck @SessionCheck
@GetMapping("/transaction/update") @GetMapping("/transaction/update")
public String updateOneGet(@RequestParam Long transactionId, @RequestParam(defaultValue = "") LocalDate today, public String updateOneGet(@RequestParam Long transactionId, @RequestParam(defaultValue = "") LocalDate today,
Model model) { Model model, HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
if (today == null) { if (today == null) {
today = LocalDate.now(); today = LocalDate.now();
} }
List<CategoryForm> categoryFormList = CategoryForm.convertFrom(categoryService.findAll()); 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( TransactionForm transactionForm = TransactionForm.convertFrom(
transactionService.findByTransactionId(transactionId), transactionService.findByTransactionId(transactionId),
@@ -339,19 +371,19 @@ public class TransactionController {
model.addAttribute("totalIncome", totalIncome); model.addAttribute("totalIncome", totalIncome);
model.addAttribute("totalExpense", totalExpense); model.addAttribute("totalExpense", totalExpense);
GoalForm goalForm = GoalForm.convertFrom(goalService.getGoalByUserId(loginUser.getUserId())); // List<GoalForm> goalForm = GoalForm.convertFrom(goalService.getGoalByUserId(loginUser.getUserId()));
UserForm userForm = UserForm.convertFrom(userService.findByUserId(loginUser.getUserId())); UserForm userForm = UserForm.convertFrom(userService.findByUserId(loginUser.getUserId()));
model.addAttribute("achievementRate", goalForm.getAchievementRate()); // model.addAttribute("achievementRate", goalForm.getAchievementRate());
//
model.addAttribute("currentAmount", goalForm.getCurrentAmount()); // model.addAttribute("currentAmount", goalForm.getCurrentAmount());
//
model.addAttribute("targetAmount", goalForm.getTargetAmount()); // model.addAttribute("targetAmount", goalForm.getTargetAmount());
model.addAttribute("saving", userForm.getSaving()); model.addAttribute("saving", userForm.getSaving());
model.addAttribute("deadline", goalForm.getDeadline()); // model.addAttribute("deadline", goalForm.getDeadline());
return "menu"; return "menu";
} }

View File

@@ -11,6 +11,7 @@ import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.service.CourseService; import com.example.demo.app.domain.service.CourseService;
import com.example.demo.app.domain.service.QuestionService; import com.example.demo.app.domain.service.QuestionService;
import com.example.demo.app.domain.service.UserService; import com.example.demo.app.domain.service.UserService;
@@ -83,9 +84,11 @@ public class UserController {
Model model, Model model,
HttpSession session) { HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
Long courseId = courseService.findByName((String) session.getAttribute("selectedCourseName")); Long courseId = courseService.findByName((String) session.getAttribute("selectedCourseName"));
userService.register(userForm, courseId); userService.register(userForm, courseId, loginUser.getUserId());
return "redirect:/login"; return "redirect:/login";
} }

View File

@@ -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;
}

View File

@@ -25,4 +25,11 @@ public class CategoryForm {
return categoryModelList.stream().map(CategoryForm::convertFrom).toList(); return categoryModelList.stream().map(CategoryForm::convertFrom).toList();
} }
public static CategoryModel convertTo(CategoryForm categoryForm) {
return new CategoryModel(
categoryForm.getCategoryId(),
categoryForm.getCategoryName(),
categoryForm.getTransactionType());
}
} }

View File

@@ -30,4 +30,12 @@ public class CourseForm {
return courseModelList.stream().map(CourseForm::convertFrom).toList(); return courseModelList.stream().map(CourseForm::convertFrom).toList();
} }
public static CourseModel convertTo(CourseForm courseForm) {
return new CourseModel(
courseForm.getCourseId(),
courseForm.getCourseName(),
courseForm.getDescription()
);
}
} }

View File

@@ -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());
}
}

View File

@@ -1,6 +1,7 @@
package com.example.demo.app.presentation.form; package com.example.demo.app.presentation.form;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
@@ -32,6 +33,8 @@ public class GoalForm {
private Integer currentAmount; // 現在の資産 private Integer currentAmount; // 現在の資産
private Long userId;
public static GoalForm convertFrom(GoalModel goalModel) { public static GoalForm convertFrom(GoalModel goalModel) {
return new GoalForm( return new GoalForm(
goalModel.getGoalId(), goalModel.getGoalId(),
@@ -41,11 +44,12 @@ public class GoalForm {
goalModel.getDeadline(), goalModel.getDeadline(),
goalModel.getGoalComplete(), goalModel.getGoalComplete(),
goalModel.getAchievementRate(), goalModel.getAchievementRate(),
goalModel.getCurrentAmount()); goalModel.getCurrentAmount(),
goalModel.getUserId());
} }
// public static List<GoalForm> convertFrom(List<GoalModel> goalModelList) { public static List<GoalForm> convertFrom(List<GoalModel> goalModelList) {
// return goalModelList.stream().map(GoalForm::convertFrom).toList(); return goalModelList.stream().map(GoalForm::convertFrom).toList();
// } }
} }

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -36,7 +36,7 @@ public class UserForm {
userModel.getSaving(), userModel.getSaving(),
userModel.getAnnualIncome(), userModel.getAnnualIncome(),
userModel.getMonthlyBudget(), userModel.getMonthlyBudget(),
userModel.getGoalId(), 0L,
userModel.getCourseId() userModel.getCourseId()
); );
} }

View File

@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</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 class="pb-5 pt-5">
<div th:replace="~{header :: header}"></div>
<h1>カテゴリ登録</h1>
<form th:action="@{/category/create}" th:object="${categoryForm}" method="post">
<div>
<label for="categoryName">カテゴリ名</label>
<input type="text" id="categoryName" th:field="*{categoryName}">
</div>
<br>
<div>
<label for="transactionType">収入・支出</label>
<select id="transactionType" th:field="*{transactionType}">
<option value="">選択してください</option>
<option value="0">支出</option>
<option value="1">収入</option>
</select>
</div>
<br>
<button type="submit">登録</button>
</form>
<div th:replace="~{footer :: footer}"></div>
</body>
</html>

View File

@@ -0,0 +1,63 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>カテゴリ一覧</title>
<link rel="stylesheet" th:href="@{/css/transaction_detail.css}">
<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>
<ul>
<li th:each="categoryForm : ${categoryFormList}" class="transaction-item">
<div>
<p>
カテゴリ名:
<span th:text="${categoryForm.categoryName}"></span>
<br>
収支区分:
<span th:if="${categoryForm.transactionType == 0}" th:text="|支出|"></span>
<span th:if="${categoryForm.transactionType == 1}" th:text="|収入|"></span>
</p>
</div>
<div class="transaction-buttons">
<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">削除</button>
</form>
<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">編集</button>
</form>
</div>
<hr>
<hr>
</li>
</ul>
</div>
<form th:action="@{/category/create}" method="get">
<input type="hidden" name="today" id="today" th:value="${today}">
<button type="submit">新規登録</button>
</form>
<div th:replace="~{footer :: footer}"></div>
</body>
</html>

View File

@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</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 class="pb-5 pt-5">
<div th:replace="~{header :: header}"></div>
<h1>カテゴリ編集</h1>
<form th:action="@{/category/update}" th:object="${categoryForm}" method="post">
<div>
<label for="categoryName">カテゴリ名</label>
<input type="text" id="categoryName" th:field="*{categoryName}">
</div>
<br>
<div>
<label for="transactionType">収入・支出</label>
<select id="transactionType" th:field="*{transactionType}">
<option value="">選択してください</option>
<option value="0">支出</option>
<option value="1">収入</option>
</select>
</div>
<br>
<input type="hidden" name="categoryId" th:value="${categoryId}">
<button type="submit">登録</button>
</form>
<div th:replace="~{footer :: footer}"></div>
</body>
</html>

View File

@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</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 class="pb-5 pt-5">
<div th:replace="~{header :: header}"></div>
<h1>コース登録</h1>
<form th:action="@{/course/create/ratio}" th:object="${courseForm}" method="post">
<div>
<label for="courseName">コース名</label>
<input type="text" id="courseName" th:field="*{courseName}">
</div>
<br>
<div>
<label for="description">説明</label>
<textarea id="description" th:field="*{description}" placeholder="説明を入力してください">
</textarea>
</div>
<br>
<button type="submit">登録</button>
</form>
<div th:replace="~{footer :: footer}"></div>
</body>
</html>

View File

@@ -0,0 +1,109 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</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 class="pb-5 pt-5">
<div th:replace="~{header :: header}"></div>
<h1>コース登録</h1>
<form th:action="@{/course/create}" th:object="${allocationFormList}" method="post">
<div>
<label for="allocationRatio1">給与</label>
<input type="number" id="allocationRatio1" th:field="*{allocationRatio1}">
</div>
<br>
<div>
<label for="allocationRatio2">賞与</label>
<input type="number" id="allocationRatio2" th:field="*{allocationRatio2}">
</div>
<br>
<div>
<label for="allocationRatio3">その他</label>
<input type="number" id="allocationRatio3" th:field="*{allocationRatio3}">
</div>
<br>
<div>
<label for="allocationRatio4">固定費</label>
<input type="number" id="allocationRatio4" th:field="*{allocationRatio4}">
</div>
<br>
<div>
<label for="allocationRatio5">食費</label>
<input type="number" id="allocationRatio5" th:field="*{allocationRatio5}">
</div>
<br>
<div>
<label for="allocationRatio6">交通費</label>
<input type="number" id="allocationRatio6" th:field="*{allocationRatio6}">
</div>
<br>
<div>
<label for="allocationRatio7">日用品費</label>
<input type="number" id="allocationRatio7" th:field="*{allocationRatio7}">
</div>
<br>
<div>
<label for="allocationRatio8">被服/美容費</label>
<input type="number" id="allocationRatio8" th:field="*{allocationRatio8}">
</div>
<br>
<div>
<label for="allocationRatio9">医療費</label>
<input type="number" id="allocationRatio9" th:field="*{allocationRatio9}">
</div>
<br>
<div>
<label for="allocationRatio10">趣味/娯楽費</label>
<input type="number" id="allocationRatio10" th:field="*{allocationRatio10}">
</div>
<br>
<div>
<label for="allocationRatio11">その他</label>
<input type="number" id="allocationRatio11" th:field="*{allocationRatio11}">
</div>
<br>
<button type="submit">登録</button>
</form>
<div th:replace="~{footer :: footer}"></div>
</body>
</html>

View File

@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>固定費詳細</title>
<link rel="stylesheet" th:href="@{/css/transaction_detail.css}">
<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>
<h1 th:text="${today}"></h1>
<div>
<ul>
<li th:each="fixedCostForm : ${fixedCostFormList}" class="transaction-item">
<div>
<p>
カテゴリ名:
<span th:text="${fixedCostForm.categoryName}"></span>
<br>
固定費名:
<span th:text="${fixedCostForm.fixedCostName}"></span>
<br>
金額:
<span th:text="${fixedCostForm.amount}"></span>
</p>
</div>
<div class="transaction-buttons">
<form th:action="@{/transaction/create}" method="get">
<input type="hidden" name="fixedCostId" th:value="${fixedCostForm.fixedCostId}">
<input type="hidden" name="today" th:value="${today}">
<button type="submit">登録</button>
</form>
<form th:action="@{/fixed-cost/delete}" method="post">
<input type="hidden" name="fixedCostId" th:value="${fixedCostForm.fixedCostId}">
<input type="hidden" name="today" th:value="${today}">
<button type="submit">削除</button>
</form>
</div>
<hr>
<hr>
</li>
</ul>
</div>
<form th:action="@{/fixed-cost/create}" method="get">
<input type="hidden" name="today" id="today" th:value="${today}">
<button type="submit">新規登録</button>
</form>
<div th:replace="~{footer :: footer}"></div>
</body>
</html>

View File

@@ -0,0 +1,129 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</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 class="pb-5 pt-5">
<div th:replace="~{header :: header}"></div>
<h1>取引登録</h1>
<form th:action="@{/fixed-cost/create}" th:object="${fixedCostForm}" method="post">
<div>
<label for="fixedCostName">固定費名</label>
<input type="text" id="fixedCostName" th:field="*{fixedCostName}" required>
</div>
<br>
<div>
<label for="transactionType">収入・支出</label>
<select id="transactionType">
<option value="">選択してください</option>
<option value="1">支出</option>
<option value="2">収入</option>
</select>
</div>
<br>
<div>
<label for="categoryId">カテゴリ</label>
<select id="categoryId" th:field="*{categoryId}">
<option value="">選択してください</option>
<option class="expenseListClass" th:each="category : ${expenseList}" th:value="${category.categoryId}"
th:text="${category.categoryName}">
</option>
<option class="incomeListClass" th:each="category : ${incomeList}" th:value="${category.categoryId}"
th:text="${category.categoryName}">
</option>
</select>
</div>
<br>
<div>
<label for="amount">金額</label>
<input type="number" id="amount" th:field="*{amount}" min="0" placeholder="金額を入力してください" required>
</div>
<br>
<input type="hidden" name="today" id="today" th:value="${today}">
<button type="submit">登録</button>
</form>
<div th:replace="~{footer :: footer}"></div>
<script>
const transactionType = document.getElementById("transactionType");
const categoryId = document.getElementById("categoryId");
const expenseList = document.getElementsByClassName("expenseListClass");
const incomeList = document.getElementsByClassName("incomeListClass");
transactionType.addEventListener("change", function () {
if (this.value === "1") {
for (let i = 0; i < expenseList.length; i++) {
expenseList[i].style.display = "";
}
for (let i = 0; i < incomeList.length; i++) {
incomeList[i].style.display = "none";
}
} else if (this.value === "2") {
for (let i = 0; i < expenseList.length; i++) {
expenseList[i].style.display = "none";
}
for (let i = 0; i < incomeList.length; i++) {
incomeList[i].style.display = "";
}
} else {
for (let i = 0; i < expenseList.length; i++) {
expenseList[i].style.display = "none";
}
for (let i = 0; i < incomeList.length; i++) {
incomeList[i].style.display = "none";
}
}
categoryId.value = "";
});
</script>
</body>
</html>

View File

@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<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>
<h1>目標作成</h1>
<form th:action="@{/goal/create}" th:object="${goalForm}" method="post">
<input type="hidden" th:field="*{goalId}">
<div>
<label>目標名</label>
<input type="text" th:field="*{goalTitle}" required>
</div>
<div>
<label>目標説明</label>
<textarea th:field="*{goalSubtitle}" required></textarea>
</div>
<div>
<label>目標金額</label>
<input type="number" th:field="*{targetAmount}" required min="1">
</div>
<div>
<label>目標達成期限</label>
<input type="date" th:field="*{deadline}" th:min="${#temporals.format(#temporals.createNow(), 'yyyy-MM-dd')}" required>
</div>
<button type="submit">更新する</button>
</form>
<div th:replace="~{footer :: footer}"></div>
</body>
</html>

View File

@@ -0,0 +1,89 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<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>
<h1>目標履歴</h1>
<div>
<ul>
<li th:each="goalForm : ${goalCompleteFormList}" class="transaction-item">
<div>
<p>
目標名:
<span th:text="${goalForm.goalTitle}">
</span>
<br>
目標説明:
<span th:text="${goalForm.goalSubtitle}">
</span>
<br>
目標金額:
<span th:text="${goalForm.targetAmount}">
</span>
<br>
目標達成期限:
<span th:text="${goalForm.deadline}">
</span>
<br>
</p>
</form>
</div>
<div class="transaction-buttons">
<form th:action="@{/goal/delete}" method="post">
<input type="hidden" name="goalId" th:value="${goalForm.goalId}">
<input type="hidden" name="record" th:value="1">
<button type="submit">
削除
</button>
</form>
</div>
</li>
</ul>
</div>
<form th:action="@{/goal}" method="get">
<button type="submit">
戻る
</button>
</form>
<div th:replace="~{footer :: footer}"></div>
</body>
</html>

View File

@@ -1,53 +1,199 @@
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"> <html xmlns:th="http://www.thymeleaf.org">
<head> <head>
<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" http-equiv="Content-Type"> <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1" http-equiv="Content-Type">
<title>目標詳細</title> <title>目標詳細</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" th:href="@{/css/style.css}"> <link rel="stylesheet" th:href="@{/css/style.css}">
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.0/chart.umd.min.js"></script>
</head> </head>
<body style="padding-top:80px; padding-bottom:80px;"> <body style="padding-top:80px; padding-bottom:80px;">
<div th:replace="~{header :: header}"></div> <div th:replace="~{header :: header}"></div>
<div class="main-container"> <div class="main-container">
<h1 class="page-title">目標詳細</h1> <h1 class="page-title">目標詳細</h1>
<table class="table"> <!-- -->
<tr> <div th:if="${graphGoal != null}">
<th>目標名</th>
<td th:text="${goalForm.goalTitle}"></td>
</tr>
<tr> <h2 th:text="${graphGoal.goalTitle}"></h2>
<th>目標説明</th>
<td th:text="${goalForm.goalSubtitle}"></td>
</tr>
<tr>
<th>目標金額</th>
<td th:text="${goalForm.targetAmount}"></td>
</tr>
<tr>
<th>目標達成期限</th>
<td th:text="${goalForm.deadline}"></td>
</tr>
<tr> <p>
<th>達成率</th> 目標金額:
<td th:text="${goalForm.achievementRate} + '%'"></td> <span th:text="${graphGoal.targetAmount}"></span>
</tr> </p>
</div>
</table> <div style="width: 600px; height: 300px;">
<canvas id="myChart"></canvas>
</div>
<a th:href="@{/goal/edit}" class="btn btn-sm btn-primary w-100">編集する</a>
</div> <script th:inline="javascript">
<div th:replace="~{footer :: footer}"></div> const months =
/*[[${achievementList.![month.monthValue]}]]*/[];
const achievementRates =
/*[[${achievementList.![achievementRate]}]]*/[];
const labels =
months.map(month => month + '月');
const myCt =
document.getElementById('myChart');
const myChart =
new Chart(myCt, {
type: 'bar',
data: {
labels: labels,
datasets: [
{
label: '達成率',
data: achievementRates,
backgroundColor:
'rgba(54, 162, 235, 0.5)',
borderColor:
'rgba(54, 162, 235, 1)',
borderWidth: 1
}
]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true,
max: 100,
ticks: {
callback: function (value) {
return value + '%';
}
}
}
}
}
});
</script>
<!-- -->
<div>
<ul>
<li th:each="goalForm : ${goalFormList}" class="transaction-item">
<div>
<form th:action="@{/goal}" method="get">
<table class="table">
<input type="radio" name="goalId" th:value="${goalForm.goalId}"
th:checked="${graphGoal != null and graphGoal.goalId == goalForm.goalId}"
onchange="this.form.submit()">
<tr>
<th>目標名</th>
<td th:text="${goalForm.goalTitle}"></td>
</tr>
<tr>
<th>目標説明</th>
<td th:text="${goalForm.goalSubtitle}"></td>
</tr>
<tr>
<th>目標金額</th>
<td th:text="${goalForm.targetAmount}"></td>
</tr>
<tr>
<th>目標達成期限</th>
<td th:text="${goalForm.deadline}"></td>
</tr>
<tr>
<th>達成率</th>
<td th:text="${goalForm.achievementRate} + '%'"></td>
</tr>
</table>
</form>
</div>
<div class="transaction-buttons">
<form th:action="@{/goal/edit}" method="get">
<input type="hidden" name="goalId" th:value="${goalForm.goalId}">
<button type="submit" class="btn btn-sm btn-primary w-100">
編集
</button>
</form>
<form th:action="@{/goal/delete}" method="post">
<input type="hidden" name="goalId" th:value="${goalForm.goalId}">
<button type="submit" class="btn btn-sm btn-primary w-100">
削除
</button>
</form>
</div>
</li>
</ul>
</div>
<form th:action="@{/goal/create}" method="get">
<button type="submit" class="btn btn-sm btn-primary w-100">
新規登録
</button>
</form>
<form th:action="@{/goal/record}" method="get">
<button type="submit" class="btn btn-sm btn-primary w-100">
履歴
</button>
</form>
<div th:replace="~{footer :: footer}"></div>
</body> </body>
</html> </html>

View File

@@ -138,6 +138,8 @@
</div> </div>
</div> </div>
<div class="card shadow-sm"> <div class="card shadow-sm">

View File

@@ -1,13 +1,14 @@
<!DOCTYPE html> <!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"> <html xmlns:th="http://www.thymeleaf.org">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" th:href="@{/css/style.css}"> <title>コース選択</title>
<title>コース選択</title>
</head> </head>
<body style="padding-top:80px; padding-bottom:80px;">
<body>
<div th:replace="~{header :: header}"></div> <div th:replace="~{header :: header}"></div>
<h1 class="page-title">コース選択</h1> <h1 class="page-title">コース選択</h1>
@@ -48,4 +49,5 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.7/dist/js/bootstrap.bundle.min.js"></script>
</body> </body>
</html> </html>

View File

@@ -105,6 +105,19 @@
</div> </div>
<form th:action="@{/transaction/create}" method="get">
<input type="hidden" name="today" id="today" th:value="${today}">
<button type="submit">新規登録</button>
</form>
<form th:action="@{/fixed-cost/list}" method="get">
<input type="hidden" name="today" th:value="${today}">
<button type="submit">固定費一覧</button>
</form>
<form th:action="@{/category/list}" method="get">
<input type="hidden" name="today" th:value="${today}">
<button type="submit">カテゴリ一覧</button>
</form>
<div th:replace="~{footer :: footer}"></div> <div th:replace="~{footer :: footer}"></div>
</body> </body>