Compare commits
18 Commits
s-choi
...
3b239d07bd
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b239d07bd | |||
| 0c54a42b97 | |||
| e0b0109a2b | |||
|
|
76e3fc2345 | ||
| bcafdbe067 | |||
|
|
e9d3e16157 | ||
|
|
70ad3678a5 | ||
|
|
b2b290a998 | ||
|
|
1debde25f2 | ||
|
|
714ffba31f | ||
|
|
430f456866 | ||
|
|
003e03c0c1 | ||
|
|
060102d2b1 | ||
|
|
f5b88de9e6 | ||
|
|
68bfbc195d | ||
|
|
11a8fbf665 | ||
| 3760bf352d | |||
| 76e91f0bf0 |
@@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ package com.example.demo.app.domain.model;
|
|||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
|
|
||||||
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;
|
||||||
@@ -27,8 +28,10 @@ public class GoalModel {
|
|||||||
private Integer achievementRate; // 達成率
|
private Integer achievementRate; // 達成率
|
||||||
|
|
||||||
private Integer currentAmount; // 現在の資産
|
private Integer currentAmount; // 現在の資産
|
||||||
|
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
public static GoalModel convertFrom(GoalEntity goalEntity) {
|
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,10 +39,12 @@ public class GoalModel {
|
|||||||
goalEntity.getTargetAmount(),
|
goalEntity.getTargetAmount(),
|
||||||
goalEntity.getDeadline(),
|
goalEntity.getDeadline(),
|
||||||
goalEntity.getGoalComplete(),
|
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(
|
return new GoalEntity(
|
||||||
goalModel.getGoalId(),
|
goalModel.getGoalId(),
|
||||||
goalModel.getGoalTitle(),
|
goalModel.getGoalTitle(),
|
||||||
@@ -47,7 +52,7 @@ public class GoalModel {
|
|||||||
goalModel.getTargetAmount(),
|
goalModel.getTargetAmount(),
|
||||||
goalModel.getDeadline(),
|
goalModel.getDeadline(),
|
||||||
goalModel.getGoalComplete(),
|
goalModel.getGoalComplete(),
|
||||||
null);
|
userEntity, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GoalModel convertFrom(GoalForm goalForm) {
|
public static GoalModel convertFrom(GoalForm goalForm) {
|
||||||
@@ -58,7 +63,8 @@ public class GoalModel {
|
|||||||
goalForm.getTargetAmount(),
|
goalForm.getTargetAmount(),
|
||||||
goalForm.getDeadline(),
|
goalForm.getDeadline(),
|
||||||
goalForm.getGoalComplete()
|
goalForm.getGoalComplete()
|
||||||
,null,null);
|
,null,null,
|
||||||
|
goalForm.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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()
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.example.demo.app.domain.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.example.demo.app.domain.model.FixedCostModel;
|
||||||
|
|
||||||
|
public interface FixedCostService {
|
||||||
|
|
||||||
|
public List<FixedCostModel> findAllByUserId(Long userId);
|
||||||
|
|
||||||
|
public FixedCostModel save(FixedCostModel fixedCostModel);
|
||||||
|
|
||||||
|
public void delete(Long fixedCostId);
|
||||||
|
|
||||||
|
public FixedCostModel findById(Long fixedCostId);
|
||||||
|
}
|
||||||
@@ -1,16 +1,18 @@
|
|||||||
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);
|
||||||
|
|
||||||
// void deleteGoal(Long goalId);
|
// void deleteGoal(Long goalId);
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package com.example.demo.app.domain.service.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.example.demo.app.domain.model.FixedCostModel;
|
||||||
|
import com.example.demo.app.domain.service.FixedCostService;
|
||||||
|
import com.example.demo.app.infra.repository.CategoryRepository;
|
||||||
|
import com.example.demo.app.infra.repository.FixedCostRepository;
|
||||||
|
import com.example.demo.app.infra.repository.UserRepository;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class FixedCostServiceImpl implements FixedCostService{
|
||||||
|
|
||||||
|
|
||||||
|
private final FixedCostRepository fixedCostRepository;
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
private final CategoryRepository categoryRepository;
|
||||||
|
|
||||||
|
|
||||||
|
public List<FixedCostModel> findAllByUserId(Long userId) {
|
||||||
|
|
||||||
|
return FixedCostModel.convertFrom(fixedCostRepository.findByUserId(userId));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public FixedCostModel save(FixedCostModel fixedCostModel) {
|
||||||
|
|
||||||
|
return FixedCostModel.convertFrom(fixedCostRepository.save( FixedCostModel.convertTo(fixedCostModel, userRepository.findById(fixedCostModel.getUserId()).get(), categoryRepository.findById(fixedCostModel.getCategoryId()).get())));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(Long fixedCostId) {
|
||||||
|
|
||||||
|
fixedCostRepository.deleteById(fixedCostId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public FixedCostModel findById(Long fixedCostId) {
|
||||||
|
return FixedCostModel.convertFrom(fixedCostRepository.findById(fixedCostId).get());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
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 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;
|
||||||
@@ -21,14 +24,14 @@ public class GoalServiceImpl implements GoalService {
|
|||||||
@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 +45,38 @@ 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
|
|
||||||
public GoalModel createGoal(GoalModel goalModel) {
|
|
||||||
|
|
||||||
GoalEntity goalEntity = GoalModel.convertTo(goalModel);
|
@Override
|
||||||
|
public GoalModel createGoal(GoalModel goalModel, Long userId) {
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.example.demo.app.infra.repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
|
|
||||||
|
import com.example.demo.app.infra.entity.FixedCostEntity;
|
||||||
|
|
||||||
|
public interface FixedCostRepository extends JpaRepository<FixedCostEntity, Long> {
|
||||||
|
|
||||||
|
@Query("select f from FixedCostEntity f where f.userEntity.userId = :userId")
|
||||||
|
public List<FixedCostEntity> findByUserId(Long userId);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
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.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 +11,7 @@ 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);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -69,7 +69,7 @@ public class GoalController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GoalModel goalModel = GoalModel.convertFrom(goalForm);
|
GoalModel goalModel = GoalModel.convertFrom(goalForm);
|
||||||
goalService.updateGoal(goalModel);
|
goalService.updateGoal(goalModel, userId);
|
||||||
|
|
||||||
return "redirect:/goal";
|
return "redirect:/goal";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,12 +20,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 +41,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 +184,23 @@ 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,
|
||||||
|
Long fixedCostId,
|
||||||
Model model) {
|
Model model) {
|
||||||
|
|
||||||
if (today == null) {
|
if (today == null) {
|
||||||
today = LocalDate.now();
|
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());
|
List<CategoryForm> categoryFormList = CategoryForm.convertFrom(categoryService.findAll());
|
||||||
|
|
||||||
TransactionForm transactionForm = new TransactionForm();
|
|
||||||
transactionForm.setTransactionDate(today);
|
|
||||||
|
|
||||||
System.out.println(transactionForm.getCategoryName() + " " + transactionForm.getAmount());
|
System.out.println(transactionForm.getCategoryName() + " " + transactionForm.getAmount());
|
||||||
|
|
||||||
@@ -339,19 +348,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";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.example.demo.app.presentation.form;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.example.demo.app.domain.model.FixedCostModel;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class FixedCostForm {
|
||||||
|
|
||||||
|
private Long fixedCostId;
|
||||||
|
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
private Long categoryId;
|
||||||
|
|
||||||
|
private String fixedCostName;
|
||||||
|
|
||||||
|
private Integer amount;
|
||||||
|
|
||||||
|
private String categoryName;
|
||||||
|
|
||||||
|
|
||||||
|
public static FixedCostForm convertFrom(FixedCostModel fixedCostModel) {
|
||||||
|
return new FixedCostForm(
|
||||||
|
fixedCostModel.getFixedCostId(),
|
||||||
|
fixedCostModel.getUserId(),
|
||||||
|
fixedCostModel.getCategoryId(),
|
||||||
|
fixedCostModel.getFixedCostName(),
|
||||||
|
fixedCostModel.getAmount(),
|
||||||
|
"");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static List<FixedCostForm> convertFrom(List<FixedCostModel> fixedCostModelList) {
|
||||||
|
return fixedCostModelList.stream().map(fixedCostModel -> FixedCostForm.convertFrom(fixedCostModel)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FixedCostModel convertTo(FixedCostForm fixedCostForm) {
|
||||||
|
return new FixedCostModel(
|
||||||
|
fixedCostForm.getFixedCostId(),
|
||||||
|
fixedCostForm.getUserId(),
|
||||||
|
fixedCostForm.getCategoryId(),
|
||||||
|
fixedCostForm.getFixedCostName(),
|
||||||
|
fixedCostForm.getAmount());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,6 +1,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;
|
||||||
|
|
||||||
@@ -31,6 +32,8 @@ public class GoalForm {
|
|||||||
private Integer achievementRate; // 達成率
|
private Integer achievementRate; // 達成率
|
||||||
|
|
||||||
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(
|
||||||
@@ -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();
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
66
src/main/resources/templates/fixed_cost.html
Normal file
66
src/main/resources/templates/fixed_cost.html
Normal 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>
|
||||||
129
src/main/resources/templates/fixed_cost_create.html
Normal file
129
src/main/resources/templates/fixed_cost_create.html
Normal 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>
|
||||||
@@ -138,8 +138,9 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card shadow-sm">
|
<div class="card shadow-sm">
|
||||||
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@@ -160,6 +161,9 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
|
||||||
<div th:replace="~{footer :: footer}"></div>
|
<div th:replace="~{footer :: footer}"></div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@@ -105,6 +105,15 @@
|
|||||||
|
|
||||||
</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>
|
||||||
|
|
||||||
<div th:replace="~{footer :: footer}"></div>
|
<div th:replace="~{footer :: footer}"></div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user