From c530876eebfe2a083451d31e851dea833c1712fa Mon Sep 17 00:00:00 2001 From: yummygyudon Date: Sun, 26 Nov 2023 07:30:53 +0900 Subject: [PATCH] =?UTF-8?q?HOT=20FIX=20:=20=ED=81=B4=EB=9D=BC=EC=9D=B4?= =?UTF-8?q?=EC=96=B8=ED=8A=B8=20=EC=9A=94=EA=B5=AC=EC=82=AC=ED=95=AD=20?= =?UTF-8?q?=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../program/controller/ProgramController.java | 5 +- .../dto/response/ProgramDetailResponse.java | 54 +++++++------------ .../program/service/ProgramService.java | 37 ++++--------- 3 files changed, 32 insertions(+), 64 deletions(-) diff --git a/src/main/java/org/sopt/sopkerton/program/controller/ProgramController.java b/src/main/java/org/sopt/sopkerton/program/controller/ProgramController.java index df19511..dbd1c03 100644 --- a/src/main/java/org/sopt/sopkerton/program/controller/ProgramController.java +++ b/src/main/java/org/sopt/sopkerton/program/controller/ProgramController.java @@ -4,6 +4,7 @@ import lombok.RequiredArgsConstructor; import org.sopt.sopkerton.program.domain.exception.ProgramSuccess; import org.sopt.sopkerton.common.response.ApiResponse; +import org.sopt.sopkerton.program.dto.response.ProgramDetailResponse; import org.sopt.sopkerton.program.dto.response.ProgramListResponse; import org.sopt.sopkerton.program.service.ProgramService; import org.springframework.http.ResponseEntity; @@ -39,10 +40,10 @@ public ResponseEntity>> programListViewByS } @GetMapping("/detail") - public ResponseEntity orderProgramDetail( + public ResponseEntity> orderProgramDetail( @RequestParam("programId") Long programId ) { - Object programDetail = programService.getProgramDetail(1L, programId); + ProgramDetailResponse programDetail = programService.getProgramDetail(1L, programId); return ResponseEntity .status(ProgramSuccess.PROGRAM_DETAIL_VIEW_SUCCESS.getHttpStatus()) .body( diff --git a/src/main/java/org/sopt/sopkerton/program/dto/response/ProgramDetailResponse.java b/src/main/java/org/sopt/sopkerton/program/dto/response/ProgramDetailResponse.java index 941ecb4..1a414c5 100644 --- a/src/main/java/org/sopt/sopkerton/program/dto/response/ProgramDetailResponse.java +++ b/src/main/java/org/sopt/sopkerton/program/dto/response/ProgramDetailResponse.java @@ -2,41 +2,23 @@ import com.fasterxml.jackson.annotation.JsonProperty; -public abstract class ProgramDetailResponse { +public record ProgramDetailResponse ( + @JsonProperty("imageUrl") + String imageUrl, + @JsonProperty("content") + String content, + @JsonProperty("organizationName") + String organizationName, + @JsonProperty("registerAt") + String registerAt, + @JsonProperty("hour") + int hour, + @JsonProperty("salary") + int salary, + @JsonProperty("isApply") + boolean isApply, + @JsonProperty("programType") + String type +){ - public record VolunteerDetail( - @JsonProperty("imageUrl") - String imageUrl, - @JsonProperty("content") - String content, - @JsonProperty("organizationName") - String organizationName, - @JsonProperty("registerAt") - String registerAt, - @JsonProperty("hour") - int hour, - @JsonProperty("isApply") - boolean isApply, - @JsonProperty("programType") - String type - ) { - } - - public record EmploymentDetail( - @JsonProperty("imageUrl") - String imageUrl, - @JsonProperty("content") - String content, - @JsonProperty("organizationName") - String organizationName, - @JsonProperty("registerAt") - String registerAt, - @JsonProperty("salary") - int salary, - @JsonProperty("isApply") - boolean isApply, - @JsonProperty("programType") - String type - ) { - } } diff --git a/src/main/java/org/sopt/sopkerton/program/service/ProgramService.java b/src/main/java/org/sopt/sopkerton/program/service/ProgramService.java index e1007e2..e0748cf 100644 --- a/src/main/java/org/sopt/sopkerton/program/service/ProgramService.java +++ b/src/main/java/org/sopt/sopkerton/program/service/ProgramService.java @@ -22,8 +22,6 @@ @Service @RequiredArgsConstructor public class ProgramService { - private static final String VOLUNTEER_TYPE = "VOLUNTEERING"; - private static final String EMPLOYMENT_TYPE = "EMPLOYMENT"; private final ProgramRepository programRepository; private final ApplyRepository applyRepository; @@ -60,35 +58,22 @@ public List getStatusDoneProgramList() { .collect(Collectors.toList()); } - public Object getProgramDetail(Long userId, Long programId) { + public ProgramDetailResponse getProgramDetail(Long userId, Long programId) { Program program = programRepository.findById(programId) .orElseThrow(() -> new ProgramException(ProgramError.PROGRAM_NOT_FOUND)); 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( - program.getImageUrl(), - program.getContent(), - program.getOrganizationName(), - formatToLocalDate(program.getRegisterAt()), - program.getVolunteerHours(), - isApply, - program.getType() - ); - } - if (program.getType().equals(EMPLOYMENT_TYPE)){ - return new ProgramDetailResponse.EmploymentDetail( - program.getImageUrl(), - program.getContent(), - program.getOrganizationName(), - formatToLocalDate(program.getRegisterAt()), - program.getSalary(), - isApply, - program.getType() - ); - } - return null; + return new ProgramDetailResponse( + program.getImageUrl(), + program.getContent(), + program.getOrganizationName(), + formatToLocalDate(program.getRegisterAt()), + program.getVolunteerHours(), + program.getSalary(), + isApply, + program.getType() + ); } private String formatToLocalDate(LocalDateTime localDateTime) {