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

Feat: userId를 가진 특정 사용자의 최신 스크린 타임 조회 #9

Open
jiseokson opened this issue Jan 26, 2024 · 0 comments
Assignees

Comments

@jiseokson
Copy link
Member

조회

다음은 userId를 사진 사용자의 최신 스크린 타임을 반환하는 서비스 코드의 일부이다.

Page<ScreenTime> screenTimePage
        = screenTimeRepository.findLatestByUserId(userId, PageRequest.of(0, 1));
List<ScreenTime> screenTimes = screenTimePage.getContent();
if (screenTimes.isEmpty()) {
    throw new ScreenTimeNotFoundException();
}
return ScreenTimeResponse.build(user, screenTimes.get(0));

findLatestByUserId() 메소드는 Page를 반환하도록 선언했으므로 getContent() 메소드를 통해 List로 변환 후 isEmpty() 메소드를 통해 ScreenTime 엔티티의 존재성을 검사해야 한다. 만약 존재하지 않는다면 (isEmpty() == true 라면) ScreenTimeNotFoundException을 발생시키고, 존재한다면 get(0) 메소드를 통해 스크린 타임 엔티티를 가져온다.

@jiseokson jiseokson self-assigned this Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant