Skip to content

Commit

Permalink
Merge branch 'dev' into feat/#126
Browse files Browse the repository at this point in the history
  • Loading branch information
funnysunny08 committed Nov 8, 2023
2 parents fc6c854 + 7daacc4 commit 95a730d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import com.clova.anifriends.domain.recruitment.Recruitment;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.data.domain.Page;

public record FindRecruitmentsByShelterIdResponse(
PageInfo pageInfo,
List<RecruitmentResponse> recruitments
) {
private record RecruitmentResponse(
String title,
LocalDateTime volunteerDate,
LocalDateTime deadline,
int capacity,
int applicantCount
long recruitmentId,
String recruitmentTitle,
LocalDateTime recruitmentStartTime,
LocalDateTime recruitmentDeadline,
int recruitmentCapacity,
int recruitmentApplicantCount
) {

private static RecruitmentResponse from(Recruitment recruitment){
return new RecruitmentResponse(
recruitment.getRecruitmentId(),
recruitment.getTitle(),
recruitment.getStartTime(),
recruitment.getDeadline(),
Expand All @@ -28,9 +31,9 @@ private static RecruitmentResponse from(Recruitment recruitment){
}
}

public static FindRecruitmentsByShelterIdResponse of(List<Recruitment> recruitments, PageInfo pageInfo) {
public static FindRecruitmentsByShelterIdResponse from(Page<Recruitment> recruitments) {
return new FindRecruitmentsByShelterIdResponse(
pageInfo,
PageInfo.from(recruitments),
recruitments.stream()
.map(RecruitmentResponse::from)
.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,14 @@ public Page<Recruitment> findRecruitmentsByShelterId(long shelterId, Pageable pa
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
return new PageImpl<>(recruitments);

Long count = query.select(recruitment.count())
.from(recruitment)
.where(recruitment.shelter.shelterId.eq(shelterId)
.and(recruitment.info.isClosed.eq(false)))
.fetchOne();

return new PageImpl<>(recruitments, pageable, count == null ? 0 : count);
}

Predicate getDateCondition(LocalDate startDate, LocalDate endDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ public FindRecruitmentsByShelterIdResponse findShelterRecruitmentsByShelter(
Page<Recruitment> pagination = recruitmentRepository.findRecruitmentsByShelterId(
shelterId, pageable
);
return FindRecruitmentsByShelterIdResponse.of(pagination.getContent(),
PageInfo.from(pagination));
return FindRecruitmentsByShelterIdResponse.from(pagination);
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,13 @@ void findRecruitmentsByShelterId() throws Exception {
fieldWithPath("pageInfo.totalElements").type(NUMBER).description("총 게시글 수"),
fieldWithPath("pageInfo.hasNext").type(BOOLEAN).description("다음 페이지 여부"),
fieldWithPath("recruitments[]").type(ARRAY).description("모집 게시글 리스트"),
fieldWithPath("recruitments[].title").type(STRING).description("모집 제목"),
fieldWithPath("recruitments[].volunteerDate").type(STRING)
fieldWithPath("recruitments[].recruitmentId").type(NUMBER).description("모집 ID"),
fieldWithPath("recruitments[].recruitmentTitle").type(STRING).description("모집 제목"),
fieldWithPath("recruitments[].recruitmentStartTime").type(STRING)
.description("봉사 시작 시간"),
fieldWithPath("recruitments[].deadline").type(STRING).description("모집 마감 시간"),
fieldWithPath("recruitments[].capacity").type(NUMBER).description("모집 정원"),
fieldWithPath("recruitments[].applicantCount").type(NUMBER)
fieldWithPath("recruitments[].recruitmentDeadline").type(STRING).description("모집 마감 시간"),
fieldWithPath("recruitments[].recruitmentCapacity").type(NUMBER).description("모집 정원"),
fieldWithPath("recruitments[].recruitmentApplicantCount").type(NUMBER)
.description("현재 지원자 수")
)
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.util.ReflectionTestUtils;

@ExtendWith(MockitoExtension.class)
class RecruitmentServiceTest {
Expand Down Expand Up @@ -213,6 +214,7 @@ void findRecruitmentsByShelterId() {
// given
Shelter shelter = shelter();
Recruitment recruitment = recruitment(shelter);
ReflectionTestUtils.setField(recruitment, "recruitmentId", 4L);
Page<Recruitment> pageResult = new PageImpl<>(List.of(recruitment));
FindRecruitmentsByShelterIdResponse expected = findRecruitmentsByShelterIdResponse(
pageResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static FindRecruitmentsByShelterResponse findRecruitmentsByShelterRespons

public static FindRecruitmentsByShelterIdResponse findRecruitmentsByShelterIdResponse(
Page<Recruitment> pageResult) {
return FindRecruitmentsByShelterIdResponse.of(pageResult.getContent(), PageInfo.from(pageResult));
return FindRecruitmentsByShelterIdResponse.from(pageResult);
}

public static FindRecruitmentDetailResponse findRecruitmentDetailResponse(
Expand Down

0 comments on commit 95a730d

Please sign in to comment.