feat: cascade 설정

This commit is contained in:
박정민 2024-08-09 16:35:18 +09:00
parent 5bc56fc2a7
commit 4d479d702e
4 changed files with 14 additions and 8 deletions

View File

@ -64,10 +64,10 @@ public class Board {
@OnDelete(action = OnDeleteAction.CASCADE) @OnDelete(action = OnDeleteAction.CASCADE)
private Lecture lecture; private Lecture lecture;
@OneToMany(mappedBy = "board", cascade = CascadeType.ALL) @OneToMany(mappedBy = "board")
private List<Comment> comments; private List<Comment> comments;
public ResponseBoardSummaryDto makeSummaryDto(){ public ResponseBoardSummaryDto makeSummaryDto() {
return ResponseBoardSummaryDto.builder() return ResponseBoardSummaryDto.builder()
.id(id) .id(id)
.title(title) .title(title)
@ -76,7 +76,7 @@ public class Board {
.build(); .build();
} }
public ResponseBoardDetailDto makeDetailDto(long userId){ public ResponseBoardDetailDto makeDetailDto(long userId) {
return ResponseBoardDetailDto.builder() return ResponseBoardDetailDto.builder()
.id(id) .id(id)
.name(user.getName()) .name(user.getName())

View File

@ -10,6 +10,8 @@ import lombok.Builder;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp; import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import org.hibernate.annotations.UpdateTimestamp; import org.hibernate.annotations.UpdateTimestamp;
import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.annotation.LastModifiedDate;
@ -46,6 +48,7 @@ public class Comment {
@ManyToOne @ManyToOne
@JoinColumn(name = "board_id") @JoinColumn(name = "board_id")
@OnDelete(action = OnDeleteAction.CASCADE)
Board board; Board board;
public ResponseCommentDto makeCommentDto(long userId) { public ResponseCommentDto makeCommentDto(long userId) {

View File

@ -7,6 +7,8 @@ import com.edufocus.edufocus.report.entity.vo.ReportSet;
import com.edufocus.edufocus.user.model.entity.vo.User; import com.edufocus.edufocus.user.model.entity.vo.User;
import jakarta.persistence.*; import jakarta.persistence.*;
import lombok.*; import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import java.util.UUID; import java.util.UUID;
@ -22,22 +24,23 @@ public class Registration {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private long id; private long id;
@ManyToOne(cascade = CascadeType.ALL) @ManyToOne
@JoinColumn(name = "user_id") @JoinColumn(name = "user_id")
private User user; private User user;
@ManyToOne(cascade = CascadeType.ALL) @ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "lecture_id") @JoinColumn(name = "lecture_id")
private Lecture lecture; private Lecture lecture;
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private RegistrationStatus status; private RegistrationStatus status;
public boolean isAccepted(){ public boolean isAccepted() {
return status == RegistrationStatus.ACCEPTED; return status == RegistrationStatus.ACCEPTED;
} }
public Report makeReport(ReportSet reportSet, QuizSet quizSet, long lectureId){ public Report makeReport(ReportSet reportSet, QuizSet quizSet, long lectureId) {
return Report.builder() return Report.builder()
.allCount(0) .allCount(0)
.correctCount(-1) .correctCount(-1)

View File

@ -21,7 +21,7 @@ spring.datasource.username=${USER_NAME}
spring.datasource.password=${USER_PASSWORD} spring.datasource.password=${USER_PASSWORD}
spring.mvc.pathmatch.matching-strategy=ant_path_matcher spring.mvc.pathmatch.matching-strategy=ant_path_matcher
spring.jpa.database=mysql spring.jpa.database=mysql
spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.ddl-auto=create
spring.jpa.show-sql=true spring.jpa.show-sql=true
spring.jpa.properties.hibernate.jdbc.time_zone=Asia/Seoul spring.jpa.properties.hibernate.jdbc.time_zone=Asia/Seoul
management.endpoints.web.exposure.include=health,info management.endpoints.web.exposure.include=health,info