Compare commits
11 Commits
ce0a158988
...
662e3433d2
| Author | SHA1 | Date | |
|---|---|---|---|
| 662e3433d2 | |||
| 60d4ebd74f | |||
|
|
1b6193082d | ||
|
|
86e41765f5 | ||
|
|
804e4a6fdd | ||
| 49af15f939 | |||
|
|
2e64d623b5 | ||
|
|
170e319dca | ||
|
|
6b91c91c19 | ||
|
|
1c5cb6bf7a | ||
|
|
e2286762d6 |
@@ -0,0 +1,20 @@
|
||||
package com.example.demo.app.domain.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class CourseInfoModel {
|
||||
|
||||
private Long courseId;
|
||||
|
||||
private String courseName;
|
||||
|
||||
private Long categoryId;
|
||||
|
||||
private String categoryName;
|
||||
|
||||
private Integer allocationRatio;
|
||||
|
||||
}
|
||||
@@ -2,6 +2,9 @@ package com.example.demo.app.domain.model;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
import com.example.demo.app.infra.entity.GoalEntity;
|
||||
import com.example.demo.app.presentation.form.GoalForm;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -21,4 +24,35 @@ public class GoalModel {
|
||||
|
||||
private Integer goalComplete;
|
||||
|
||||
public static GoalModel convertFrom(GoalEntity goalEntity) {
|
||||
return new GoalModel(
|
||||
goalEntity.getGoalId(),
|
||||
goalEntity.getGoalTitle(),
|
||||
goalEntity.getGoalSubtitle(),
|
||||
goalEntity.getTargetAmount(),
|
||||
goalEntity.getDeadline(),
|
||||
goalEntity.getGoalComplete());
|
||||
}
|
||||
|
||||
public static GoalEntity convertTo(GoalModel goalModel) {
|
||||
return new GoalEntity(
|
||||
goalModel.getGoalId(),
|
||||
goalModel.getGoalTitle(),
|
||||
goalModel.getGoalSubtitle(),
|
||||
goalModel.getTargetAmount(),
|
||||
goalModel.getDeadline(),
|
||||
goalModel.getGoalComplete(),
|
||||
null);
|
||||
}
|
||||
|
||||
public static GoalModel convertFrom(GoalForm goalForm) {
|
||||
return new GoalModel(
|
||||
goalForm.getGoalId(),
|
||||
goalForm.getGoalTitle(),
|
||||
goalForm.getGoalSubtitle(),
|
||||
goalForm.getTargetAmount(),
|
||||
goalForm.getDeadline(),
|
||||
goalForm.getGoalComplete());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.IdClass;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.OneToOne;
|
||||
@@ -18,6 +19,7 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Entity
|
||||
@IdClass(AllocationId.class)
|
||||
@Table(name = "allocation_m")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.example.demo.app.infra.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AllocationId implements Serializable {
|
||||
private Long categoryEntity;
|
||||
|
||||
private Long courseEntity;
|
||||
}
|
||||
@@ -24,7 +24,7 @@ public class GoalEntity {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "goal_id")
|
||||
private Integer goalId;
|
||||
private Long goalId;
|
||||
|
||||
@Column(name = "goal_title", nullable = true)
|
||||
private String goalTitle;
|
||||
|
||||
@@ -7,24 +7,26 @@ import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
import com.example.demo.app.domain.model.CourseInfoModel;
|
||||
import com.example.demo.app.infra.entity.AllocationEntity;
|
||||
import com.example.demo.app.infra.entity.AllocationId;
|
||||
|
||||
public interface AllocationRepository extends JpaRepository<AllocationEntity, Long>{
|
||||
public interface AllocationRepository extends JpaRepository<AllocationEntity, AllocationId>{
|
||||
|
||||
List<AllocationEntity> findByCourseId(Long courseId);
|
||||
List<AllocationEntity> findByCourseEntity_CourseId(Long courseId);
|
||||
|
||||
@Query(" SELECT co.course_id, "
|
||||
+ " co.course_name, "
|
||||
+ " ca.category_id, "
|
||||
+ " ca.categpry_name, "
|
||||
+ " a.allocation_ratio "
|
||||
+ " FROM allocation_m a "
|
||||
+ " INNER JOIN course_m co "
|
||||
+ " ON a.course_id = co.course_id "
|
||||
+ " INNER JOIN category_t ca "
|
||||
+ " on a.category_id = ca.category_id "
|
||||
+ " WHERE ca.transaction_type = 0 "
|
||||
+ " ORDER BY a.course_id ASC, "
|
||||
+ " a.category_id ASC ")
|
||||
@Query(" SELECT new com.example.demo.app.domain.model.CourseInfoModel("
|
||||
+ "co.courseId, "
|
||||
+ " co.courseName, "
|
||||
+ " ca.categoryId, "
|
||||
+ " ca.categoryName, "
|
||||
+ " a.allocationRatio )"
|
||||
+ " FROM AllocationEntity a"
|
||||
+ " INNER JOIN CourseEntity co "
|
||||
+ " ON a.courseEntity.courseId = co.courseId "
|
||||
+ " INNER JOIN CategoryEntity ca "
|
||||
+ " on a.categoryEntity.categoryId = ca.categoryId "
|
||||
+ " WHERE ca.transactionType = 0 "
|
||||
+ " ORDER BY a.courseEntity.courseId ASC, "
|
||||
+ " a.categoryEntity.categoryId ASC ")
|
||||
List<CourseInfoModel> findAllJoinedAllocation();
|
||||
|
||||
}
|
||||
|
||||
@@ -13,13 +13,13 @@ public interface TransactionRepository extends JpaRepository<TransactionEntity,
|
||||
@Query("select t from TransactionEntity t where t.userEntity.userId = :userId and t.transactionDate = :transactionDate")
|
||||
public List<TransactionEntity> findByUserIdAndDate(LocalDate todayDate, Long userId);
|
||||
|
||||
@Query("select t from TransactionEntity t where (t.transactionDate between :startDate and :endDate) and (t.userId = :userId) order by t.transactionDate asc")
|
||||
@Query("select t from TransactionEntity t where (t.transactionDate between :startDate and :endDate) and (t.userEntity.userId = :userId) order by t.transactionDate asc")
|
||||
public List<TransactionEntity> findAllByDateAndUserId(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
|
||||
@Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryId = c.categoryId where (t.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 0")
|
||||
@Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryEntity.categoryId = c.categoryId where (t.userEntity.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 0")
|
||||
public Integer findTotalExpense(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
|
||||
@Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryId = c.categoryId where (t.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 1")
|
||||
@Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryEntity.categoryId = c.categoryId where (t.userEntity.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 1")
|
||||
public Integer findTotalIncome(LocalDate startDate, LocalDate endDate, Long userId);
|
||||
|
||||
@Query("select sum(t.amount) from TransactionEntity t where t.userEntity.userId = :userId and t.categoryEntity.categoryId = :categoryId and t.transactionDate between :startDate and :endDate")
|
||||
|
||||
@@ -66,7 +66,7 @@ public class TransactionController {
|
||||
}
|
||||
|
||||
// 詳細画面
|
||||
@GetMapping()
|
||||
@GetMapping("/transaction/detail")
|
||||
public String findOne(@RequestParam(required = false) LocalDate todayDates, Model model, HttpSession session) {
|
||||
|
||||
LocalDate todayDate = (todayDates == null) ? LocalDate.now() : todayDates;
|
||||
@@ -93,13 +93,13 @@ public class TransactionController {
|
||||
return "";
|
||||
}
|
||||
|
||||
@GetMapping("")
|
||||
@GetMapping("/transaction/create")
|
||||
public String createOneGet(@ModelAttribute TransactionForm transactionForm) {
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@PostMapping()
|
||||
@PostMapping("/transaction/create")
|
||||
public String createOnePost(@ModelAttribute TransactionForm transactionForm, Model model) {
|
||||
|
||||
if (transactionService.createTransaction(TransactionForm.convertTo(transactionForm)) != 0) {
|
||||
@@ -110,13 +110,13 @@ public class TransactionController {
|
||||
|
||||
}
|
||||
|
||||
@GetMapping("")
|
||||
@GetMapping("/transaction/update")
|
||||
public String updateOneGet(@ModelAttribute TransactionForm transactionForm) {
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
@PostMapping()
|
||||
@PostMapping("/transaction/update")
|
||||
public String updateOnePost(@ModelAttribute TransactionForm transactionForm, Model model) {
|
||||
|
||||
if (transactionService.updateTransaction(TransactionForm.convertTo(transactionForm)) != 0) {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.CourseModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CourseForm {
|
||||
|
||||
private Long courseId;
|
||||
private String courseName;
|
||||
private String description;
|
||||
|
||||
|
||||
public static CourseForm convertFrom(CourseModel courseModel) {
|
||||
return new CourseForm(
|
||||
courseModel.getCourseId(),
|
||||
courseModel.getCourseName(),
|
||||
courseModel.getDescription()
|
||||
);
|
||||
}
|
||||
|
||||
public static List<CourseForm> convertFrom(List<CourseModel> courseModelList){
|
||||
return courseModelList.stream().map(CourseForm::convertFrom).toList();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.example.demo.app.presentation.form;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.app.domain.model.CourseInfoModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CourseInfoForm {
|
||||
|
||||
private Long courseId;
|
||||
|
||||
private String courseName;
|
||||
|
||||
private Long categoryId;
|
||||
|
||||
private String categoryName;
|
||||
|
||||
private Integer allocationRatio;
|
||||
|
||||
|
||||
public static CourseInfoForm convertFrom(CourseInfoModel courseInfoModel ) {
|
||||
return new CourseInfoForm(courseInfoModel.getCategoryId(), courseInfoModel.getCourseName(), courseInfoModel.getCategoryId(), courseInfoModel.getCategoryName(), courseInfoModel.getAllocationRatio());
|
||||
}
|
||||
|
||||
public static List<CourseInfoForm> convertFrom(List<CourseInfoModel> courseInfoModelList ) {
|
||||
return courseInfoModelList.stream().map(CourseInfoForm::convertFrom).toList();
|
||||
}
|
||||
|
||||
public static CourseInfoModel convertTo(CourseInfoForm courseInfoForm) {
|
||||
return new CourseInfoModel(
|
||||
courseInfoForm.getCourseId(),
|
||||
courseInfoForm.getCourseName(),
|
||||
courseInfoForm.getCategoryId(),
|
||||
courseInfoForm.getCategoryName(),
|
||||
courseInfoForm.getAllocationRatio());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user