4 Commits

2 changed files with 31 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
package com.example.demo.app.infra.entity;
import java.util.List;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
@@ -9,12 +11,14 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import com.example.demo.app.domain.model.AllocationModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@Table(name = "allocation")
@Table(name = "allocation_m")
@Data
@NoArgsConstructor
@AllArgsConstructor
@@ -32,5 +36,16 @@ public class AllocationEntity {
@Column(name = "allocation_ratio", nullable = false)
private Integer allocationRatio;
public static List<AllocationModel> createAllocationModelList(List<AllocationEntity> allocationEntityList) {
return allocationEntityList
.stream()
.map(allocationEntity -> new AllocationModel(
allocationEntity.getCategoryEntity().getCategoryId(),
allocationEntity.getCourseEntity().getCourseId(),
allocationEntity.getAllocationRatio()
)).toList();
}
}

View File

@@ -12,12 +12,14 @@ import jakarta.persistence.Table;
import org.springframework.data.annotation.Id;
import com.example.demo.app.domain.model.CourseModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Entity
@Table(name = "course")
@Table(name = "course_m")
@Data
@NoArgsConstructor
@AllArgsConstructor
@@ -41,4 +43,16 @@ public class CourseEntity {
@OneToOne(mappedBy = "courseEntity")
private List<AllocationEntity> allocationEntity;
public static List<CourseModel> createCourseModelList(List<CourseEntity> courseEntityList) {
return courseEntityList
.stream()
.map(courseEntity -> new CourseModel(
courseEntity.getCourseId(),
courseEntity.getCourseName(),
courseEntity.getDescription()
)).toList();
}
}