Skip to content

Commit

Permalink
Feat: 일정 기간이 남은 지원 현황을 조회하여 반환하는 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yunhacandy authored Aug 22, 2024
2 parents 17c6ebc + 3d5e6af commit bcc4290
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cotato.growingpain.log.domain.entity.JobPost;
import cotato.growingpain.log.dto.request.JobPostRequestDTO;
import cotato.growingpain.log.dto.request.JobPostRetrieveDTO;
import cotato.growingpain.log.dto.response.JobApplicationListResponse;
import cotato.growingpain.log.dto.retrieve.JobPostListRetrieveDTO;
import cotato.growingpain.log.service.JobService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -89,4 +90,13 @@ public Response<JobPost> updateJobPost(
return Response.createSuccess("지원 현황 삭제 완료", null);
}

@Operation(summary = "일정 기간이 남은 지원 현황 조회", description = "일정 기간이 남은 지원 현황을 조회하여 반환하는 메소드")
@ApiResponse(content = @Content(schema = @Schema(implementation = JobApplicationListResponse.class)))
@GetMapping("/days-left/{days}")
@ResponseStatus(HttpStatus.OK)
public Response<JobApplicationListResponse> getJobApplicationsByDaysLeft( @AuthenticationPrincipal Long memberId,
@PathVariable int days) {
JobApplicationListResponse jobApplications = jobService.getJobApplicationsByDaysLeft(memberId, days);
return Response.createSuccess(days + "일 남은 지원 현황 조회 완료", jobApplications);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package cotato.growingpain.log.dto.response;

import java.util.List;

public record JobApplicationListResponse(
List<JobApplicationResponse> jobApplicaionList
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cotato.growingpain.log.dto.response;

import cotato.growingpain.log.domain.entity.JobApplication;

public record JobApplicationResponse(

Long jobPostId,
Long jobApplicationId,
String companyName,
String applicationType,
String applicationCloseDate
) {
public JobApplicationResponse(JobApplication jobApplication) {
this(
jobApplication.getJobPost().getId(),
jobApplication.getId(),
jobApplication.getJobPost().getCompanyName(),
jobApplication.getApplicationType().name(),
jobApplication.getApplicationCloseDate()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@

public interface JobApplicationRepository extends JpaRepository<JobApplication, Long> {
List<JobApplication> findByJobPostId(Long jobPostId);
List<JobApplication> findByMemberIdAndApplicationCloseDate(Long memberId, String applicationCloseDate);
}
18 changes: 18 additions & 0 deletions src/main/java/cotato/growingpain/log/service/JobService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
import cotato.growingpain.log.domain.entity.JobPost;
import cotato.growingpain.log.dto.request.JobPostRequestDTO;
import cotato.growingpain.log.dto.request.JobPostRetrieveDTO;
import cotato.growingpain.log.dto.response.JobApplicationListResponse;
import cotato.growingpain.log.dto.response.JobApplicationResponse;
import cotato.growingpain.log.dto.retrieve.JobPostListRetrieveDTO;
import cotato.growingpain.log.repository.ApplicationDetailRepository;
import cotato.growingpain.log.repository.JobApplicationRepository;
import cotato.growingpain.log.repository.JobPostRepository;
import cotato.growingpain.member.domain.entity.Member;
import cotato.growingpain.member.repository.MemberRepository;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -88,4 +92,18 @@ public void deleteJobPost(Long jobPostId, Long memberId) {
jobPostRepository.delete(jobPost);
}

public JobApplicationListResponse getJobApplicationsByDaysLeft(Long memberId, int daysLeft) {
// 현재 날짜에서 daysLeft를 더한 날짜 계산
LocalDate targetDate = LocalDate.now().plusDays(daysLeft);
String formattedDate = targetDate.format(DateTimeFormatter.ISO_DATE);

// 해당 날짜에 해당하는 JobApplication을 조회
List<JobApplicationResponse> applications = jobApplicationRepository.findByMemberIdAndApplicationCloseDate(memberId, formattedDate)
.stream()
.map(JobApplicationResponse::new) // 매핑 로직 간소화
.collect(Collectors.toList());

// JobApplicationListResponse로 반환
return new JobApplicationListResponse(applications);
}
}

0 comments on commit bcc4290

Please sign in to comment.