스프링 설계


@Entity
@Getter
**@NoArgsConstructor(access = AccessLevel.PROTECTED)**
public class Sprint extends BaseTimeEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "sprint_id")
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "project_id")
    private Project project;

    private String title;

    private String goal;

    private LocalDate startDt;

    private LocalDate dueDt;

    @OneToMany(mappedBy = "sprint", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<Feedback> feedbacks = new ArrayList<>();

    @OneToMany(mappedBy = "sprint", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<Task> tasks = new ArrayList<>();

    @OneToMany(mappedBy = "sprint", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<Meeting> meetings = new ArrayList<>();

    @OneToMany(mappedBy = "sprint", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<Contribution> contribution = new ArrayList<>();

    private Double progress;

    **@Builder(access = AccessLevel.PRIVATE)**
    private Sprint(
            Project project,
            String title,
            String goal,
            LocalDate startDt,
            LocalDate dueDt,
            Double progress) {
        this.project = project;
        this.title = title;
        this.goal = goal;
        this.startDt = startDt;
        this.dueDt = dueDt;
        this.progress = progress;
    }

    public static Sprint **createSprint**(Project project, String title, String goal, LocalDate dueDt) {
        validateDueDt(LocalDate.now(), dueDt);
        return Sprint.builder()
                .project(project)
                .title(title)
                .goal(goal)
                .progress(0.0)
                .startDt(LocalDate.now())
                .dueDt(dueDt)
                .build();
    }

    public void updateSprint(String goal, LocalDate dueDt) {
        if (goal != null) this.goal = goal;
        if (dueDt != null) {
            validateDueDt(this.startDt, dueDt);
            this.dueDt = dueDt;
        }
    }

    public void updateSprintTitle(String title) {
        this.title = title;
    }

    public void updateProgress(Double progress) {
        this.progress = progress;
    }
}

Spring Guide - Directory - Yun Blog | 기술 블로그