[EDIT] 目標テーブルを修正しました。

This commit is contained in:
s-choi
2026-09-24 13:19:23 +09:00
parent 1debde25f2
commit b2b290a998
3 changed files with 26 additions and 11 deletions

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;
@@ -27,8 +28,10 @@ public class GoalModel {
private Integer achievementRate; // 達成率
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(
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

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

@@ -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;
@@ -31,6 +32,8 @@ public class GoalForm {
private Integer achievementRate; // 達成率
private Integer currentAmount; // 現在の資産
private Long userId;
public static GoalForm convertFrom(GoalModel goalModel) {
return new GoalForm(
@@ -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();
}
}