Skip to content

Commit

Permalink
GETP-208 refactor: 영속성 관련 기능을 persistence adapter로 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
scv1702 committed Aug 27, 2024
1 parent 50cbfee commit 1504f94
Show file tree
Hide file tree
Showing 22 changed files with 209 additions and 153 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package es.princip.getp.application.project.apply;

import es.princip.getp.application.project.apply.command.ApplyProjectCommand;
import es.princip.getp.application.project.apply.exception.AlreadyAppliedProjectException;
import es.princip.getp.application.project.apply.port.in.ApplyProjectUseCase;
import es.princip.getp.application.project.apply.port.out.CheckProjectApplicationPort;
import es.princip.getp.application.project.apply.port.out.SaveProjectApplicationPort;
import es.princip.getp.application.project.commission.port.out.LoadProjectPort;
import es.princip.getp.domain.people.command.domain.People;
import es.princip.getp.domain.people.command.domain.PeopleRepository;
import es.princip.getp.domain.people.exception.NotFoundPeopleException;
import es.princip.getp.domain.project.apply.exception.AlreadyAppliedProjectException;
import es.princip.getp.domain.project.apply.model.ProjectApplication;
import es.princip.getp.domain.project.apply.service.ProjectApplier;
import es.princip.getp.domain.project.commission.model.Project;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package es.princip.getp.domain.project.apply.exception;
package es.princip.getp.application.project.apply.exception;

import es.princip.getp.common.exception.BusinessLogicException;
import es.princip.getp.common.exception.ErrorDescription;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package es.princip.getp.application.project.meeting;

