Skip to content

Commit

Permalink
Refactor : 학력 제외 record 연관관계 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Suhun0331 committed Dec 4, 2024
1 parent ce56eba commit f5df15c
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 72 deletions.
9 changes: 3 additions & 6 deletions src/main/java/umc/kkijuk/server/record/domain/Award.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class Award extends BaseEntity {
@Column(name = "award_id")
private Long id;

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

@Size(max = 30)
private String competitionName;
@Size(max = 15)
Expand All @@ -40,7 +40,4 @@ public void changeAwardInfo(String competitionName, String administer, String aw
this.acquireDate = acquireDate;
}

public Long getMemberId() {
return this.record.getMemberId();
}
}
7 changes: 0 additions & 7 deletions src/main/java/umc/kkijuk/server/record/domain/File.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ public class File extends BaseEntity {
@Column(nullable = false)
private Long memberId;

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

private FileType fileType;

@Column(length = 20)
Expand All @@ -32,7 +28,4 @@ public class File extends BaseEntity {

private String url;

public Long getMemberId() {
return this.record.getMemberId();
}
}
8 changes: 2 additions & 6 deletions src/main/java/umc/kkijuk/server/record/domain/License.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ public class License 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;

@NotNull
private LicenseTag licenseTag;
Expand All @@ -51,8 +50,5 @@ public void changeLicenseInfo(LicenseTag licenseTag, String licenseName, String
this.acquireDate = acquireDate;
}

public Long getMemberId() {
return this.record.getMemberId();
}

}
12 changes: 0 additions & 12 deletions src/main/java/umc/kkijuk/server/record/domain/Record.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ public class Record extends BaseEntity {
@OneToMany(mappedBy = "record", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Education> educations = new ArrayList<>();

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

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

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

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

@Builder
public Record(Long memberId, String address, String profileImageUrl, List<Education> educations) {
this.memberId = memberId;
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/umc/kkijuk/server/record/domain/Skill.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ public class Skill 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;

@NotNull
private SkillTag skillTag;
Expand All @@ -38,7 +37,4 @@ public void changeSkillInfo(SkillTag skillTag, String skillName, Workmanship wor
this.workmanship = workmanship;
}

public Long getMemberId() {
return this.record.getMemberId();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@


public interface AwardRepository extends JpaRepository<Award, Long> {
List<Award> findByRecordId(Long recordId);
List<Award> findByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package umc.kkijuk.server.record.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import umc.kkijuk.server.record.domain.Award;
import umc.kkijuk.server.record.domain.Education;

import java.util.List;

public interface EducationRepository extends JpaRepository<Education, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public interface FileRepository extends JpaRepository<File,Long> {
boolean existsByMemberIdAndFileTitle(Long memberId, String fileTitle);
boolean existsByMemberIdAndUrlTitle(Long memberId, String urlTitle);
Optional<File> findByMemberIdAndUrlTitle(Long memberId, String urlTitle);
List<File> findByRecordId(Long recordId);
List<File> findByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
import java.util.List;

public interface LicenseRepository extends JpaRepository<License, Long> {
List<License> findByRecordId(Long recordId);

List<License> findByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
public interface RecordRepository extends JpaRepository<Record, Long> {
Record findByMemberId(Long memberId);
boolean existsByMemberId(Long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
import java.util.List;

public interface SkillRepository extends JpaRepository<Skill, Long> {
List<Skill> findByRecordId(Long recordId);
List<Skill> findByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ public FileResponse saveFile(Long memberId, Long recordId, FileReqDto request) {
throw new IllegalArgumentException("이미 존재하는 파일 이름입니다: " + request.getTitle());
}

Record record = recordRepository.findById(recordId)
.orElseThrow(() -> new ResourceNotFoundException("Record", recordId));
// Record record = recordRepository.findById(recordId)
// .orElseThrow(() -> new ResourceNotFoundException("Record", recordId));
File file = File.builder()
.memberId(memberId)
.record(record)
.fileType(FileType.File)
.fileTitle(request.getTitle())
.keyName(request.getKeyName())
Expand Down Expand Up @@ -133,12 +132,11 @@ public FileResponse saveUrl(Long memberId, Long recordId, UrlReqDto urlReqDto){
if (fileRepository.existsByMemberIdAndUrlTitle(memberId, urlReqDto.getUrlTitle())) {
throw new IllegalArgumentException("이미 존재하는 URL 제목입니다: " + urlReqDto.getUrlTitle());
}
Record record = recordRepository.findById(recordId)
.orElseThrow(() -> new ResourceNotFoundException("Record", recordId));
// Record record = recordRepository.findById(recordId)
// .orElseThrow(() -> new ResourceNotFoundException("Record", recordId));

File file = File.builder()
.memberId(memberId)
.record(record)
.fileType(FileType.URL)
.urlTitle(urlReqDto.getUrlTitle())
.url(urlReqDto.getUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,24 @@ public RecordResponse getRecord(Long memberId) {
.toList();

// 수상
List<AwardResponse> awards = awardRepository.findByRecordId(record.getId()).stream()
List<AwardResponse> awards = awardRepository.findByMemberId(memberId).stream()
.map(AwardResponse::new)
.sorted(Comparator.comparing(AwardResponse::getAcquireDate).reversed())
.toList();

// 자격증
List<LicenseResponse> licenses = licenseRepository.findByRecordId(record.getId()).stream()
List<LicenseResponse> licenses = licenseRepository.findByMemberId(memberId).stream()
.map(LicenseResponse::new)
.sorted(Comparator.comparing(LicenseResponse::getAcquireDate).reversed())
.toList();

// 스킬
List<SkillResponse> skills = skillRepository.findByRecordId(record.getId()).stream()
List<SkillResponse> skills = skillRepository.findByMemberId(memberId).stream()
.map(SkillResponse::new)
.collect(Collectors.toList());

// 파일
List<FileResponse> files = fileRepository.findByRecordId(record.getId()).stream()
List<FileResponse> files = fileRepository.findByMemberId(memberId).stream()
.map(FileResponse::new)
.collect(Collectors.toList());

Expand Down Expand Up @@ -179,24 +179,24 @@ public RecordResponse updateRecord(Long memberId, Long recordId, RecordReqDto re
.toList();

// 수상
List<AwardResponse> awards = awardRepository.findByRecordId(record.getId()).stream()
List<AwardResponse> awards = awardRepository.findByMemberId(memberId).stream()
.map(AwardResponse::new)
.sorted(Comparator.comparing(AwardResponse::getAcquireDate).reversed())
.toList();

// 자격증
List<LicenseResponse> licenses = licenseRepository.findByRecordId(record.getId()).stream()
List<LicenseResponse> licenses = licenseRepository.findByMemberId(memberId).stream()
.map(LicenseResponse::new)
.sorted(Comparator.comparing(LicenseResponse::getAcquireDate).reversed())
.toList();

// 스킬
List<SkillResponse> skills = skillRepository.findByRecordId(record.getId()).stream()
List<SkillResponse> skills = skillRepository.findByMemberId(memberId).stream()
.map(SkillResponse::new)
.collect(Collectors.toList());

// 파일
List<FileResponse> files = fileRepository.findByRecordId(record.getId()).stream()
List<FileResponse> files = fileRepository.findByMemberId(memberId).stream()
.map(FileResponse::new)
.collect(Collectors.toList());

Expand Down Expand Up @@ -259,36 +259,32 @@ public RecordDownResponse downloadResume(Long recordId, Long memberId) {
.collect(Collectors.toList());

// 수상
List<AwardResponse> awards = awardRepository.findByRecordId(record.getId()).stream()
List<AwardResponse> awards = awardRepository.findByMemberId(memberId).stream()
.map(AwardResponse::new)
.sorted(Comparator.comparing(AwardResponse::getAcquireDate).reversed())
.toList();

// 자격증
List<LicenseResponse> licenses = licenseRepository.findByRecordId(record.getId()).stream()
List<LicenseResponse> licenses = licenseRepository.findByMemberId(memberId).stream()
.map(LicenseResponse::new)
.sorted(Comparator.comparing(LicenseResponse::getAcquireDate).reversed())
.toList();

// 스킬
List<SkillResponse> skills = skillRepository.findByRecordId(record.getId()).stream()
List<SkillResponse> skills = skillRepository.findByMemberId(memberId).stream()
.map(SkillResponse::new)
.collect(Collectors.toList());

// 파일
List<FileResponse> files = fileRepository.findByRecordId(record.getId()).stream()
List<FileResponse> files = fileRepository.findByMemberId(memberId).stream()
.map(FileResponse::new)
.collect(Collectors.toList());


return new RecordDownResponse(record, member, educationList, employments,
activitiesAndExperiences, projectsAndComp, eduCareers, awards, licenses, skills, files);

}




@Override
@Transactional
public EducationResponse saveEducation(Member requestMember, Long recordId, EducationReqDto educationReqDto) {
Expand Down Expand Up @@ -356,7 +352,7 @@ public LicenseResponse saveLicense(Member requestMember, Long recordId, LicenseR
}

License license = License.builder()
.record(record)
.memberId(requestMember.getId())
.licenseTag((licenseReqDto.getLicenseTag()))
.licenseName(licenseReqDto.getLicenseName())
.administer(licenseReqDto.getAdminister())
Expand All @@ -377,7 +373,7 @@ public LicenseResponse updateLicense(Member requestMember, Long licenseId, Licen
License license = licenseRepository.findById(licenseId)
.orElseThrow(() -> new ResourceNotFoundException("License", licenseId));

if (!license.getRecord().getMemberId().equals(requestMember.getId())) {
if (!license.getMemberId().equals(requestMember.getId())) {
throw new IntroOwnerMismatchException();
}

Expand All @@ -399,7 +395,7 @@ public Long deleteLicense(Member requestMember, Long licenseId) {
License license = licenseRepository.findById(licenseId)
.orElseThrow(() -> new ResourceNotFoundException("License", licenseId));

if (!license.getRecord().getMemberId().equals(requestMember.getId())) {
if (!license.getMemberId().equals(requestMember.getId())) {
throw new IntroOwnerMismatchException();
}

Expand All @@ -420,7 +416,7 @@ public AwardResponse saveAward(Member requestMember, Long recordId, AwardReqDto
}

Award award = Award.builder()
.record(record)
.memberId(requestMember.getId())
.competitionName(awardReqDto.getCompetitionName())
.administer(awardReqDto.getAdminister())
.awardName(awardReqDto.getAwardName())
Expand All @@ -439,7 +435,7 @@ public AwardResponse updateAward(Member requestMember, Long awardId, AwardReqDto
Award award = awardRepository.findById(awardId)
.orElseThrow(() -> new ResourceNotFoundException("Award", awardId));

if (!award.getRecord().getMemberId().equals(requestMember.getId())) {
if (!award.getMemberId().equals(requestMember.getId())) {
throw new IntroOwnerMismatchException();
}

Expand All @@ -460,7 +456,7 @@ public Long deleteAward(Member requestMember, Long awardId) {
Award award = awardRepository.findById(awardId)
.orElseThrow(() -> new ResourceNotFoundException("Award", awardId));

if (!award.getRecord().getMemberId().equals(requestMember.getId())) {
if (!award.getMemberId().equals(requestMember.getId())) {
throw new IntroOwnerMismatchException();
}

Expand All @@ -481,7 +477,7 @@ public SkillResponse saveSkill(Member requestMember, Long recordId, SkillReqDto
}

Skill skill = Skill.builder()
.record(record)
.memberId(requestMember.getId())
.skillTag(skillReqDto.getSkillTag())
.skillName(skillReqDto.getSkillName())
.workmanship(skillReqDto.getWorkmanship())
Expand All @@ -499,7 +495,7 @@ public SkillResponse updateSkill(Member requestMember, Long skillId, SkillReqDto
Skill skill = skillRepository.findById(skillId)
.orElseThrow(() -> new ResourceNotFoundException("Skill", skillId));

if (!skill.getRecord().getMemberId().equals(requestMember.getId())) {
if (!skill.getMemberId().equals(requestMember.getId())) {
throw new IntroOwnerMismatchException();
}

Expand All @@ -519,7 +515,7 @@ public Long deleteSkill(Member requestMember, Long skillId) {
Skill skill = skillRepository.findById(skillId)
.orElseThrow(() -> new ResourceNotFoundException("Skill", skillId));

if (!skill.getRecord().getMemberId().equals(requestMember.getId())) {
if (!skill.getMemberId().equals(requestMember.getId())) {
throw new IntroOwnerMismatchException();
}

Expand Down

0 comments on commit f5df15c

Please sign in to comment.