Skip to content

Commit

Permalink
Refactor : 학력 연관관계 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Suhun0331 committed Dec 4, 2024
1 parent f5df15c commit 2d11476
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/main/java/umc/kkijuk/server/record/domain/Education.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public class Education extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@JoinColumn(name = "record_id", nullable = false)
private Record record;
@Column(nullable = false)
private Long memberId;

private String category;
private String schoolName;
Expand Down
5 changes: 1 addition & 4 deletions src/main/java/umc/kkijuk/server/record/domain/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ public class Record extends BaseEntity {
private String address;
private String profileImageUrl;

@OneToMany(mappedBy = "record", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Education> educations = new ArrayList<>();

@Builder
public Record(Long memberId, String address, String profileImageUrl, List<Education> educations) {
public Record(Long memberId, String address, String profileImageUrl) {
this.memberId = memberId;
this.address = address;
this.profileImageUrl = profileImageUrl;
this.educations = educations;
}

public void update(String address, String profileImageUrl) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import org.springframework.data.jpa.repository.JpaRepository;
import umc.kkijuk.server.record.domain.Award;
import umc.kkijuk.server.record.domain.Education;
import umc.kkijuk.server.record.domain.File;

import java.util.List;

public interface EducationRepository extends JpaRepository<Education, Long> {
List<Education> findByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public RecordResponse getRecord(Long memberId) {

if (record != null) {
// 학력
List<EducationResponse> educationList = record.getEducations()
List<EducationResponse> educationList = educationRepository.findByMemberId(memberId)
.stream()
.map(EducationResponse::new)
.collect(Collectors.toList());
Expand Down Expand Up @@ -204,7 +204,7 @@ public RecordResponse updateRecord(Long memberId, Long recordId, RecordReqDto re
recordReqDto.getAddress(),
recordReqDto.getProfileImageUrl());

List<EducationResponse> educationList = record.getEducations()
List<EducationResponse> educationList = educationRepository.findByMemberId(memberId)
.stream()
.map(EducationResponse::new)
.collect(Collectors.toList());
Expand Down Expand Up @@ -253,7 +253,7 @@ public RecordDownResponse downloadResume(Long recordId, Long memberId) {



List<EducationResponse> educationList = record.getEducations()
List<EducationResponse> educationList = educationRepository.findByMemberId(memberId)
.stream()
.map(EducationResponse::new)
.collect(Collectors.toList());
Expand Down Expand Up @@ -295,7 +295,7 @@ public EducationResponse saveEducation(Member requestMember, Long recordId, Educ
}

Education education = Education.builder()
.record(record)
.memberId(requestMember.getId())
.category(educationReqDto.getCategory())
.schoolName(educationReqDto.getSchoolName())
.major(educationReqDto.getMajor())
Expand All @@ -314,7 +314,7 @@ public EducationResponse saveEducation(Member requestMember, Long recordId, Educ
public EducationResponse updateEducation(Member requestMember, Long educationId, EducationReqDto educationReqDto) {
Education education = educationRepository.findById(educationId)
.orElseThrow(() -> new ResourceNotFoundException("education ", educationId));
if (!education.getRecord().getMemberId().equals(requestMember.getId())) {
if (!education.getMemberId().equals(requestMember.getId())) {
throw new IntroOwnerMismatchException();
}
education.changeEducationInfo(
Expand All @@ -332,7 +332,7 @@ public EducationResponse updateEducation(Member requestMember, Long educationId,
public Long deleteEducation(Member requestMember, Long educationId) {
Education education = educationRepository.findById(educationId)
.orElseThrow(() -> new ResourceNotFoundException("education ", educationId));
if (!education.getRecord().getMemberId().equals(requestMember.getId())) {
if (!education.getMemberId().equals(requestMember.getId())) {
throw new IntroOwnerMismatchException();
}

Expand Down

0 comments on commit 2d11476

Please sign in to comment.