18 Commits

Author SHA1 Message Date
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
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
25 changed files with 645 additions and 63 deletions

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

@@ -3,6 +3,7 @@ package com.example.demo.app.domain.model;
import java.time.LocalDate;
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;
@@ -28,7 +29,9 @@ public class GoalModel {
private Integer currentAmount; // 現在の資産
public static GoalModel convertFrom(GoalEntity goalEntity) {
private Long userId;
public static GoalModel convertFrom(GoalEntity goalEntity, int achievementRate, int currentAmount) {
return new GoalModel(
goalEntity.getGoalId(),
goalEntity.getGoalTitle(),
@@ -36,10 +39,12 @@ public class GoalModel {
goalEntity.getTargetAmount(),
goalEntity.getDeadline(),
goalEntity.getGoalComplete(),
null,null);
achievementRate,
currentAmount,
goalEntity.getUserEntity().getUserId());
}
public static GoalEntity convertTo(GoalModel goalModel) {
public static GoalEntity convertTo(GoalModel goalModel, UserEntity userEntity) {
return new GoalEntity(
goalModel.getGoalId(),
goalModel.getGoalTitle(),
@@ -47,7 +52,7 @@ public class GoalModel {
goalModel.getTargetAmount(),
goalModel.getDeadline(),
goalModel.getGoalComplete(),
null);
userEntity, 0);
}
public static GoalModel convertFrom(GoalForm goalForm) {
@@ -58,7 +63,8 @@ public class GoalModel {
goalForm.getTargetAmount(),
goalForm.getDeadline(),
goalForm.getGoalComplete()
,null,null);
,null,null,
goalForm.getUserId());
}
}

View File

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

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,18 @@
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 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);
// void deleteGoal(Long goalId);

View File

@@ -5,7 +5,7 @@ import com.example.demo.app.presentation.form.UserForm;
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);

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,8 @@
package com.example.demo.app.domain.service.impl;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import com.example.demo.app.domain.model.GoalModel;
@@ -21,14 +24,14 @@ public class GoalServiceImpl implements GoalService {
@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 getGoalByUserId(Long userId) {
public List<GoalModel> getGoalByUserId(Long userId) {
UserEntity userEntity = userRepository.findById(userId).orElseThrow();
GoalEntity goalEntity = userEntity.getGoalEntity();
List<GoalEntity> goalEntityList = goalRepository.findAllByUserId(userId);
// 収支の合計を計算(収入はプラス、支出はマイナス)
int transactionTotal = userEntity.getTransactionEntityList().stream()
@@ -42,42 +45,38 @@ public class GoalServiceImpl implements GoalService {
int currentAmount = userEntity.getSaving() + transactionTotal;
// 達成率(%) = 現在の資産 ÷ 目標金額 × 100
int achievementRate =
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());
? 0
: (int) ((currentAmount * 100.0) / goalEntity.getTargetAmount()),
currentAmount)));
GoalModel goalModel = GoalModel.convertFrom(goalEntity);
return new GoalModel(
goalModel.getGoalId(),
goalModel.getGoalTitle(),
goalModel.getGoalSubtitle(),
goalModel.getTargetAmount(),
goalModel.getDeadline(),
goalModel.getGoalComplete(),
achievementRate,
currentAmount);
return goalModelList;
}
@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);
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);
}
}

View File

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

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.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;
@@ -41,7 +43,10 @@ public class GoalEntity {
@Column(name = "goal_complete", nullable = false)
private Integer goalComplete = 0;
@OneToOne(mappedBy = "goalEntity")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
private UserEntity userEntity;
private Integer deleteFlag;
}

View File

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

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,9 @@
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.stereotype.Repository;
import com.example.demo.app.infra.entity.GoalEntity;
@@ -8,4 +11,7 @@ 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);
}

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

@@ -69,7 +69,7 @@ public class GoalController {
}
GoalModel goalModel = GoalModel.convertFrom(goalForm);
goalService.updateGoal(goalModel);
goalService.updateGoal(goalModel, userId);
return "redirect:/goal";
}

View File

@@ -20,12 +20,13 @@ 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.form.CategoryForm;
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.TransactionForm;
import com.example.demo.app.presentation.form.UserForm;
@@ -40,6 +41,7 @@ public class TransactionController {
private final CategoryService categoryService;
private final GoalService goalService;
private final UserService userService;
private final FixedCostService fixedCostService;
// 一覧画面
@SessionCheck
@@ -182,16 +184,23 @@ public class TransactionController {
@SessionCheck
@GetMapping("/transaction/create")
public String createOneGet(@RequestParam(defaultValue = "") LocalDate today,
Long fixedCostId,
Model model) {
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());
}
List<CategoryForm> categoryFormList = CategoryForm.convertFrom(categoryService.findAll());
TransactionForm transactionForm = new TransactionForm();
transactionForm.setTransactionDate(today);
System.out.println(transactionForm.getCategoryName() + " " + transactionForm.getAmount());
@@ -339,19 +348,19 @@ public class TransactionController {
model.addAttribute("totalIncome", totalIncome);
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()));
model.addAttribute("achievementRate", goalForm.getAchievementRate());
model.addAttribute("currentAmount", goalForm.getCurrentAmount());
model.addAttribute("targetAmount", goalForm.getTargetAmount());
// model.addAttribute("achievementRate", goalForm.getAchievementRate());
//
// model.addAttribute("currentAmount", goalForm.getCurrentAmount());
//
// model.addAttribute("targetAmount", goalForm.getTargetAmount());
model.addAttribute("saving", userForm.getSaving());
model.addAttribute("deadline", goalForm.getDeadline());
// model.addAttribute("deadline", goalForm.getDeadline());
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.RequestParam;
import com.example.demo.app.domain.model.LoginModel;
import com.example.demo.app.domain.service.CourseService;
import com.example.demo.app.domain.service.QuestionService;
import com.example.demo.app.domain.service.UserService;
@@ -83,9 +84,11 @@ public class UserController {
Model model,
HttpSession session) {
LoginModel loginUser = (LoginModel) session.getAttribute("loginUser");
Long courseId = courseService.findByName((String) session.getAttribute("selectedCourseName"));
userService.register(userForm, courseId);
userService.register(userForm, courseId, loginUser.getUserId());
return "redirect:/login";
}

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;
import java.time.LocalDate;
import java.util.List;
import org.springframework.format.annotation.DateTimeFormat;
@@ -32,6 +33,8 @@ public class GoalForm {
private Integer currentAmount; // 現在の資産
private Long userId;
public static GoalForm convertFrom(GoalModel goalModel) {
return new GoalForm(
goalModel.getGoalId(),
@@ -41,11 +44,12 @@ public class GoalForm {
goalModel.getDeadline(),
goalModel.getGoalComplete(),
goalModel.getAchievementRate(),
goalModel.getCurrentAmount());
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();
}
}

View File

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

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

@@ -138,6 +138,7 @@
</div>
</div>
<div class="card shadow-sm">
@@ -160,6 +161,9 @@
</div>
<hr>
<div th:replace="~{footer :: footer}"></div>
</body>

View File

@@ -105,6 +105,15 @@
</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>
<div th:replace="~{footer :: footer}"></div>
</body>