diff --git a/src/main/java/org/sopt/sopkerton/program/infrastructure/ProgramRepository.java b/src/main/java/org/sopt/sopkerton/program/infrastructure/ProgramRepository.java index 158051d..686b782 100644 --- a/src/main/java/org/sopt/sopkerton/program/infrastructure/ProgramRepository.java +++ b/src/main/java/org/sopt/sopkerton/program/infrastructure/ProgramRepository.java @@ -1,6 +1,7 @@ package org.sopt.sopkerton.program.infrastructure; import java.util.List; + import org.sopt.sopkerton.program.domain.Program; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -10,4 +11,5 @@ public interface ProgramRepository extends JpaRepository { @Query("select p from Program p where p.type = :type order by p.registerAt") List findAllByProgramType(@Param("type")String programType); + } 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 9aca4db..caa8769 100644 --- a/src/main/java/org/sopt/sopkerton/program/service/ProgramService.java +++ b/src/main/java/org/sopt/sopkerton/program/service/ProgramService.java @@ -6,14 +6,24 @@ import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.sopt.sopkerton.program.domain.Program; +import org.sopt.sopkerton.program.domain.exception.ProgramError; +import org.sopt.sopkerton.program.domain.exception.ProgramException; +import org.sopt.sopkerton.program.dto.response.ProgramDetailResponse; import org.sopt.sopkerton.program.dto.response.ProgramListResponse; 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.infrastructure.ApplyRepository; import org.springframework.stereotype.Service; @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; public List getProgramListByProgramType(String programType) { List programs = programRepository.findAllByProgramType(programType); @@ -31,10 +41,40 @@ public List getProgramListByProgramType(String programType) 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(); + 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 + ); + } + if (program.getType().equals(EMPLOYMENT_TYPE)){ + return new ProgramDetailResponse.EmploymentDetail( + program.getImageUrl(), + program.getContent(), + program.getOrganizationName(), + formatToLocalDate(program.getRegisterAt()), + program.getSalary(), + isApply + ); + } + return null; + } + private String formatToLocalDate(LocalDateTime localDateTime) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM월 dd일"); return localDateTime.format(formatter); } - + private boolean convertToIsApply(ApplyStatus status) { + return status.equals(ApplyStatus.APPLY); + } }