Skip to content

Commit

Permalink
[#26]Refactor: findGitHubsByImaginary도 native query에서 querydsl로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobhboy committed May 10, 2023
1 parent d0d91fc commit 2d6ed1c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package bssm.db.bssmgit.domain.github.domain.repository;

import bssm.db.bssmgit.domain.github.domain.GitHub;
import bssm.db.bssmgit.domain.github.web.dto.response.GithubResponseDto;

import java.util.List;

public interface CustomGithubRepository {
List<GithubResponseDto> getGitHubAndUser();

List<GitHub> findGitHubsByImaginary();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package bssm.db.bssmgit.domain.github.domain.repository;

import bssm.db.bssmgit.domain.github.domain.GitHub;
import bssm.db.bssmgit.domain.github.domain.type.Imaginary;
import bssm.db.bssmgit.domain.github.web.dto.response.GithubResponseDto;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;
Expand All @@ -24,6 +26,16 @@ public List<GithubResponseDto> getGitHubAndUser() {
.from(gitHub)
.innerJoin(user.gitHub)
.fetchJoin()
.distinct()
.orderBy(gitHub.commits.desc())
.fetch();
}

@Override
public List<GitHub> findGitHubsByImaginary() {
return jpaQueryFactory
.selectFrom(gitHub)
.where(gitHub.imaginary.eq(Imaginary.IMAGINARY_NUMBER))
.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,7 @@

import bssm.db.bssmgit.domain.github.domain.GitHub;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface GitHubRepository extends JpaRepository<GitHub, Long> {

@Query("select g from GitHub g " +
"where g.imaginary = " +
"bssm.db.bssmgit.domain.github.domain.type.Imaginary.IMAGINARY_NUMBER")
List<GitHub> findGitHubsByImaginary();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package bssm.db.bssmgit.domain.github.service;

import bssm.db.bssmgit.domain.github.domain.GitHub;
import bssm.db.bssmgit.domain.github.domain.repository.GitHubRepository;
import bssm.db.bssmgit.domain.github.domain.repository.CustomGithubRepository;
import bssm.db.bssmgit.domain.user.domain.ImaginaryNumber;
import bssm.db.bssmgit.domain.user.domain.User;
import bssm.db.bssmgit.domain.user.facade.ImaginaryNumberFacade;
Expand All @@ -25,7 +25,7 @@
@Service
public class ImaginaryNumberService {

private final GitHubRepository gitHubRepository;
private final CustomGithubRepository customGithubRepository;
private final UserFacade userFacade;
private final ImaginaryNumberFacade imaginaryNumberFacade;

Expand Down Expand Up @@ -107,7 +107,7 @@ private boolean reportsLessThan5(List<Long> userIds, Long userId) {
}

private void dontHaveImaginaryNumber() {
List<GitHub> gitHubs = gitHubRepository.findGitHubsByImaginary();
List<GitHub> gitHubs = customGithubRepository.findGitHubsByImaginary();

for (GitHub gitHub : gitHubs) {
if (!notExistsRecordReportButAdaptImaginaryNumberUser()) {
Expand Down

0 comments on commit 2d6ed1c

Please sign in to comment.