Skip to content

Commit

Permalink
๐Ÿ› [Fix] ๊ณต๊ณ  ์ „์ฒด ์กฐํšŒ API์˜ ์ž˜๋ชป๋œ ์‘๋‹ต ์ˆ˜์ • (#817)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimhan-nah authored Apr 8, 2024
1 parent d4e5e32 commit ccbaae4
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
public interface RecruitmentAdminRepository extends JpaRepository<Recruitment, Long> {
Page<Recruitment> findAllByOrderByEndTimeDesc(Pageable pageable);

Page<Recruitment> findAllByIsDeletedOrderByEndTimeDesc(boolean isDeleted, Pageable pageable);

@Query("SELECT r FROM Recruitment r WHERE r.id = :recruitId AND r.isDeleted = false")
Optional<Recruitment> findNotDeletedRecruit(Long recruitId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public void setFinish(Boolean finish) {
this.isFinish = finish;
}

public boolean getIsFinsh() {
return this.isFinish;
}

/**
* Question์—์„œ ํ˜ธ์ถœํ•˜๋Š” ์—ฐ๊ด€๊ด€๊ณ„ ํŽธ์˜ ๋ฉ”์„œ๋“œ, ๊ธฐํƒ€ ํ˜ธ์ถœ ๊ธˆ์ง€
* @param question
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public ResponseEntity<Void> updateRecruitStatus(@PathVariable @Positive Long rec
}

@GetMapping
public ResponseEntity<RecruitmentsResponse> getRecruitments(PageRequestDto pageRequestDto) {
public ResponseEntity<RecruitmentsResponse> getRecruitments(@Valid PageRequestDto pageRequestDto) {
Pageable pageable = PageRequest.of(pageRequestDto.getPage() - 1, pageRequestDto.getSize());
AllRecruitmentsResult allRecruitments = recruitmentAdminService.getAllRecruitments(pageable);
return ResponseEntity.ok(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@
import java.time.LocalDateTime;

import gg.data.recruit.recruitment.Recruitment;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class RecruitmentDto {
private Long id;
private String title;
private String status;
private Boolean isFinish;
private String generation;
private LocalDateTime startDate;
private LocalDateTime endDate;

@Builder
public RecruitmentDto(Long id, String title, String status, String generation, LocalDateTime startDate,
public RecruitmentDto(Long id, String title, Boolean isFinish, String generation, LocalDateTime startDate,
LocalDateTime endDate) {
this.id = id;
this.title = title;
this.status = status;
this.isFinish = isFinish;
this.generation = generation;
this.startDate = startDate;
this.endDate = endDate;
Expand All @@ -32,6 +33,7 @@ public static RecruitmentDto toRecruitmentDto(Recruitment recruitment) {
return RecruitmentDto.builder()
.id(recruitment.getId())
.title(recruitment.getTitle())
.isFinish(recruitment.getIsFinsh())
.generation(recruitment.getGeneration())
.startDate(recruitment.getStartTime())
.endDate(recruitment.getEndTime())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public class RecruitmentsResponse {
private List<RecruitmentDto> recruitments = new ArrayList<>();
private int totalPage;

public RecruitmentsResponse(List<Recruitment> recruitments, int totalPage) {
for (Recruitment recruitment : recruitments) {
public RecruitmentsResponse(List<Recruitment> recruitmentList, int totalPage) {
for (Recruitment recruitment : recruitmentList) {
this.recruitments.add(RecruitmentDto.toRecruitmentDto(recruitment));
}
this.totalPage = totalPage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public void updateRecruitStatus(UpdateRecruitStatusParam updateRecruitStatusPara
*/
@Transactional(readOnly = true)
public AllRecruitmentsResult getAllRecruitments(Pageable pageable) {
Page<Recruitment> allByOrderByEndDateDesc = recruitmentAdminRepository.findAllByOrderByEndTimeDesc(pageable);
Page<Recruitment> allByOrderByEndDateDesc = recruitmentAdminRepository.findAllByIsDeletedOrderByEndTimeDesc(
false, pageable);
return new AllRecruitmentsResult(allByOrderByEndDateDesc.getTotalPages(), allByOrderByEndDateDesc.getContent());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gg.recruit.api.user.controller;

import javax.validation.Valid;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -25,7 +27,7 @@ public class RecruitmentController {
private final ApplicationService applicationService;

@GetMapping
public ActiveRecruitmentListResDto findActiveRecruitmentList(PageRequestDto requestDto) {
public ActiveRecruitmentListResDto findActiveRecruitmentList(@Valid PageRequestDto requestDto) {
Pageable pageable = PageRequest.of(requestDto.getPage() - 1, requestDto.getSize());
return new ActiveRecruitmentListResDto(recruitmentService.findActiveRecruitmentList(pageable));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ void getAllRecruitments() {
// given
Page<Recruitment> mock = mock(Page.class);
Pageable mockPageable = mock(Pageable.class);
given(recruitmentAdminRepository.findAllByOrderByEndTimeDesc(mockPageable)).willReturn(mock);
given(recruitmentAdminRepository.findAllByIsDeletedOrderByEndTimeDesc(false, mockPageable)).willReturn(mock);

// when
recruitmentAdminService.getAllRecruitments(mockPageable);

// then
verify(recruitmentAdminRepository, times(1)).findAllByOrderByEndTimeDesc(mockPageable);
verify(recruitmentAdminRepository, times(1)).findAllByIsDeletedOrderByEndTimeDesc(false, mockPageable);
}

@Nested
Expand Down

0 comments on commit ccbaae4

Please sign in to comment.