Skip to content

Commit

Permalink
refactor: 프로젝트 도메인의 사용자에게 반환할 에러 메시지에 대한 책임을 사용자 정의 예외로 이동 (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
scv1702 committed Aug 2, 2024
1 parent 500ddaf commit 3025939
Show file tree
Hide file tree
Showing 31 changed files with 170 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import es.princip.getp.infra.exception.BusinessLogicException;
import es.princip.getp.infra.exception.ErrorDescription;
import org.springframework.http.HttpStatus;

public class AlreadyExistsPeopleException extends BusinessLogicException {

private static final HttpStatus status = HttpStatus.CONFLICT;
private static final String code = "ALREADY_EXISTS_PEOPLE";
private static final String message = "이미 피플 정보를 등록했습니다.";

public AlreadyExistsPeopleException() {
super(status, ErrorDescription.of(code, message));
super(ErrorDescription.of(code, message));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import es.princip.getp.infra.exception.BusinessLogicException;
import es.princip.getp.infra.exception.ErrorDescription;
import org.springframework.http.HttpStatus;

public class AlreadyExistsPeopleProfileException extends BusinessLogicException {

private static final HttpStatus status = HttpStatus.CONFLICT;
private static final String code = "ALREADY_EXISTS_PEOPLE_PROFILE";
private static final String message = "이미 피플 프로필을 등록했습니다.";

public AlreadyExistsPeopleProfileException() {
super(status, ErrorDescription.of(code, message));
super(ErrorDescription.of(code, message));
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package es.princip.getp.domain.people.exception;

import es.princip.getp.infra.exception.BusinessLogicException;
import es.princip.getp.infra.exception.ErrorDescription;
import org.springframework.http.HttpStatus;
import es.princip.getp.infra.exception.NotFoundException;

public class NotFoundPeopleException extends BusinessLogicException {
public class NotFoundPeopleException extends NotFoundException {

private static final HttpStatus status = HttpStatus.NOT_FOUND;
private static final String code = "NOT_FOUND_PEOPLE";
private static final String message = "존재하지 않는 피플입니다.";

public NotFoundPeopleException() {
super(status, ErrorDescription.of(code, message));
super(ErrorDescription.of(code, message));
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package es.princip.getp.domain.people.exception;

import es.princip.getp.infra.exception.BusinessLogicException;
import es.princip.getp.infra.exception.ErrorDescription;
import org.springframework.http.HttpStatus;
import es.princip.getp.infra.exception.NotFoundException;

public class NotFoundPeopleProfileException extends BusinessLogicException {
public class NotFoundPeopleProfileException extends NotFoundException {

private static final HttpStatus status = HttpStatus.NOT_FOUND;
private static final String code = "NOT_FOUND_PEOPLE_PROFILE";
private static final String message = "존재하지 않는 피플 프로필입니다.";

public NotFoundPeopleProfileException() {
super(status, ErrorDescription.of(code, message));
super(ErrorDescription.of(code, message));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import es.princip.getp.infra.exception.BusinessLogicException;
import es.princip.getp.infra.exception.ErrorDescription;
import org.springframework.http.HttpStatus;

public class NotRegisteredPeopleProfileException extends BusinessLogicException {

private static final HttpStatus status = HttpStatus.CONFLICT;
private static final String code = "NOT_REGISTERED_PEOPLE_PROFILE";
private static final String message = "프로젝트에 지원하려면 피플 프로필을 등록해야 합니다.";

public NotRegisteredPeopleProfileException() {
super(status, ErrorDescription.of(code, message));
super(ErrorDescription.of(code, message));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

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.command.application.command.ApplyProjectCommand;
import es.princip.getp.domain.project.command.domain.*;
import jakarta.persistence.EntityNotFoundException;
import es.princip.getp.domain.project.exception.NotFoundProjectException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -28,9 +29,9 @@ public class ProjectApplicationService {
@Transactional
public Long applyForProject(final ApplyProjectCommand command) {
final People people = peopleRepository.findByMemberId(command.memberId())
.orElseThrow(() -> new EntityNotFoundException("해당 피플이 존재하지 않습니다."));
.orElseThrow(NotFoundPeopleException::new);
final Project project = projectRepository.findById(command.projectId())
.orElseThrow(() -> new EntityNotFoundException("해당 프로젝트가 존재하지 않습니다."));
.orElseThrow(NotFoundProjectException::new);
final ProjectApplication application = projectApplier.applyForProject(
people,
project,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

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.command.domain.*;
import jakarta.persistence.EntityNotFoundException;
import es.princip.getp.domain.project.exception.NotFoundProjectException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -29,9 +30,9 @@ public class ProjectLikeService {
@Transactional
public void like(final Long memberId, final Long projectId) {
final People people = peopleRepository.findById(memberId)
.orElseThrow(() -> new EntityNotFoundException("해당 피플을 찾을 수 없습니다."));
.orElseThrow(NotFoundPeopleException::new);
final Project project = projectRepository.findById(projectId)
.orElseThrow(() -> new EntityNotFoundException("해당 프로젝트를 찾을 수 없습니다."));
.orElseThrow(NotFoundProjectException::new);

final ProjectLike like = projectLiker.like(people, project);

Expand All @@ -47,9 +48,9 @@ public void like(final Long memberId, final Long projectId) {
@Transactional
public void unlike(final Long memberId, final Long projectId) {
final People people = peopleRepository.findById(memberId)
.orElseThrow(() -> new EntityNotFoundException("해당 피플을 찾을 수 없습니다."));
.orElseThrow(NotFoundPeopleException::new);
final Project project = projectRepository.findById(projectId)
.orElseThrow(() -> new EntityNotFoundException("해당 프로젝트를 찾을 수 없습니다."));
.orElseThrow(NotFoundProjectException::new);

projectUnliker.unlike(people, project);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import es.princip.getp.domain.common.domain.Duration;
import es.princip.getp.domain.people.command.domain.People;
import es.princip.getp.domain.people.command.domain.PeopleProfileChecker;
import es.princip.getp.domain.project.exception.ProjectApplicationClosedException;
import es.princip.getp.domain.project.exception.ClosedProjectApplicationException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -39,7 +39,7 @@ public ProjectApplication applyForProject(
) {
final Clock clock = clockHolder.getClock();
if (project.isApplicationClosed(clock)) {
throw new ProjectApplicationClosedException();
throw new ClosedProjectApplicationException();
}
peopleProfileChecker.checkPeopleProfileIsRegistered(people);
return ProjectApplication.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import es.princip.getp.domain.common.domain.ClockHolder;
import es.princip.getp.domain.common.domain.Duration;
import es.princip.getp.domain.project.exception.ApplicationDurationIsEndedException;
import es.princip.getp.domain.project.exception.ApplicationDurationIsNotBeforeEstimatedDurationException;
import es.princip.getp.domain.project.exception.ApplicationDurationNotBeforeEstimatedDurationException;
import es.princip.getp.domain.project.exception.EndedApplicationDurationException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

Expand All @@ -21,10 +21,10 @@ public Project commissionProject(final ProjectData data) {
final Duration estimatedDuration = data.estimatedDuration();

if (applicationDuration.isEnded(clock)) {
throw new ApplicationDurationIsEndedException();
throw new EndedApplicationDurationException();
}
if (!applicationDuration.isBefore(estimatedDuration)) {
throw new ApplicationDurationIsNotBeforeEstimatedDurationException();
throw new ApplicationDurationNotBeforeEstimatedDurationException();
}

final ProjectStatus status = ProjectStatus.determineStatus(applicationDuration, clock);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package es.princip.getp.domain.project.command.domain;

import es.princip.getp.domain.people.command.domain.People;
import es.princip.getp.domain.project.exception.ProjectAlreadyLikedException;
import es.princip.getp.domain.project.exception.AlreadyLikedProjectException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

Expand All @@ -13,7 +13,7 @@ public class ProjectLiker {

private void checkProjectAlreadyLiked(final Long peopleId, final Long projectId) {
if (projectLikeRepository.existsByPeopleIdAndProjectId(peopleId, projectId)) {
throw new ProjectAlreadyLikedException();
throw new AlreadyLikedProjectException();
}
}

Expand All @@ -23,7 +23,7 @@ private void checkProjectAlreadyLiked(final Long peopleId, final Long projectId)
* @param people 좋아요를 누르는 피플
* @param project 좋아요를 누를 프로젝트
* @return 좋아요 이력
* @throws ProjectAlreadyLikedException 이미 해당 프로젝트에 좋아요를 눌렀던 경우
* @throws AlreadyLikedProjectException 이미 해당 프로젝트에 좋아요를 눌렀던 경우
*/
public ProjectLike like(final People people, final Project project) {
final Long peopleId = people.getPeopleId();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package es.princip.getp.domain.project.command.domain;

import es.princip.getp.domain.people.command.domain.People;
import es.princip.getp.domain.project.exception.ProjectNeverLikedException;
import es.princip.getp.domain.project.exception.NeverLikedProjectException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

Expand All @@ -13,7 +13,7 @@ public class ProjectUnliker {

private void checkProjectNeverLiked(final Long peopleId, final Long projectId) {
if (!projectLikeRepository.existsByPeopleIdAndProjectId(peopleId, projectId)) {
throw new ProjectNeverLikedException();
throw new NeverLikedProjectException();
}
}

Expand All @@ -22,7 +22,7 @@ private void checkProjectNeverLiked(final Long peopleId, final Long projectId) {
*
* @param people 좋아요를 취소하는 피플
* @param project 좋아요를 취소할 프로젝트
* @throws ProjectNeverLikedException 프로젝트에 좋아요를 누른 적이 없는 경우
* @throws NeverLikedProjectException 프로젝트에 좋아요를 누른 적이 없는 경우
*/
public void unlike(final People people, final Project project) {
final Long peopleId = people.getPeopleId();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package es.princip.getp.domain.project.exception;

import es.princip.getp.infra.exception.BusinessLogicException;
import es.princip.getp.infra.exception.ErrorDescription;

public class AlreadyLikedProjectException extends BusinessLogicException {

private static final String code = "ALREADY_LIKED_PROJECT";
private static final String message = "이미 좋아요를 누른 프로젝트입니다.";

public AlreadyLikedProjectException() {
super(ErrorDescription.of(code, message));
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package es.princip.getp.domain.project.exception;

import es.princip.getp.infra.exception.BusinessLogicException;
import es.princip.getp.infra.exception.ErrorDescription;

public class ApplicationDurationNotBeforeEstimatedDurationException extends BusinessLogicException {

private static final String code = "APPLICATION_DURATION_NOT_BEFORE_ESTIMATED_DURATION";
private static final String message = "지원자 모집 기간은 예상 작업 기간보다 이전이어야 합니다.";

public ApplicationDurationNotBeforeEstimatedDurationException() {
super(ErrorDescription.of(code, message));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package es.princip.getp.domain.project.exception;

import es.princip.getp.infra.exception.BusinessLogicException;
import es.princip.getp.infra.exception.ErrorDescription;

public class ClosedProjectApplicationException extends BusinessLogicException {

private static final String code = "CLOSED_PROJECT_APPLICATION";
private static final String message = "해당 프로젝트의 지원자 모집이 닫혔습니다.";

public ClosedProjectApplicationException() {
super(ErrorDescription.of(code, message));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package es.princip.getp.domain.project.exception;

import es.princip.getp.infra.exception.BusinessLogicException;
import es.princip.getp.infra.exception.ErrorDescription;

public class EndedApplicationDurationException extends BusinessLogicException {

private static final String code = "ENDED_APPLICATION_DURATION";
private static final String message = "지원자 모집 기간은 금일부터거나 이후여야 합니다.";

public EndedApplicationDurationException() {
super(ErrorDescription.of(code, message));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package es.princip.getp.domain.project.exception;

import es.princip.getp.infra.exception.BusinessLogicException;
import es.princip.getp.infra.exception.ErrorDescription;

public class NeverLikedProjectException extends BusinessLogicException {

private static final String code = "NEVER_LIKED_PROJECT";
private static final String message = "좋아요를 누르지 않은 프로젝트입니다.";

public NeverLikedProjectException() {
super(ErrorDescription.of(code, message));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package es.princip.getp.domain.project.exception;

import es.princip.getp.infra.exception.ErrorDescription;
import es.princip.getp.infra.exception.NotFoundException;

public class NotFoundProjectException extends NotFoundException {

private static final String code = "NOT_FOUND_PROJECT";
private static final String message = "존재하지 않는 프로젝트입니다.";

public NotFoundProjectException() {
super(ErrorDescription.of(code, message));
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 3025939

Please sign in to comment.