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) {