Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] 선택적 파라미터 디폴트값 설정 #58

Merged
merged 3 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,9 @@ public ResponseEntity<FeedbackResponse> writeFeedback(
@GetMapping("/admin")
public ResponseEntity<PageResponse<FeedbackResponse>> searchFeedbackList(
@PageableDefault(page = 0, size = 10, sort = "createAt", direction = Direction.DESC) Pageable pageable,
@RequestParam(required = false, name = "startDate")
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam(required = false, name = "endDate")
@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate,
@RequestParam(required = false, name = "answerStatus") Long answerStatus) {
@RequestParam(required = false, name = "startDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam(required = false, name = "endDate") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate,
@RequestParam(required = false, name = "answerStatus", defaultValue = "-1") Long answerStatus) {
return ResponseEntity.ok()
.body(feedbackService.searchFeedbackList(pageable, startDate, endDate, answerStatus));
}
Expand All @@ -61,16 +59,17 @@ public ResponseEntity<PageResponse<FeedbackResponse>> searchFeedbackList(
public ResponseEntity<PageResponse<FeedbackResponse>> searchFeedbackList(
@PageableDefault(page = 0, size = 10, sort = "createAt", direction = Direction.DESC) Pageable pageable,
@RequestParam(name = "keyword") String keyword,
@RequestParam(required = false, name = "answerStatus") Long answerStatus) {
@RequestParam(required = false, name = "answerStatus", defaultValue = "-1") Long answerStatus) {
return ResponseEntity.ok()
.body(feedbackService.searchByKeyword(pageable, keyword, answerStatus));
}

@Operation(summary = "피드백 목록 조회")
@GetMapping
public ResponseEntity<PageResponse<FeedbackResponse>> searchFeedbackList(
@PageableDefault(page = 0, size = 10) Pageable pageable) {
return ResponseEntity.ok().body(feedbackService.searchFeedbackList(pageable));
@PageableDefault(page = 0, size = 10) Pageable pageable,
@RequestParam(required = false, name = "answerStatus", defaultValue = "-1") Long answerStatus) {
return ResponseEntity.ok().body(feedbackService.searchFeedbackList(pageable, answerStatus));
}

@Operation(summary = "피드백 상세 조회")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public interface CustomFeedbackRepository {

Page<FeedbackResponse> findAllByActiveMembers(Pageable pageable);
Page<FeedbackResponse> findAllByActiveMembers(Pageable pageable, Long answerStatus);

Page<FeedbackResponse> findPagedByMember(Long memberId, Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ public class CustomFeedbackRepositoryImpl implements CustomFeedbackRepository {
private final JPAQueryFactory jpaQueryFactory;

@Override
public Page<FeedbackResponse> findAllByActiveMembers(Pageable pageable) {
public Page<FeedbackResponse> findAllByActiveMembers(Pageable pageable, Long answerStatus) {
BooleanExpression answerStatusCondition = answerStatusCondition(answerStatus);

List<FeedbackResponse> results = jpaQueryFactory
.select(feedbackResponseDto).from(feedback)
.join(member).on(feedback.member.eq(member)).fetchJoin()
.where(member.memberStatus.eq(MemberStatus.ACTIVITY))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.where(member.memberStatus.eq(MemberStatus.ACTIVITY).and(answerStatusCondition))
.offset(pageable.getOffset()).limit(pageable.getPageSize())
.orderBy(new OrderSpecifier<>(Order.DESC, feedback.createdAt)).fetch();

long count = Optional.ofNullable(
jpaQueryFactory
.select(feedback.count()).from(feedback)
jpaQueryFactory.select(feedback.count()).from(feedback)
.join(member).on(feedback.member.eq(member)).fetchJoin()
.where(member.memberStatus.eq(MemberStatus.ACTIVITY)).fetchOne()
).orElse(0L);
.where(member.memberStatus.eq(MemberStatus.ACTIVITY).and(answerStatusCondition))
.fetchOne()).orElse(0L);

return new PageImpl<>(results, pageable, count);
}
Expand All @@ -81,20 +81,20 @@ public Page<FeedbackResponse> findAll(Pageable pageable,
LocalDate startDate, LocalDate endDate, Long answerStatus) {

BooleanExpression betweenDates = betweenDates(feedback.createdAt, startDate, endDate);
BooleanExpression answerStatusCondition = answerStatusCondition(answerStatus);

List<FeedbackResponse> results = jpaQueryFactory
.select(feedbackResponseDto).from(feedback)
.join(member).on(feedback.member.eq(member)).fetchJoin()
.where(betweenDates.and(answerStatusCondition(answerStatus)))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.offset(pageable.getOffset()).limit(pageable.getPageSize())
.orderBy(getOrderSpecifiers(pageable, feedback.getType(), "feedback")).fetch();

long count = Optional.ofNullable(
jpaQueryFactory
.select(feedback.count()).from(feedback)
.join(member).on(feedback.member.eq(member)).fetchJoin()
.where(betweenDates.and(answerStatusCondition(answerStatus))).fetchOne()
.where(betweenDates.and(answerStatusCondition)).fetchOne()
).orElse(0L);

return new PageImpl<>(results, pageable, count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,23 @@ public class FeedbackService {
private final MemberRepository memberRepository;
private final FeedbackJdbcRepository feedbackJdbcRepository;

public PageResponse<FeedbackResponse> searchFeedbackList(Pageable pageable) {
Page<FeedbackResponse> responsePage = feedbackRepository.findAllByActiveMembers(pageable);
public PageResponse<FeedbackResponse> searchFeedbackList(Pageable pageable, Long answerStatus) {
Page<FeedbackResponse> responsePage = feedbackRepository.findAllByActiveMembers(pageable,
answerStatus);
return new PageResponse<>(responsePage);
}

public PageResponse<FeedbackResponse> searchFeedbackList(Pageable pageable,
LocalDate startDate, LocalDate endDate, Long answerStatus) {
Page<FeedbackResponse> responsePage = feedbackRepository.findAll(pageable, startDate, endDate, answerStatus);
Page<FeedbackResponse> responsePage = feedbackRepository.findAll(pageable, startDate,
endDate, answerStatus);
return new PageResponse<>(responsePage);
}

public PageResponse<FeedbackResponse> searchByKeyword(Pageable pageable, String keyword,
Long answerStatus) {
Page<FeedbackResponse> responsePage = feedbackJdbcRepository.fullTextSearch(pageable, keyword, answerStatus);
Page<FeedbackResponse> responsePage = feedbackJdbcRepository.fullTextSearch(pageable,
keyword, answerStatus);
return new PageResponse<>(responsePage);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ void setup() {
void findAllByActiveMembers() {
// when
Pageable pageable = PageRequest.of(3, 10);
Page<FeedbackResponse> actual = feedbackRepository.findAllByActiveMembers(pageable);
Long answerStatus = -1L; // 모든 피드백 보기
Page<FeedbackResponse> actual = feedbackRepository.findAllByActiveMembers(pageable, answerStatus);

// then
SoftAssertions.assertSoftly(softAssertions -> {
Expand Down
Loading