Skip to content

Commit

Permalink
REFACTOR : Apply 도메인 예외처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yummygyudon committed Nov 25, 2023
1 parent 845c716 commit 4dce402
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.sopt.sopkerton.program.infrastructure.ProgramRepository;
import org.sopt.sopkerton.user.domain.Apply;
import org.sopt.sopkerton.user.domain.enums.ApplyStatus;
import org.sopt.sopkerton.user.domain.exception.apply.ApplyError;
import org.sopt.sopkerton.user.domain.exception.apply.ApplyException;
import org.sopt.sopkerton.user.infrastructure.ApplyRepository;
import org.springframework.stereotype.Service;

Expand All @@ -29,7 +31,7 @@ public class ProgramService {
public List<ProgramListResponse> getProgramListByProgramType(String programType) {
List<Program> programs = programRepository.findAllByProgramType(programType);

List<ProgramListResponse> programListResponses = programs.stream()
return programs.stream()
.map(program -> new ProgramListResponse(
program.getId(),
program.getTitle(),
Expand All @@ -40,13 +42,12 @@ public List<ProgramListResponse> getProgramListByProgramType(String programType)
program.getType()
))
.collect(Collectors.toList());
return programListResponses;
}

public List<ProgramListResponse> getStatusDoneProgramList() {
List<Program> programs = programRepository.findAllByStatus(Status.DONE);

List<ProgramListResponse> programListResponses = programs.stream()
return programs.stream()
.map(program -> new ProgramListResponse(
program.getId(),
program.getTitle(),
Expand All @@ -57,13 +58,13 @@ public List<ProgramListResponse> getStatusDoneProgramList() {
program.getType()
))
.collect(Collectors.toList());
return programListResponses;
}

public Object getProgramDetail(Long userId, Long programId) {
Program program = programRepository.findById(programId)
.orElseThrow(() -> new ProgramException(ProgramError.PROGRAM_NOT_FOUND));
Apply apply = applyRepository.findByUserIdAndProgramId(userId, programId).get();
Apply apply = applyRepository.findByUserIdAndProgramId(userId, programId)
.orElseThrow(() -> new ApplyException(ApplyError.APPLY_NOT_FOUND));
boolean isApply = convertToIsApply(apply.getIsApply());
if (program.getType().equals(VOLUNTEER_TYPE)) {
return new ProgramDetailResponse.VolunteerDetail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.RequiredArgsConstructor;
import org.sopt.sopkerton.common.response.ApiResponse;
import org.sopt.sopkerton.user.domain.exception.UserSuccess;
import org.sopt.sopkerton.user.domain.exception.user.UserSuccess;
import org.sopt.sopkerton.user.dto.response.DetailView;
import org.sopt.sopkerton.user.dto.response.MainView;
import org.sopt.sopkerton.user.service.UserService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.sopt.sopkerton.user.domain.exception.apply;

import lombok.AllArgsConstructor;
import org.sopt.sopkerton.common.exception.base.ErrorBase;
import org.springframework.http.HttpStatus;

@AllArgsConstructor
public enum ApplyError implements ErrorBase {

APPLY_NOT_FOUND(HttpStatus.NOT_FOUND, "Can not found Apply.")
;


private final HttpStatus status;
private final String errorMessage;

@Override
public int getHttpStatusCode() {
return this.status.value();
}

@Override
public HttpStatus getHttpStatus() {
return this.status;
}

@Override
public String getErrorMessage() {
return this.errorMessage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sopt.sopkerton.user.domain.exception.apply;

import org.sopt.sopkerton.common.exception.base.ExceptionBase;

public class ApplyException extends ExceptionBase {
public ApplyException(ApplyError errorBase) {
super(errorBase);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.sopt.sopkerton.user.domain.exception.apply;

import lombok.AllArgsConstructor;
import org.sopt.sopkerton.common.exception.base.SuccessBase;
import org.springframework.http.HttpStatus;

@AllArgsConstructor
public enum ApplySuccess implements SuccessBase {

;

private final HttpStatus status;
private final String successMessage;

@Override
public int getHttpStatusCode() {
return this.status.value();
}

@Override
public HttpStatus getHttpStatus() {
return this.status;
}

@Override
public String getSuccessMessage() {
return this.successMessage;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.sopkerton.user.domain.exception;
package org.sopt.sopkerton.user.domain.exception.user;

import lombok.AllArgsConstructor;
import org.sopt.sopkerton.common.exception.base.ErrorBase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.sopkerton.user.domain.exception;
package org.sopt.sopkerton.user.domain.exception.user;

import org.sopt.sopkerton.common.exception.base.ExceptionBase;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.sopkerton.user.domain.exception;
package org.sopt.sopkerton.user.domain.exception.user;

import lombok.AllArgsConstructor;
import org.sopt.sopkerton.common.exception.base.SuccessBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import lombok.RequiredArgsConstructor;
import org.sopt.sopkerton.user.domain.User;
import org.sopt.sopkerton.user.domain.enums.Gender;
import org.sopt.sopkerton.user.domain.exception.UserError;
import org.sopt.sopkerton.user.domain.exception.UserException;
import org.sopt.sopkerton.user.domain.exception.user.UserError;
import org.sopt.sopkerton.user.domain.exception.user.UserException;
import org.sopt.sopkerton.user.dto.response.DetailView;
import org.sopt.sopkerton.user.dto.response.MainView;
import org.sopt.sopkerton.user.infrastructure.UserRepository;
Expand Down

0 comments on commit 4dce402

Please sign in to comment.