From 4d479d702e914ffdaf376d466669424a45aaf6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=A0=95=EB=AF=BC?= Date: Fri, 9 Aug 2024 16:35:18 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20cascade=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/edufocus/edufocus/board/entity/vo/Board.java | 6 +++--- .../edufocus/edufocus/board/entity/vo/Comment.java | 3 +++ .../edufocus/registration/entity/Registration.java | 11 +++++++---- backend/src/main/resources/application.properties | 2 +- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java index 2cca933..17274f4 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Board.java @@ -64,10 +64,10 @@ public class Board { @OnDelete(action = OnDeleteAction.CASCADE) private Lecture lecture; - @OneToMany(mappedBy = "board", cascade = CascadeType.ALL) + @OneToMany(mappedBy = "board") private List comments; - public ResponseBoardSummaryDto makeSummaryDto(){ + public ResponseBoardSummaryDto makeSummaryDto() { return ResponseBoardSummaryDto.builder() .id(id) .title(title) @@ -76,7 +76,7 @@ public class Board { .build(); } - public ResponseBoardDetailDto makeDetailDto(long userId){ + public ResponseBoardDetailDto makeDetailDto(long userId) { return ResponseBoardDetailDto.builder() .id(id) .name(user.getName()) diff --git a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java index 80bb200..3a44c96 100644 --- a/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java +++ b/backend/src/main/java/com/edufocus/edufocus/board/entity/vo/Comment.java @@ -10,6 +10,8 @@ import lombok.Builder; import lombok.NoArgsConstructor; import lombok.Setter; import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import org.hibernate.annotations.UpdateTimestamp; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; @@ -46,6 +48,7 @@ public class Comment { @ManyToOne @JoinColumn(name = "board_id") + @OnDelete(action = OnDeleteAction.CASCADE) Board board; public ResponseCommentDto makeCommentDto(long userId) { diff --git a/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java b/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java index 1d2870d..ee0d3e7 100644 --- a/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java +++ b/backend/src/main/java/com/edufocus/edufocus/registration/entity/Registration.java @@ -7,6 +7,8 @@ import com.edufocus.edufocus.report.entity.vo.ReportSet; import com.edufocus.edufocus.user.model.entity.vo.User; import jakarta.persistence.*; import lombok.*; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import java.util.UUID; @@ -22,22 +24,23 @@ public class Registration { @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; - @ManyToOne(cascade = CascadeType.ALL) + @ManyToOne @JoinColumn(name = "user_id") private User user; - @ManyToOne(cascade = CascadeType.ALL) + @ManyToOne + @OnDelete(action = OnDeleteAction.CASCADE) @JoinColumn(name = "lecture_id") private Lecture lecture; @Enumerated(EnumType.STRING) private RegistrationStatus status; - public boolean isAccepted(){ + public boolean isAccepted() { 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() .allCount(0) .correctCount(-1) diff --git a/backend/src/main/resources/application.properties b/backend/src/main/resources/application.properties index 943e868..dd85ef5 100644 --- a/backend/src/main/resources/application.properties +++ b/backend/src/main/resources/application.properties @@ -21,7 +21,7 @@ spring.datasource.username=${USER_NAME} spring.datasource.password=${USER_PASSWORD} spring.mvc.pathmatch.matching-strategy=ant_path_matcher spring.jpa.database=mysql -spring.jpa.hibernate.ddl-auto=update +spring.jpa.hibernate.ddl-auto=create spring.jpa.show-sql=true spring.jpa.properties.hibernate.jdbc.time_zone=Asia/Seoul management.endpoints.web.exposure.include=health,info