import es.princip.getp.application.project.apply.port.out.CheckProjectApplicationPort;
import es.princip.getp.application.project.commission.port.out.LoadProjectPort;
import es.princip.getp.application.project.meeting.command.ScheduleMeetingCommand;
import es.princip.getp.application.project.meeting.exception.NotApplicantException;
Expand All @@ -9,7 +10,6 @@
import es.princip.getp.domain.people.command.domain.People;
import es.princip.getp.domain.people.command.domain.PeopleRepository;
import es.princip.getp.domain.people.exception.NotFoundPeopleException;
import es.princip.getp.domain.project.apply.ProjectApplicationRepository;
import es.princip.getp.domain.project.commission.model.Project;
import es.princip.getp.domain.project.meeting.model.ProjectMeeting;
import lombok.RequiredArgsConstructor;
Expand All @@ -24,8 +24,7 @@ public class ProjectMeetingService {
private final PeopleRepository peopleRepository;
private final LoadProjectPort loadProjectPort;

private final ProjectApplicationRepository applicationRepository;

private final CheckProjectApplicationPort checkProjectApplicationPort;
private final SaveProjectMeetingPort saveProjectMeetingPort;
private final CheckProjectMeetingPort checkProjectMeetingPort;

Expand Down Expand Up @@ -68,7 +67,7 @@ private void checkMemberIsClientOfProject(final Long memberId, final Long projec
}

private void checkPeopleIsApplicant(final Long applicantId, final Long projectId) {
if (!applicationRepository.existsByApplicantIdAndProjectId(applicantId, projectId)) {
if (!checkProjectApplicationPort.existsByApplicantIdAndProjectId(applicantId, projectId)) {
throw new NotApplicantException();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package es.princip.getp.domain.common.model;

import jakarta.persistence.Embeddable;
import jakarta.persistence.Embedded;
import lombok.*;
import es.princip.getp.domain.BaseModel;
import jakarta.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

@Getter
@ToString
@Embeddable
@EqualsAndHashCode
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class AttachmentFile {
@EqualsAndHashCode(callSuper = false)
public class AttachmentFile extends BaseModel {

@Embedded
private URL url;
@NotNull private final URL url;

public AttachmentFile(final URL url) {
this.url = url;

validate();
}

public static AttachmentFile from(final String url) {
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/es/princip/getp/domain/common/model/Duration.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package es.princip.getp.domain.common.model;

import es.princip.getp.domain.BaseModel;
import es.princip.getp.domain.common.exception.StartDateIsAfterEndDateException;
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.*;
import jakarta.validation.constraints.NotNull;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

import java.time.Clock;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

@Getter
@ToString
@Embeddable
@EqualsAndHashCode
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Duration {
@EqualsAndHashCode(callSuper = false)
public class Duration extends BaseModel {

@Column(name = "application_start_date")
private LocalDate startDate;

@Column(name = "application_end_date")
private LocalDate endDate;
@NotNull private final LocalDate startDate;
@NotNull private final LocalDate endDate;

public Duration(final LocalDate startDate, final LocalDate endDate) {
validate(startDate, endDate);
this.startDate = startDate;
this.endDate = endDate;

validate();
}

private void validate(final LocalDate startDate, final LocalDate endDate) {
@Override
protected void validate() {
super.validate();
if (startDate.isAfter(endDate)) {
throw new StartDateIsAfterEndDateException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static MeetingSchedule of(
}

@Override
public void validate() {
protected void validate() {
super.validate();
if (startTime.isAfter(endTime)) {
throw new StartTimeIsAfterEndTimeException();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,76 +1,50 @@
package es.princip.getp.domain.project.apply.model;

import es.princip.getp.common.domain.BaseTimeEntity;
import es.princip.getp.domain.BaseEntity;
import es.princip.getp.domain.common.model.AttachmentFile;
import es.princip.getp.domain.common.model.Duration;
import jakarta.persistence.*;
import lombok.AccessLevel;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.time.LocalDateTime;
import java.util.List;

@Getter
@Entity
@Table(name = "project_application")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ProjectApplication extends BaseTimeEntity {
public class ProjectApplication extends BaseEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "project_application_id")
@Getter
private Long applicationId;

// 지원자의 피플 ID
@Column(name = "people_id")
private Long applicantId;

// 지원한 프로젝트 ID
@Column(name = "project_id")
private Long projectId;

// 희망 작업 기간
@Embedded
@AttributeOverrides(
{
@AttributeOverride(name = "startDate", column = @Column(name = "expected_start_date")),
@AttributeOverride(name = "endDate", column = @Column(name = "expected_end_date"))
}
)
private Duration expectedDuration;

// 지원 상태
@Enumerated(EnumType.STRING)
@Column(name = "status")
private ProjectApplicationStatus applicationStatus;

// 지원 내용
@Column(name = "description")
private String description;

// 첨부 파일 목록
@ElementCollection
@CollectionTable(name = "project_application_attachment_file", joinColumns = @JoinColumn(name = "project_application_id"))
private List<AttachmentFile> attachmentFiles = new ArrayList<>();
@NotNull private final Long applicantId;
@NotNull private final Long projectId;
@NotNull private Duration expectedDuration;
@NotNull private ProjectApplicationStatus applicationStatus;
@NotBlank private String description;
private final List<@NotNull AttachmentFile> attachmentFiles;

@Builder
public ProjectApplication(
final Long applicationId,
final Long applicantId,
final Long projectId,
final Duration expectedDuration,
final ProjectApplicationStatus applicationStatus,
final String description,
final List<AttachmentFile> attachmentFiles
final List<AttachmentFile> attachmentFiles,
final LocalDateTime createdAt,
final LocalDateTime updatedAt
) {
super(createdAt, updatedAt);

this.applicationId = applicationId;
this.applicantId = applicantId;
this.projectId = projectId;
this.expectedDuration = expectedDuration;
this.applicationStatus = applicationStatus;
this.description = description;
this.attachmentFiles = attachmentFiles;

validate();
}

public void setStatus(final ProjectApplicationStatus applicationStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
import java.util.Map;

import static es.princip.getp.domain.people.command.domain.QPeople.people;
import static es.princip.getp.domain.project.apply.model.QProjectApplication.projectApplication;
import static es.princip.getp.persistence.adapter.project.ProjectPersistenceUtil.toProjectIds;

@Repository
@RequiredArgsConstructor
class FindAppliedProjectAdapter extends QueryDslSupport implements FindAppliedProjectPort {

private static final QProjectApplicationJpaEntity projectApplication
= QProjectApplicationJpaEntity.projectApplicationJpaEntity;
private static final QProjectJpaEntity project = QProjectJpaEntity.projectJpaEntity;

private final FindProjectApplicationAdapter findProjectApplicationAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
import static es.princip.getp.domain.people.command.domain.QPeople.people;
import static es.princip.getp.domain.people.query.dao.PeopleDaoUtil.orderSpecifiersFromSort;
import static es.princip.getp.domain.people.query.dao.PeopleDaoUtil.toPeopleIds;
import static es.princip.getp.domain.project.apply.model.QProjectApplication.projectApplication;
import static java.util.stream.Collectors.toMap;

@Repository
@RequiredArgsConstructor
// TODO: 조회 성능 개선 필요
class FindProjectApplicantAdapter extends QueryDslSupport implements FindProjectApplicantPort {

private static final QProjectApplicationJpaEntity projectApplication
= QProjectApplicationJpaEntity.projectApplicationJpaEntity;
private static final QMemberJpaEntity member = QMemberJpaEntity.memberJpaEntity;

private final PeopleLikeDao peopleLikeDao;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
import java.util.Optional;
import java.util.stream.Collectors;

import static es.princip.getp.domain.project.apply.model.QProjectApplication.projectApplication;

@Repository
@RequiredArgsConstructor
public class FindProjectApplicationAdapter extends QueryDslSupport {

private static final QProjectApplicationJpaEntity projectApplication
= QProjectApplicationJpaEntity.projectApplicationJpaEntity;

public Map<Long, Long> countByProjectIds(final Long... projectId) {
return queryFactory.select(projectApplication.projectId, projectApplication.count())
.from(projectApplication)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package es.princip.getp.persistence.adapter.project.apply;

import es.princip.getp.domain.project.apply.model.ProjectApplicationStatus;
import es.princip.getp.persistence.adapter.BaseTimeJpaEntity;
import es.princip.getp.persistence.adapter.common.DurationJpaVO;
import jakarta.persistence.*;
import lombok.*;

import java.util.ArrayList;
import java.util.List;

@Getter
@Entity
@Builder
@AllArgsConstructor
@Table(name = "project_application")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
class ProjectApplicationJpaEntity extends BaseTimeJpaEntity {

@Id
@Column(name = "project_application_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long applicationId;

@Column(name = "people_id")
private Long applicantId;

@Column(name = "project_id")
private Long projectId;

@Embedded
@AttributeOverrides(
{
@AttributeOverride(name = "startDate", column = @Column(name = "expected_start_date")),
@AttributeOverride(name = "endDate", column = @Column(name = "expected_end_date"))
}
)
private DurationJpaVO expectedDuration;

@Enumerated(EnumType.STRING)
@Column(name = "status")
private ProjectApplicationStatus applicationStatus;

@Column(name = "description")
private String description;

@Builder.Default
@ElementCollection
@CollectionTable(
name = "project_application_attachment_file",
joinColumns = @JoinColumn(name = "project_application_id")
)
private List<String> attachmentFiles = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package es.princip.getp.persistence.adapter.project.apply;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
interface ProjectApplicationJpaRepository extends JpaRepository<ProjectApplicationJpaEntity, Long> {

boolean existsByApplicantIdAndProjectId(Long applicantId, Long projectId);
}
Loading

0 comments on commit 1504f94

Please sign in to comment.