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

refactor : SliceParam 제거 #281

Merged
merged 3 commits into from
Feb 3, 2023
Merged

Conversation

gengminy
Copy link
Member

@gengminy gengminy commented Feb 2, 2023

개요

작업사항

  • SliceParam 을 Pageable 로 대체했습니다 (Deprecated)
  • Host 와 Event Slice 정렬 순서를 id desc 로 다시 고정하였습니다
  • 이벤트 응답 VO 에 @DateFormat 누락 분 적용하였습니다
  • endAt 계산 시 runTime 없을 때 NullPointException 해결하였습니다
    @Override
    public Slice<Event> querySliceEventsByHostIdIn(List<Long> hostId, Pageable pageable) {
        List<Event> events =
                queryFactory
                        .selectFrom(event)
                        .where(event.hostId.in(hostId))
                        .orderBy(event.id.desc())
                        .offset(pageable.getOffset())
                        .limit(pageable.getPageSize() + 1)
                        .fetch();
        return SliceUtil.valueOf(events, pageable);
    }
  • List -> Slice 바꾸는 변환 로직이 많이 중복되어서 SliceUtil.valueOf 정적 메서드 만들었습니다

CALCULATING("CALCULATING", "정산중")

  • 이벤트 상태에 정산중을 추가했습니다

변경로직

  • 내용을 적어주세요.

@gengminy gengminy added For: API [이슈 대상] 외부 API Type: Errors/Bugs [이슈 목적] 버그, 애러 수정 Type: Refactor [이슈 목적] 프로덕션 코드 리팩토링 labels Feb 2, 2023
@gengminy gengminy self-assigned this Feb 2, 2023
Copy link
Member

@ImNM ImNM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엘쥐티엠~

Comment on lines +4 to +26
import java.util.List;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Slice;
import org.springframework.data.domain.SliceImpl;

public class SliceUtil {
// 리스트를 슬라이스로 변환
public static <T> Slice<T> valueOf(List<T> contents, Pageable pageable) {
boolean hasNext = hasNext(contents, pageable);
return new SliceImpl<>(
hasNext ? getContent(contents, pageable) : contents, pageable, hasNext);
}

// 다음 페이지 있는지 확인
private static <T> boolean hasNext(List<T> content, Pageable pageable) {
return pageable.isPaged() && content.size() > pageable.getPageSize();
}

// 데이터 1개 빼고 반환
private static <T> List<T> getContent(List<T> content, Pageable pageable) {
return content.subList(0, pageable.getPageSize());
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와우 좋습니다! 최고!!

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 292 Code Smells

15.5% 15.5% Coverage
0.0% 0.0% Duplication

Copy link
Member

@sanbonai06 sanbonai06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slice 확인이요! 수고하셨어요! LGTM 👍

@gengminy gengminy merged commit ec58a46 into dev Feb 3, 2023
@ImNM ImNM deleted the refactor/279-change-to-pageable branch February 3, 2023 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For: API [이슈 대상] 외부 API Type: Errors/Bugs [이슈 목적] 버그, 애러 수정 Type: Refactor [이슈 목적] 프로덕션 코드 리팩토링
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🔨[refactor] SliceParam 을 Pageable 로 교체
3 participants