diff --git a/src/main/java/umc/kkijuk/server/career/controller/response/EtcResponse.java b/src/main/java/umc/kkijuk/server/career/controller/response/EtcResponse.java index 89789fd5..81713e80 100644 --- a/src/main/java/umc/kkijuk/server/career/controller/response/EtcResponse.java +++ b/src/main/java/umc/kkijuk/server/career/controller/response/EtcResponse.java @@ -46,6 +46,6 @@ public EtcResponse(CareerEtc etc, List details) { @Override public LocalDate getEndDate() { - return null; + return enddate; } } diff --git a/src/main/java/umc/kkijuk/server/career/controller/response/FindCareerResponse.java b/src/main/java/umc/kkijuk/server/career/controller/response/FindCareerResponse.java index 03832605..e0b095b4 100644 --- a/src/main/java/umc/kkijuk/server/career/controller/response/FindCareerResponse.java +++ b/src/main/java/umc/kkijuk/server/career/controller/response/FindCareerResponse.java @@ -2,8 +2,11 @@ import lombok.*; import umc.kkijuk.server.career.domain.BaseCareer; +import umc.kkijuk.server.detail.controller.response.BaseCareerDetailResponse; +import umc.kkijuk.server.detail.domain.CareerType; import java.time.LocalDate; +import java.util.List; @Data @Getter @@ -12,19 +15,21 @@ @AllArgsConstructor public class FindCareerResponse { private Long careerId; - private String careerType; private String careerTitle; private String careerAlias; private LocalDate startdate; private LocalDate enddate; + private CategoryResponse category; - public FindCareerResponse(BaseCareer career, String careerType){ - this.careerId = career.getId(); - this.careerType = careerType; - this.careerTitle = career.getName(); - this.careerAlias = career.getAlias(); - this.startdate = career.getStartdate(); - this.enddate = career.getEnddate(); + + public FindCareerResponse(Long careerId, String careerTitle, String careerAlias, + LocalDate startdate, LocalDate enddate, CareerType type){ + this.careerId = careerId; + this.careerTitle = careerTitle; + this.careerAlias = careerAlias; + this.startdate = startdate; + this.enddate = enddate; + this.category = new CategoryResponse(type.getId(),type.getDescription(),type.name()); } } diff --git a/src/main/java/umc/kkijuk/server/career/controller/response/FindDetailResponse.java b/src/main/java/umc/kkijuk/server/career/controller/response/FindDetailResponse.java index 234ebc72..38b8a25f 100644 --- a/src/main/java/umc/kkijuk/server/career/controller/response/FindDetailResponse.java +++ b/src/main/java/umc/kkijuk/server/career/controller/response/FindDetailResponse.java @@ -1,7 +1,9 @@ package umc.kkijuk.server.career.controller.response; import lombok.*; +import umc.kkijuk.server.career.domain.BaseCareer; import umc.kkijuk.server.detail.controller.response.BaseCareerDetailResponse; +import umc.kkijuk.server.detail.domain.CareerType; import java.time.LocalDate; @@ -14,16 +16,26 @@ @AllArgsConstructor public class FindDetailResponse implements BaseCareerResponse { private Long careerId; - private String careerType; + private CategoryResponse category; private String careerTitle; private String careerAlias; private LocalDate startdate; private LocalDate enddate; private List detailList; - @Override public LocalDate getEndDate() { return this.enddate; } + + public FindDetailResponse(Long careerId, String careerTitle, String careerAlias, LocalDate startdate, LocalDate enddate, + List detailList, CareerType type){ + this.careerId = careerId; + this.careerTitle = careerTitle; + this.careerAlias = careerAlias; + this.startdate = startdate; + this.enddate = enddate; + this.detailList = detailList; + this.category = new CategoryResponse(type.getId(),type.getDescription(),type.name()); + } } diff --git a/src/main/java/umc/kkijuk/server/career/domain/Activity.java b/src/main/java/umc/kkijuk/server/career/domain/Activity.java index 7bf412db..169a457c 100644 --- a/src/main/java/umc/kkijuk/server/career/domain/Activity.java +++ b/src/main/java/umc/kkijuk/server/career/domain/Activity.java @@ -13,7 +13,8 @@ @AllArgsConstructor(access = AccessLevel.PROTECTED) @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Activity extends BaseCareer { - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String organizer; private String role; @@ -21,8 +22,11 @@ public class Activity extends BaseCareer { private int contribution; private Boolean isTeam; - @OneToMany(mappedBy = "activity", cascade = CascadeType.ALL) - private List detailList = new ArrayList<>(); +// @OneToMany(mappedBy = "activity", cascade = CascadeType.ALL) +// private List detailList = new ArrayList<>(); +// @Convert(converter = LongListConverter.class) +// private List details = new ArrayList<>(); + @Override public Long getId() { return id; @@ -32,19 +36,21 @@ public Long getId() { public void setSummary(String summary) { super.setSummary(summary); } + @Builder public Activity(Long memberId, String name, String alias, Boolean unknown, LocalDate startdate, LocalDate enddate, String organizer, String role, int teamSize, int contribution, Boolean isTeam) { - super(memberId, name, alias, unknown,startdate, enddate); + super(memberId, name, alias, unknown, startdate, enddate); this.organizer = organizer; this.role = role; this.teamSize = teamSize; this.contribution = contribution; this.isTeam = isTeam; } - public void updateActivity(String name, String alias, Boolean unknown,LocalDate startdate, + + public void updateActivity(String name, String alias, Boolean unknown, LocalDate startdate, LocalDate enddate, String organizer, String role, int teamSize, int contribution, Boolean isTeam) { diff --git a/src/main/java/umc/kkijuk/server/career/domain/CareerEtc.java b/src/main/java/umc/kkijuk/server/career/domain/CareerEtc.java index 04651958..4981e9aa 100644 --- a/src/main/java/umc/kkijuk/server/career/domain/CareerEtc.java +++ b/src/main/java/umc/kkijuk/server/career/domain/CareerEtc.java @@ -17,8 +17,8 @@ public class CareerEtc extends BaseCareer{ @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @OneToMany(mappedBy = "etc", cascade = CascadeType.ALL) - private List detailList = new ArrayList<>(); +// @OneToMany(mappedBy = "etc", cascade = CascadeType.ALL) +// private List detailList = new ArrayList<>(); @Override public Long getId() { diff --git a/src/main/java/umc/kkijuk/server/career/domain/Circle.java b/src/main/java/umc/kkijuk/server/career/domain/Circle.java index 644ed15a..cb8b425a 100644 --- a/src/main/java/umc/kkijuk/server/career/domain/Circle.java +++ b/src/main/java/umc/kkijuk/server/career/domain/Circle.java @@ -18,8 +18,8 @@ public class Circle extends BaseCareer{ private Boolean location; private String role; - @OneToMany(mappedBy = "circle", cascade = CascadeType.ALL) - private List detailList = new ArrayList<>(); +// @OneToMany(mappedBy = "circle", cascade = CascadeType.ALL) +// private List detailList = new ArrayList<>(); @Override public Long getId() { return id; diff --git a/src/main/java/umc/kkijuk/server/career/domain/Competition.java b/src/main/java/umc/kkijuk/server/career/domain/Competition.java index e39284cc..f8948793 100644 --- a/src/main/java/umc/kkijuk/server/career/domain/Competition.java +++ b/src/main/java/umc/kkijuk/server/career/domain/Competition.java @@ -22,8 +22,8 @@ public class Competition extends BaseCareer{ private int contribution; private Boolean isTeam; - @OneToMany(mappedBy = "competition", cascade = CascadeType.ALL) - private List detailList = new ArrayList<>(); +// @OneToMany(mappedBy = "competition", cascade = CascadeType.ALL) +// private List detailList = new ArrayList<>(); @Override public Long getId() { return id; diff --git a/src/main/java/umc/kkijuk/server/career/domain/EduCareer.java b/src/main/java/umc/kkijuk/server/career/domain/EduCareer.java index b0fcb03e..b64f60f5 100644 --- a/src/main/java/umc/kkijuk/server/career/domain/EduCareer.java +++ b/src/main/java/umc/kkijuk/server/career/domain/EduCareer.java @@ -19,8 +19,8 @@ public class EduCareer extends BaseCareer { private String organizer; private int time; - @OneToMany(mappedBy = "eduCareer", cascade = CascadeType.ALL) - private List detailList = new ArrayList<>(); +// @OneToMany(mappedBy = "eduCareer", cascade = CascadeType.ALL) +// private List detailList = new ArrayList<>(); @Override public Long getId() { return id; diff --git a/src/main/java/umc/kkijuk/server/career/domain/Employment.java b/src/main/java/umc/kkijuk/server/career/domain/Employment.java index f44a01de..4ba74abb 100644 --- a/src/main/java/umc/kkijuk/server/career/domain/Employment.java +++ b/src/main/java/umc/kkijuk/server/career/domain/Employment.java @@ -20,8 +20,8 @@ public class Employment extends BaseCareer{ private String position; private String field; - @OneToMany(mappedBy = "employment", cascade = CascadeType.ALL) - private List detailList = new ArrayList<>(); +// @OneToMany(mappedBy = "employment", cascade = CascadeType.ALL) +// private List detailList = new ArrayList<>(); @Override public Long getId() { return id; diff --git a/src/main/java/umc/kkijuk/server/career/domain/Project.java b/src/main/java/umc/kkijuk/server/career/domain/Project.java index 76916ba4..701cf01d 100644 --- a/src/main/java/umc/kkijuk/server/career/domain/Project.java +++ b/src/main/java/umc/kkijuk/server/career/domain/Project.java @@ -21,8 +21,8 @@ public class Project extends BaseCareer{ @Enumerated(EnumType.STRING) private ProjectType location; - @OneToMany(mappedBy = "project", cascade = CascadeType.ALL) - private List detailList = new ArrayList<>(); +// @OneToMany(mappedBy = "project", cascade = CascadeType.ALL) +// private List detailList = new ArrayList<>(); @Override public Long getId() { return id; diff --git a/src/main/java/umc/kkijuk/server/career/service/CareerSearchServiceImpl.java b/src/main/java/umc/kkijuk/server/career/service/CareerSearchServiceImpl.java index fb4c77f5..b3f4d874 100644 --- a/src/main/java/umc/kkijuk/server/career/service/CareerSearchServiceImpl.java +++ b/src/main/java/umc/kkijuk/server/career/service/CareerSearchServiceImpl.java @@ -103,8 +103,6 @@ public Map> findAllCareerGroupedYear(Long memberId) { .map(EtcResponse::new).collect(Collectors.toList())); -// baseCareers.stream().sorted(Comparator.comparing(BaseCareerResponse::getEndDate).reversed()); - baseCareers = baseCareers.stream() .sorted(Comparator.comparing(BaseCareerResponse::getEndDate).reversed()) .collect(Collectors.toList()); @@ -129,26 +127,26 @@ public Map> findAllCareerGroupedYear(Long memberId) { @Override public List findAllCareer(Long memberId) { List baseCareers = projectRepository.findByMemberId(memberId).stream() - .map(project-> new ProjectResponse(project,detailRepository.findByProject(project))) + .map(project-> new ProjectResponse(project,detailRepository.findByCareerIdAndCareerType(CareerType.PROJECT,project.getId()))) .collect(Collectors.toList()); baseCareers.addAll(competitionRepository.findByMemberId(memberId).stream() - .map(comp-> new CompetitionResponse(comp, detailRepository.findByCompetition(comp))) + .map(comp-> new CompetitionResponse(comp, detailRepository.findByCareerIdAndCareerType(CareerType.COM,comp.getId()))) .collect(Collectors.toList())); baseCareers.addAll(activityRepository.findByMemberId(memberId).stream() - .map(activity->new ActivityResponse(activity, detailRepository.findByActivity(activity))) + .map(activity->new ActivityResponse(activity, detailRepository.findByCareerIdAndCareerType(CareerType.ACTIVITY,activity.getId()))) .collect(Collectors.toList())); baseCareers.addAll(circleRepository.findByMemberId(memberId).stream() - .map(circle-> new CircleResponse(circle, detailRepository.findByCircle(circle))) + .map(circle-> new CircleResponse(circle, detailRepository.findByCareerIdAndCareerType(CareerType.CIRCLE,circle.getId()))) .collect(Collectors.toList())); baseCareers.addAll(eduCareerRepository.findByMemberId(memberId).stream() - .map(eduCareer -> new EduCareerResponse(eduCareer, detailRepository.findByEduCareer(eduCareer))) + .map(eduCareer -> new EduCareerResponse(eduCareer, detailRepository.findByCareerIdAndCareerType(CareerType.EDU,eduCareer.getId()))) .collect(Collectors.toList())); baseCareers.addAll(employmentRepository.findByMemberId(memberId).stream() - .map(employment -> new EmploymentResponse(employment, detailRepository.findByEmployment(employment))) + .map(employment -> new EmploymentResponse(employment, detailRepository.findByCareerIdAndCareerType(CareerType.EMP,employment.getId()))) .collect(Collectors.toList())); baseCareers.addAll(etcRepository.findByMemberId(memberId).stream() - .map(etc -> new EtcResponse(etc, detailRepository.findByEtc(etc))) + .map(etc -> new EtcResponse(etc, detailRepository.findByCareerIdAndCareerType(CareerType.ETC,etc.getId()))) .collect(Collectors.toList())); baseCareers = baseCareers.stream() @@ -252,7 +250,8 @@ public List findCareerWithKeyword(Member requestMember, Stri } return careers.stream().limit(2) - .map(career -> new FindCareerResponse(career, career.getClass().getSimpleName())) + .map(career -> new FindCareerResponse(career.getId(), career.getName(), career.getAlias(), + career.getStartdate(), career.getEnddate(), CareerType.fromClass(career))) .collect(Collectors.toList()); } @@ -282,25 +281,25 @@ private CareerType resolveCareerType(BaseCareer career) { private R getResponse(T career, BiFunction, R> responseConstructor) { List details; if (career instanceof Activity) { - details = Optional.ofNullable(detailRepository.findByActivity((Activity) career)) + details = Optional.ofNullable(detailRepository.findByCareerIdAndCareerType(CareerType.ACTIVITY, career.getId())) .orElseGet(Collections::emptyList); } else if (career instanceof Circle) { - details = Optional.ofNullable(detailRepository.findByCircle((Circle) career)) + details = Optional.ofNullable(detailRepository.findByCareerIdAndCareerType(CareerType.CIRCLE, career.getId())) .orElseGet(Collections::emptyList); } else if (career instanceof Competition) { - details = Optional.ofNullable(detailRepository.findByCompetition((Competition) career)) + details = Optional.ofNullable(detailRepository.findByCareerIdAndCareerType(CareerType.COM, career.getId())) .orElseGet(Collections::emptyList); } else if (career instanceof EduCareer) { - details =Optional.ofNullable(detailRepository.findByEduCareer((EduCareer) career)) + details =Optional.ofNullable(detailRepository.findByCareerIdAndCareerType(CareerType.EDU, career.getId())) .orElseGet(Collections::emptyList); } else if (career instanceof Employment) { - details = Optional.ofNullable( detailRepository.findByEmployment((Employment) career)) + details = Optional.ofNullable( detailRepository.findByCareerIdAndCareerType(CareerType.EMP, career.getId())) .orElseGet(Collections::emptyList); } else if (career instanceof Project) { - details = Optional.ofNullable( detailRepository.findByProject((Project) career)) + details = Optional.ofNullable( detailRepository.findByCareerIdAndCareerType(CareerType.PROJECT, career.getId())) .orElseGet(Collections::emptyList); } else if (career instanceof CareerEtc) { - details = Optional.ofNullable( detailRepository.findByEtc((CareerEtc) career)) + details = Optional.ofNullable( detailRepository.findByCareerIdAndCareerType(CareerType.ETC, career.getId())) .orElseGet(Collections::emptyList); } else { @@ -309,10 +308,10 @@ private R getResponse(T car return responseConstructor.apply(career,details); } private List buildDetailResponse(List detailList, String sort) { - Map>> groupedDetails = new HashMap<>(); + Map>> groupedDetails = new HashMap<>(); for (BaseCareerDetail detail : detailList) { - String careerType = getCareerType(detail); - Long careerId = getCareerId(detail); + CareerType careerType = getCareerType(detail); + Long careerId = detail.getCareerId(); groupedDetails .computeIfAbsent(careerType, k -> new HashMap<>()) .computeIfAbsent(careerId, k -> new ArrayList<>()) @@ -321,8 +320,8 @@ private List buildDetailResponse(List deta List result = new ArrayList<>(); - for(Map.Entry>> entry : groupedDetails.entrySet()) { - String type = entry.getKey(); + for(Map.Entry>> entry : groupedDetails.entrySet()) { + CareerType type = entry.getKey(); Map> careerMap = entry.getValue(); for(Map.Entry> careerEntry : careerMap.entrySet()){ @@ -335,7 +334,9 @@ private List buildDetailResponse(List deta detailResponses.add(new BaseCareerDetailResponse(detail)); } - result.add(new FindDetailResponse(careerId,type,detailInfo.title,detailInfo.alias,detailInfo.startDate,detailInfo.endDate,detailResponses)); + result.add(new FindDetailResponse(careerId, detailInfo.title,detailInfo.alias, + detailInfo.startDate,detailInfo.endDate, + detailResponses,type)); } } if (sort.equals("new")) { @@ -347,30 +348,30 @@ private List buildDetailResponse(List deta } - private String getCareerType(BaseCareerDetail detail) { - switch (detail.getCareerType()) { - case ACTIVITY: return CareerType.ACTIVITY.getDescription(); - case PROJECT: return CareerType.PROJECT.getDescription(); - case EMP: return CareerType.EMP.getDescription(); - case EDU: return CareerType.EDU.getDescription(); - case COM: return CareerType.COM.getDescription(); - case CIRCLE: return CareerType.CIRCLE.getDescription(); - case ETC:return CareerType.ETC.getDescription(); - default: return null; - } - } - private Long getCareerId(BaseCareerDetail detail) { + private CareerType getCareerType(BaseCareerDetail detail) { switch (detail.getCareerType()) { - case ACTIVITY: return detail.getActivity().getId(); - case PROJECT: return detail.getProject().getId(); - case EMP: return detail.getEmployment().getId(); - case EDU: return detail.getEduCareer().getId(); - case COM: return detail.getCompetition().getId(); - case CIRCLE: return detail.getCircle().getId(); - case ETC: return detail.getEtc().getId(); + case ACTIVITY: return CareerType.ACTIVITY; + case PROJECT: return CareerType.PROJECT; + case EMP: return CareerType.EMP; + case EDU: return CareerType.EDU; + case COM: return CareerType.COM; + case CIRCLE: return CareerType.CIRCLE; + case ETC:return CareerType.ETC; default: return null; } } +// private Long getCareerId(BaseCareerDetail detail) { +// switch (detail.getCareerType()) { +// case ACTIVITY: return detail.getActivity().getId(); +// case PROJECT: return detail.getProject().getId(); +// case EMP: return detail.getEmployment().getId(); +// case EDU: return detail.getEduCareer().getId(); +// case COM: return detail.getCompetition().getId(); +// case CIRCLE: return detail.getCircle().getId(); +// case ETC: return detail.getEtc().getId(); +// default: return null; +// } +// } private CareerSearchServiceImpl.FindDetailInfo extractDetailInfo(List details) { if (details.isEmpty()) { return new CareerSearchServiceImpl.FindDetailInfo(null, null, null, null); @@ -384,32 +385,39 @@ private CareerSearchServiceImpl.FindDetailInfo extractDetailInfo(List { - title = firstDetail.getActivity().getName(); - alias = firstDetail.getActivity().getAlias(); + Activity activity = activityRepository.findById(firstDetail.getCareerId()).get(); + title = activity.getName(); + alias = activity.getAlias(); } case PROJECT -> { - title = firstDetail.getProject().getName(); - alias = firstDetail.getProject().getAlias(); + Project project = projectRepository.findById(firstDetail.getCareerId()).get(); + title = project.getName(); + alias = project.getAlias(); } case EMP -> { - title = firstDetail.getEmployment().getName(); - alias = firstDetail.getEmployment().getAlias(); + Employment emp = employmentRepository.findById(firstDetail.getCareerId()).get(); + title = emp.getName(); + alias = emp.getAlias(); } case EDU -> { - title = firstDetail.getEduCareer().getName(); - alias = firstDetail.getEduCareer().getAlias(); + EduCareer edu = eduCareerRepository.findById(firstDetail.getCareerId()).get(); + title = edu.getName(); + alias = edu.getAlias(); } case COM -> { - title = firstDetail.getCompetition().getName(); - alias = firstDetail.getCompetition().getAlias(); + Competition competition = competitionRepository.findById(firstDetail.getCareerId()).get(); + title = competition.getName(); + alias = competition.getAlias(); } case CIRCLE -> { - title = firstDetail.getCircle().getName(); - alias = firstDetail.getCircle().getAlias(); + Circle circle = circleRepository.findById(firstDetail.getCareerId()).get(); + title = circle.getName(); + alias = circle.getAlias(); } case ETC -> { - title = firstDetail.getEtc().getName(); - alias = firstDetail.getEtc().getAlias(); + CareerEtc etc = etcRepository.findById(firstDetail.getCareerId()).get(); + title = etc.getName(); + alias = etc.getAlias(); } } diff --git a/src/main/java/umc/kkijuk/server/career/service/CareerServiceImpl.java b/src/main/java/umc/kkijuk/server/career/service/CareerServiceImpl.java index 819dc29b..57ab3db7 100644 --- a/src/main/java/umc/kkijuk/server/career/service/CareerServiceImpl.java +++ b/src/main/java/umc/kkijuk/server/career/service/CareerServiceImpl.java @@ -11,6 +11,7 @@ import umc.kkijuk.server.common.domian.exception.OwnerMismatchException; import umc.kkijuk.server.common.domian.exception.ResourceNotFoundException; import umc.kkijuk.server.detail.domain.BaseCareerDetail; +import umc.kkijuk.server.detail.domain.CareerType; import umc.kkijuk.server.detail.repository.BaseCareerDetailRepository; import umc.kkijuk.server.member.domain.Member; @@ -406,25 +407,28 @@ public BaseCareerResponse createSummary(Member requestMember, Long careerId, Car private R getResponse(T career, BiFunction, R> responseConstructor) { List details; if (career instanceof Activity) { - details = Optional.ofNullable(detailRepository.findByActivity((Activity) career)) + details = Optional.ofNullable(detailRepository.findByCareerIdAndCareerType(CareerType.ACTIVITY, career.getId())) .orElseGet(Collections::emptyList); } else if (career instanceof Circle) { - details = Optional.ofNullable(detailRepository.findByCircle((Circle) career)) + details = Optional.ofNullable(detailRepository.findByCareerIdAndCareerType(CareerType.CIRCLE, career.getId())) .orElseGet(Collections::emptyList); } else if (career instanceof Competition) { - details = Optional.ofNullable(detailRepository.findByCompetition((Competition) career)) + details = Optional.ofNullable(detailRepository.findByCareerIdAndCareerType(CareerType.COM, career.getId())) .orElseGet(Collections::emptyList); } else if (career instanceof EduCareer) { - details =Optional.ofNullable(detailRepository.findByEduCareer((EduCareer) career)) + details =Optional.ofNullable(detailRepository.findByCareerIdAndCareerType(CareerType.EDU, career.getId())) .orElseGet(Collections::emptyList); } else if (career instanceof Employment) { - details = Optional.ofNullable( detailRepository.findByEmployment((Employment) career)) + details = Optional.ofNullable( detailRepository.findByCareerIdAndCareerType(CareerType.EMP, career.getId())) .orElseGet(Collections::emptyList); - } else if (career instanceof Project) { - details = Optional.ofNullable( detailRepository.findByProject((Project) career)) + details = Optional.ofNullable( detailRepository.findByCareerIdAndCareerType(CareerType.PROJECT, career.getId())) .orElseGet(Collections::emptyList); - } else { + } else if (career instanceof CareerEtc) { + details = Optional.ofNullable( detailRepository.findByCareerIdAndCareerType(CareerType.ETC, career.getId())) + .orElseGet(Collections::emptyList); + } + else { throw new IllegalArgumentException("지원하지 않는 타입입니다."); } return responseConstructor.apply(career,details); diff --git a/src/main/java/umc/kkijuk/server/detail/domain/BaseCareerDetail.java b/src/main/java/umc/kkijuk/server/detail/domain/BaseCareerDetail.java index 5f83f3df..cb08a1e2 100644 --- a/src/main/java/umc/kkijuk/server/detail/domain/BaseCareerDetail.java +++ b/src/main/java/umc/kkijuk/server/detail/domain/BaseCareerDetail.java @@ -29,6 +29,9 @@ public class BaseCareerDetail extends BaseEntity { @Enumerated(EnumType.STRING) private CareerType careerType; + @Column(nullable = false) + private Long careerId; + @Column(nullable = false) private Long memberId; @@ -38,33 +41,34 @@ public class BaseCareerDetail extends BaseEntity { - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name="activity_id") - private Activity activity; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name="circle_id") - private Circle circle; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name="competition_id") - private Competition competition; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name="edu_id") - private EduCareer eduCareer; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name="employment_id") - private Employment employment; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name="project_id") - private Project project; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name="etc_id") - private CareerEtc etc; +// @ManyToOne(fetch = FetchType.LAZY) +// @JoinColumn(name="activity_id") +// private Activity activity; +// +// @ManyToOne(fetch = FetchType.LAZY) +// @JoinColumn(name="circle_id") +// private Circle circle; +// +// @ManyToOne(fetch = FetchType.LAZY) +// @JoinColumn(name="competition_id") +// private Competition competition; +// +// @ManyToOne(fetch = FetchType.LAZY) +// @JoinColumn(name="edu_id") +// private EduCareer eduCareer; +// +// @ManyToOne(fetch = FetchType.LAZY) +// @JoinColumn(name="employment_id") +// private Employment employment; +// +// @ManyToOne(fetch = FetchType.LAZY) +// @JoinColumn(name="project_id") +// private Project project; +// +// @ManyToOne(fetch = FetchType.LAZY) +// @JoinColumn(name="etc_id") +// private CareerEtc etc; diff --git a/src/main/java/umc/kkijuk/server/detail/domain/CareerType.java b/src/main/java/umc/kkijuk/server/detail/domain/CareerType.java index ea04684f..a1e36223 100644 --- a/src/main/java/umc/kkijuk/server/detail/domain/CareerType.java +++ b/src/main/java/umc/kkijuk/server/detail/domain/CareerType.java @@ -1,24 +1,40 @@ package umc.kkijuk.server.detail.domain; +import umc.kkijuk.server.career.domain.*; + public enum CareerType { - ACTIVITY(1,"대외활동"), - PROJECT(2,"프로젝트"), - EDU(3,"교육"), - EMP(4,"경력"), - CIRCLE(5,"동아리"), - COM(6,"대회"), - ETC(7,"기타"); + ACTIVITY(1,"대외활동", Activity.class), + PROJECT(2,"프로젝트", Project.class), + EDU(3,"교육", EduCareer.class), + EMP(4,"경력", Employment.class), + CIRCLE(5,"동아리", Circle.class), + COM(6,"대회", Competition.class), + ETC(7,"기타", CareerEtc.class); private final int id; private final String description; + private final Class career; - CareerType(int id,String description) { + CareerType(int id, String description, Class career) { this.id = id; this.description = description; + this.career = career; } public String getDescription() { return description; } public int getId() {return id;} + public Class getCareer() { + return career; + } + public static CareerType fromClass(BaseCareer careerClass){ + for (CareerType type : values()) { + if (type.getCareer().equals(careerClass.getClass())) { + return type; + } + } + throw new IllegalArgumentException("지원하는 활동이 아닙니다 : " + careerClass.getClass()); + + } } diff --git a/src/main/java/umc/kkijuk/server/detail/dto/converter/BaseCareerDetailConverter.java b/src/main/java/umc/kkijuk/server/detail/dto/converter/BaseCareerDetailConverter.java index 5cb18468..b6595c4d 100644 --- a/src/main/java/umc/kkijuk/server/detail/dto/converter/BaseCareerDetailConverter.java +++ b/src/main/java/umc/kkijuk/server/detail/dto/converter/BaseCareerDetailConverter.java @@ -8,76 +8,86 @@ import java.util.ArrayList; public class BaseCareerDetailConverter { - public static BaseCareerDetail toBaseCareerDetail(Member requestMember, CareerDetailReqDto request, BaseCareer baseCareer) { - if(baseCareer instanceof Activity){ - return BaseCareerDetail.builder() - .activity((Activity) baseCareer) - .careerType(request.getCareerType()) - .memberId(requestMember.getId()) - .title(request.getTitle()) - .content(request.getContent()) - .startDate(request.getStartDate()) - .endDate(request.getEndDate()) - .careerTagList(new ArrayList<>()) - .build(); - - }else if ( baseCareer instanceof Project){ - return BaseCareerDetail.builder() - .project((Project) baseCareer) - .careerType(request.getCareerType()) - .memberId(requestMember.getId()) - .title(request.getTitle()) - .content(request.getContent()) - .startDate(request.getStartDate()) - .endDate(request.getEndDate()) - .careerTagList(new ArrayList<>()) - .build(); - }else if ( baseCareer instanceof Circle){ - return BaseCareerDetail.builder() - .circle((Circle) baseCareer) - .careerType(request.getCareerType()) - .memberId(requestMember.getId()) - .title(request.getTitle()) - .content(request.getContent()) - .startDate(request.getStartDate()) - .endDate(request.getEndDate()) - .careerTagList(new ArrayList<>()) - .build(); - }else if ( baseCareer instanceof Employment){ - return BaseCareerDetail.builder() - .employment((Employment) baseCareer) - .careerType(request.getCareerType()) - .memberId(requestMember.getId()) - .title(request.getTitle()) - .content(request.getContent()) - .startDate(request.getStartDate()) - .endDate(request.getEndDate()) - .careerTagList(new ArrayList<>()) - .build(); - }else if ( baseCareer instanceof EduCareer){ - return BaseCareerDetail.builder() - .eduCareer((EduCareer) baseCareer) - .careerType(request.getCareerType()) - .memberId(requestMember.getId()) - .title(request.getTitle()) - .content(request.getContent()) - .startDate(request.getStartDate()) - .endDate(request.getEndDate()) - .careerTagList(new ArrayList<>()) - .build(); - }else{ - return BaseCareerDetail.builder() - .competition((Competition) baseCareer) - .careerType(request.getCareerType()) - .memberId(requestMember.getId()) - .title(request.getTitle()) - .content(request.getContent()) - .startDate(request.getStartDate()) - .endDate(request.getEndDate()) - .careerTagList(new ArrayList<>()) - .build(); - - } + public static BaseCareerDetail toBaseCareerDetail(Member requestMember, CareerDetailReqDto request, Long careerId) { + return BaseCareerDetail.builder() + .careerType(request.getCareerType()) + .memberId(requestMember.getId()) + .careerId(careerId) + .title(request.getTitle()) + .content(request.getContent()) + .startDate(request.getStartDate()) + .endDate(request.getEndDate()) + .careerTagList(new ArrayList<>()) + .build(); +// if(baseCareer instanceof Activity){ +// return BaseCareerDetail.builder() +// .activity((Activity) baseCareer) +// .careerType(request.getCareerType()) +// .memberId(requestMember.getId()) +// .title(request.getTitle()) +// .content(request.getContent()) +// .startDate(request.getStartDate()) +// .endDate(request.getEndDate()) +// .careerTagList(new ArrayList<>()) +// .build(); +// +// }else if ( baseCareer instanceof Project){ +// return BaseCareerDetail.builder() +// .project((Project) baseCareer) +// .careerType(request.getCareerType()) +// .memberId(requestMember.getId()) +// .title(request.getTitle()) +// .content(request.getContent()) +// .startDate(request.getStartDate()) +// .endDate(request.getEndDate()) +// .careerTagList(new ArrayList<>()) +// .build(); +// }else if ( baseCareer instanceof Circle){ +// return BaseCareerDetail.builder() +// .circle((Circle) baseCareer) +// .careerType(request.getCareerType()) +// .memberId(requestMember.getId()) +// .title(request.getTitle()) +// .content(request.getContent()) +// .startDate(request.getStartDate()) +// .endDate(request.getEndDate()) +// .careerTagList(new ArrayList<>()) +// .build(); +// }else if ( baseCareer instanceof Employment){ +// return BaseCareerDetail.builder() +// .employment((Employment) baseCareer) +// .careerType(request.getCareerType()) +// .memberId(requestMember.getId()) +// .title(request.getTitle()) +// .content(request.getContent()) +// .startDate(request.getStartDate()) +// .endDate(request.getEndDate()) +// .careerTagList(new ArrayList<>()) +// .build(); +// }else if ( baseCareer instanceof EduCareer){ +// return BaseCareerDetail.builder() +// .eduCareer((EduCareer) baseCareer) +// .careerType(request.getCareerType()) +// .memberId(requestMember.getId()) +// .title(request.getTitle()) +// .content(request.getContent()) +// .startDate(request.getStartDate()) +// .endDate(request.getEndDate()) +// .careerTagList(new ArrayList<>()) +// .build(); +// }else{ +// return BaseCareerDetail.builder() +// .competition((Competition) baseCareer) +// .careerType(request.getCareerType()) +// .memberId(requestMember.getId()) +// .title(request.getTitle()) +// .content(request.getContent()) +// .startDate(request.getStartDate()) +// .endDate(request.getEndDate()) +// .careerTagList(new ArrayList<>()) +// .build(); +// +// } } diff --git a/src/main/java/umc/kkijuk/server/detail/repository/BaseCareerDetailRepository.java b/src/main/java/umc/kkijuk/server/detail/repository/BaseCareerDetailRepository.java index a2dfe56e..dbc5215c 100644 --- a/src/main/java/umc/kkijuk/server/detail/repository/BaseCareerDetailRepository.java +++ b/src/main/java/umc/kkijuk/server/detail/repository/BaseCareerDetailRepository.java @@ -5,47 +5,55 @@ import org.springframework.data.repository.query.Param; import umc.kkijuk.server.career.domain.*; import umc.kkijuk.server.detail.domain.BaseCareerDetail; +import umc.kkijuk.server.detail.domain.CareerType; import java.util.List; public interface BaseCareerDetailRepository extends JpaRepository { - @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + - "LEFT JOIN FETCH bcd.careerTagList ct " + - "LEFT JOIN FETCH ct.tag t " + - "WHERE bcd.competition = :competition") - List findByCompetition(Competition competition); - @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + - "LEFT JOIN FETCH bcd.careerTagList ct " + - "LEFT JOIN FETCH ct.tag t " + - "WHERE bcd.activity = :activity") - List findByActivity(Activity activity); - @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + - "LEFT JOIN FETCH bcd.careerTagList ct " + - "LEFT JOIN FETCH ct.tag t " + - "WHERE bcd.circle = :circle") - List findByCircle(Circle circle); - @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + - "LEFT JOIN FETCH bcd.careerTagList ct " + - "LEFT JOIN FETCH ct.tag t " + - "WHERE bcd.project = :project") - List findByProject(Project project); - @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + - "LEFT JOIN FETCH bcd.careerTagList ct " + - "LEFT JOIN FETCH ct.tag t " + - "WHERE bcd.eduCareer = :edu") - List findByEduCareer(EduCareer edu); - @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + - "LEFT JOIN FETCH bcd.careerTagList ct " + - "LEFT JOIN FETCH ct.tag t " + - "WHERE bcd.employment = :emp") - List findByEmployment(Employment emp); +// @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + +// "LEFT JOIN FETCH bcd.careerTagList ct " + +// "LEFT JOIN FETCH ct.tag t " + +// "WHERE bcd.competition = :competition") +// List findByCompetition(Competition competition); +// @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + +// "LEFT JOIN FETCH bcd.careerTagList ct " + +// "LEFT JOIN FETCH ct.tag t " + +// "WHERE bcd.activity = :activity") +// List findByActivity(Activity activity); +// @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + +// "LEFT JOIN FETCH bcd.careerTagList ct " + +// "LEFT JOIN FETCH ct.tag t " + +// "WHERE bcd.circle = :circle") +// List findByCircle(Circle circle); +// @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + +// "LEFT JOIN FETCH bcd.careerTagList ct " + +// "LEFT JOIN FETCH ct.tag t " + +// "WHERE bcd.project = :project") +// List findByProject(Project project); +// @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + +// "LEFT JOIN FETCH bcd.careerTagList ct " + +// "LEFT JOIN FETCH ct.tag t " + +// "WHERE bcd.eduCareer = :edu") +// List findByEduCareer(EduCareer edu); +// @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + +// "LEFT JOIN FETCH bcd.careerTagList ct " + +// "LEFT JOIN FETCH ct.tag t " + +// "WHERE bcd.employment = :emp") +// List findByEmployment(Employment emp); +// +// @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + +// "LEFT JOIN FETCH bcd.careerTagList ct " + +// "LEFT JOIN FETCH ct.tag t " + +// "WHERE bcd.etc = :etc") +// List findByEtc(CareerEtc etc); - @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + + @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + "LEFT JOIN FETCH bcd.careerTagList ct " + - "LEFT JOIN FETCH ct.tag t " + - "WHERE bcd.etc = :etc") - List findByEtc(CareerEtc etc); - + "LEFT JOIN FETCH ct.tag t "+ + "WHERE bcd.careerType = :careerType AND bcd.careerId = :careerId" + ) + List findByCareerIdAndCareerType(@Param("careerType") CareerType careerType, + @Param("careerId") Long careerId); @Query("SELECT DISTINCT bcd FROM BaseCareerDetail bcd " + "LEFT JOIN FETCH bcd.careerTagList ct " + "LEFT JOIN FETCH ct.tag t " + @@ -58,7 +66,4 @@ public interface BaseCareerDetailRepository extends JpaRepository findByTag(@Param("tagId") Long tagId); - - - } diff --git a/src/main/java/umc/kkijuk/server/detail/service/BaseCareerDetailServiceImpl.java b/src/main/java/umc/kkijuk/server/detail/service/BaseCareerDetailServiceImpl.java index c0d645b2..c8df5331 100644 --- a/src/main/java/umc/kkijuk/server/detail/service/BaseCareerDetailServiceImpl.java +++ b/src/main/java/umc/kkijuk/server/detail/service/BaseCareerDetailServiceImpl.java @@ -43,11 +43,10 @@ public BaseCareerDetailResponse createDetail(Member requestMember, CareerDetailR validateOwner(career, requestMember); List detailTagList = returnCareerTagList(request.getTagList()); - BaseCareerDetail newBaseCareerDetail = BaseCareerDetailConverter.toBaseCareerDetail(requestMember, request, career); + BaseCareerDetail newBaseCareerDetail = BaseCareerDetailConverter.toBaseCareerDetail(requestMember, request, careerId); - addDetailToCareer(career, newBaseCareerDetail); +// addDetailToCareer(career, newBaseCareerDetail); detailTagList.forEach(tag -> tag.setBaseCareerDetail(newBaseCareerDetail)); - return new BaseCareerDetailResponse(baseCareerDetailRepository.save(newBaseCareerDetail)); } @@ -95,24 +94,23 @@ private void validateOwner(BaseCareer career, Member requestMember) { } } - private void addDetailToCareer(BaseCareer career, BaseCareerDetail detail) { - if (career instanceof Competition) { - ((Competition) career).getDetailList().add(detail); - } else if (career instanceof Activity) { - ((Activity) career).getDetailList().add(detail); - } else if (career instanceof EduCareer) { - ((EduCareer) career).getDetailList().add(detail); - } else if (career instanceof Employment) { - ((Employment) career).getDetailList().add(detail); - } else if (career instanceof Circle) { - ((Circle) career).getDetailList().add(detail); - } else if (career instanceof Project) { - ((Project) career).getDetailList().add(detail); - } else { - throw new IllegalArgumentException("지원하지 않는 활동 유형입니다."); - } - } - +// private void addDetailToCareer(BaseCareer career, BaseCareerDetail detail) { +// if (career instanceof Competition) { +// ((Competition) career).getDetailList().add(detail); +// } else if (career instanceof Activity) { +// ((Activity) career).getDetailList().add(detail); +// } else if (career instanceof EduCareer) { +// ((EduCareer) career).getDetailList().add(detail); +// } else if (career instanceof Employment) { +// ((Employment) career).getDetailList().add(detail); +// } else if (career instanceof Circle) { +// ((Circle) career).getDetailList().add(detail); +// } else if (career instanceof Project) { +// ((Project) career).getDetailList().add(detail); +// } else { +// throw new IllegalArgumentException("지원하지 않는 활동 유형입니다."); +// } +// } private BaseCareer findBaseCareerByType(CareerType careerType, Long careerId) { return switch (careerType) { case ACTIVITY -> activityRepository.findById(careerId) diff --git a/src/test/java/umc/kkijuk/server/unitTest/career/controller/CareerControllerTest.java b/src/test/java/umc/kkijuk/server/unitTest/career/controller/CareerControllerTest.java index 45d806a6..02ffcb2d 100644 --- a/src/test/java/umc/kkijuk/server/unitTest/career/controller/CareerControllerTest.java +++ b/src/test/java/umc/kkijuk/server/unitTest/career/controller/CareerControllerTest.java @@ -11,7 +11,7 @@ import umc.kkijuk.server.career.controller.response.*; import umc.kkijuk.server.career.domain.*; import umc.kkijuk.server.career.dto.*; -import umc.kkijuk.server.career.service.BaseCareerServiceImpl; +import umc.kkijuk.server.career.service.CareerServiceImpl; import umc.kkijuk.server.common.domian.exception.ResourceNotFoundException; import umc.kkijuk.server.detail.domain.CareerType; import umc.kkijuk.server.login.controller.dto.LoginInfo; @@ -28,7 +28,7 @@ public class CareerControllerTest { @InjectMocks private BaseCareerController careerController; @Mock - private BaseCareerServiceImpl baseCareerService; + private CareerServiceImpl baseCareerService; @Mock private MemberServiceImpl memberService; public final Long requestMemberId = 1L;