Skip to content

Commit

Permalink
Merge pull request #30 from NOzigak/feature/recruitt
Browse files Browse the repository at this point in the history
recruit/delete 수정완료
  • Loading branch information
1224kang authored Jul 9, 2024
2 parents 2c8a83b + 2eb3ccc commit a15e855
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/main/java/hamsung/hamsung_project/entity/Comment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -30,8 +32,9 @@ public class Comment {
@OneToMany(mappedBy = "comment", cascade = CascadeType.REMOVE, orphanRemoval = true)
private List<ChildComment> childs = new ArrayList<>();

@ManyToOne
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name ="recruit_id")
@OnDelete(action= OnDeleteAction.CASCADE)
private Recruit recruit; //스터디 모집글

public static Comment createComment(Long id, String text, String createdDate, String modifiedDate) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hamsung/hamsung_project/entity/Recruit.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class Recruit {


@JoinColumn(name="study_id")
@JsonBackReference
// @JsonBackReference
@OneToOne(cascade = CascadeType.ALL)
private Study study;

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/hamsung/hamsung_project/entity/StudyMember.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package hamsung.hamsung_project.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.ColumnDefault;
Expand Down Expand Up @@ -30,6 +31,7 @@ public class StudyMember {
private User users;

@ManyToOne
@JsonBackReference
@JoinColumn(name="study_id")
private Study study;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import hamsung.hamsung_project.dto.*;
import hamsung.hamsung_project.entity.*;
import hamsung.hamsung_project.exception.InvalidDataException;
import hamsung.hamsung_project.repository.*;
import hamsung.hamsung_project.repository.RecruitsRepository;
import hamsung.hamsung_project.repository.StudyMemberRepository;
Expand All @@ -28,6 +29,7 @@ public class RecruitsService {
private final UserRepository userRepository;
private final StudyMemberService studyMemberService;
private final CommentRepository commentRepository;
private final ChildCommentRepository childCommentRepository;

//게시글 생성 //스터디 생성
@Transactional
Expand Down Expand Up @@ -108,13 +110,15 @@ public boolean deleteRecruit(Long id){
Recruit target=recruitsRepository.findById(id).orElseThrow(()->new IllegalArgumentException("해당 게시글을 찾을 수 없습니다."));
if (recruitsRepository.existsById(id)) {
//FK 연관관계 때문에 게시글에 딸린 comments 먼저 삭제.
List<Comment> comment=commentRepository.findAllByRecruitId(id);
commentRepository.deleteAll(comment);
// List<Comment> comment=commentRepository.findAllByRecruitId(id);
// commentRepository.deleteAll(comment);

recruitsRepository.deleteById(id);
return true;
} else {
return false;
}

}

//스터디 모집 상태 변경(버튼 클릭?)
Expand Down

0 comments on commit a15e855

Please sign in to comment.