-
Notifications
You must be signed in to change notification settings - Fork 1
[test] 깃 레포 단위테스트 작성 #45
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
base: dev
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| import com.specialwarriors.conal.github_repo.domain.GithubRepo; | ||
| import com.specialwarriors.conal.github_repo.exception.GithubRepoException; | ||
| import com.specialwarriors.conal.github_repo.repository.GithubRepoRepository; | ||
| import com.specialwarriors.conal.user.exception.UserException; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
|
|
@@ -15,6 +16,10 @@ public class GithubRepoQuery { | |
|
|
||
| public GithubRepo findByUserIdAndRepositoryId(Long userId, Long repositoryId) { | ||
|
|
||
| if (userId == null) { | ||
| throw new GeneralException(UserException.USER_NOT_FOUND); | ||
| } | ||
|
Comment on lines
17
to
+21
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 메서드를 이용할 때
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 현재 구조상 userId는 null이 될 가능성이 없다고 생각하기 때문에, 해당 부분을 기본형으로 바꾸거나 null 체크를 생략하는 것도 고려할 수 있겠습니다. 해당 논의를 바탕으로 코드의 의도를 좀 더 명확히 반영할 수 있도록 개선해보겠습니다. |
||
|
|
||
| GithubRepo githubRepo = githubRepoRepository.findById(repositoryId).orElseThrow(() -> | ||
| new GeneralException(GithubRepoException.NOT_FOUND_GITHUBREPO) | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,10 +141,19 @@ public GithubRepoGetResponse getGithubRepoInfo(Long userId, Long repoId) { | |
| @Transactional(readOnly = true) | ||
| public GithubRepoPageResponse getGithubRepoInfos(Long userId, int page) { | ||
|
|
||
| if (page < 0) { | ||
| throw new GeneralException(GithubRepoException.INVALID_GITHUBREPO_PAGE); | ||
| } | ||
|
Comment on lines
141
to
+146
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 말씀하신 것처럼, 컨트롤러에서 입력값을 사전에 검증하고 핵심 비즈니스 로직은 Service에서만 담당하도록 분리하는 것이 코드의 역할을 명확히 하고 가독성을 높이는 데 더 적절할 것 같습니다. 이 부분은 Controller 단에서 @RequestParam에 대한 validation을 추가하는 방식으로 개선하는 방향을 검토해보겠습니다. |
||
|
|
||
| Pageable pageable = PageRequest.of(page, PAGE_SIZE); | ||
| Page<GithubRepo> resultPage = githubRepoRepository.findGithubRepoPages(userId, | ||
| pageable); | ||
|
|
||
| int totalPages = resultPage.getTotalPages(); | ||
| if (page >= totalPages) { | ||
| throw new GeneralException(GithubRepoException.INVALID_GITHUBREPO_PAGE); | ||
| } | ||
|
|
||
| return githubRepoMapper.toGithubRepoPageResponse(resultPage, userId); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
컨벤션에 맞도록 수정하겠습니다!