[EDIT] 目標テーブルを修正しました。
This commit is contained in:
@@ -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;
|
||||||
@@ -28,7 +29,9 @@ public class GoalModel {
|
|||||||
|
|
||||||
private Integer currentAmount; // 現在の資産
|
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(
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
// }
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user