Skip to content

Commit

Permalink
refactor: 명세에 맞게 수정한다. (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
funnysunny08 authored Nov 9, 2023
1 parent 00012d8 commit c3530fd
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.clova.anifriends.domain.recruitment.Recruitment;
import java.time.LocalDateTime;
import java.util.List;
import org.springframework.data.domain.Page;

public record FindRecruitmentsByShelterResponse(
PageInfo pageInfo,
Expand All @@ -12,13 +13,13 @@ public record FindRecruitmentsByShelterResponse(
) {
private record RecruitmentResponse(
long recruitmentId,
String title,
LocalDateTime startTime,
LocalDateTime endTime,
LocalDateTime deadline,
boolean isClosed,
int applicantCount,
int capacity
String recruitmentTitle,
LocalDateTime recruitmentStartTime,
LocalDateTime recruitmentEndTime,
LocalDateTime recruitmentDeadline,
boolean recruitmentIsClosed,
int recruitmentApplicantCount,
int recruitmentCapacity
) {
private static RecruitmentResponse from(Recruitment recruitment){
return new RecruitmentResponse(
Expand All @@ -34,9 +35,9 @@ private static RecruitmentResponse from(Recruitment recruitment){
}
}

public static FindRecruitmentsByShelterResponse of(List<Recruitment> recruitments, PageInfo pageInfo){
public static FindRecruitmentsByShelterResponse from(Page<Recruitment> recruitments){
return new FindRecruitmentsByShelterResponse(
pageInfo,
PageInfo.from(recruitments),
recruitments.stream()
.map(RecruitmentResponse::from)
.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ public Page<Recruitment> findRecruitmentsByShelterOrderByCreatedAt(long shelterI
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
return new PageImpl<>(recruitments);

Long count = query.select(recruitment.count())
.from(recruitment)
.where(predicate)
.fetchOne();

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

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.clova.anifriends.domain.recruitment.service;

import com.clova.anifriends.domain.common.dto.PageInfo;
import com.clova.anifriends.domain.recruitment.Recruitment;
import com.clova.anifriends.domain.recruitment.dto.response.FindCompletedRecruitmentsResponse;
import com.clova.anifriends.domain.recruitment.dto.response.FindRecruitmentDetailResponse;
Expand Down Expand Up @@ -73,8 +72,7 @@ public FindRecruitmentsByShelterResponse findRecruitmentsByShelter(
pageable
);

return FindRecruitmentsByShelterResponse.of(pagination.getContent(),
PageInfo.from(pagination));
return FindRecruitmentsByShelterResponse.from(pagination);
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,14 @@ void findRecruitmentsByShelter() throws Exception {
fieldWithPath("pageInfo.hasNext").type(BOOLEAN).description("다음 페이지 여부"),
fieldWithPath("recruitments[]").type(ARRAY).description("모집 게시글 리스트"),
fieldWithPath("recruitments[].recruitmentId").type(NUMBER).description("모집 ID"),
fieldWithPath("recruitments[].title").type(STRING).description("모집 제목"),
fieldWithPath("recruitments[].startTime").type(STRING).description("봉사 시작 시간"),
fieldWithPath("recruitments[].endTime").type(STRING).description("봉사 끝난 시간"),
fieldWithPath("recruitments[].deadline").type(STRING).description("모집 마감 시간"),
fieldWithPath("recruitments[].isClosed").type(BOOLEAN).description("모집 마감 여부"),
fieldWithPath("recruitments[].applicantCount").type(NUMBER)
fieldWithPath("recruitments[].recruitmentTitle").type(STRING).description("모집 제목"),
fieldWithPath("recruitments[].recruitmentStartTime").type(STRING).description("봉사 시작 시간"),
fieldWithPath("recruitments[].recruitmentEndTime").type(STRING).description("봉사 끝난 시간"),
fieldWithPath("recruitments[].recruitmentDeadline").type(STRING).description("모집 마감 시간"),
fieldWithPath("recruitments[].recruitmentIsClosed").type(BOOLEAN).description("모집 마감 여부"),
fieldWithPath("recruitments[].recruitmentApplicantCount").type(NUMBER)
.description("현재 지원자 수"),
fieldWithPath("recruitments[].capacity").type(NUMBER).description("모집 정원")
fieldWithPath("recruitments[].recruitmentCapacity").type(NUMBER).description("모집 정원")
)
));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.clova.anifriends.domain.recruitment.support.fixture;

import com.clova.anifriends.domain.common.dto.PageInfo;
import com.clova.anifriends.domain.recruitment.Recruitment;
import com.clova.anifriends.domain.recruitment.dto.response.FindRecruitmentDetailResponse;
import com.clova.anifriends.domain.recruitment.dto.response.FindRecruitmentsByShelterIdResponse;
Expand All @@ -11,7 +10,7 @@ public class RecruitmentDtoFixture {

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

public static FindRecruitmentsByShelterIdResponse findRecruitmentsByShelterIdResponse(
Expand Down

0 comments on commit c3530fd

Please sign in to comment.