-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#26]Refactor: Boj, GitHub Controller를 User에서 분리
- Loading branch information
Showing
17 changed files
with
174 additions
and
97 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
src/main/java/bssm/db/bssmgit/domain/boj/domain/repository/CustomBojRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package bssm.db.bssmgit.domain.boj.domain.repository; | ||
|
||
import bssm.db.bssmgit.domain.boj.web.dto.response.BojResponseDto; | ||
|
||
import java.util.List; | ||
|
||
public interface CustomBojRepository { | ||
|
||
List<BojResponseDto> findAllUserBojDesc(); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/bssm/db/bssmgit/domain/boj/domain/repository/CustomBojRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package bssm.db.bssmgit.domain.boj.domain.repository; | ||
|
||
import bssm.db.bssmgit.domain.boj.web.dto.response.BojResponseDto; | ||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
import static bssm.db.bssmgit.domain.boj.domain.QBoj.boj; | ||
import static bssm.db.bssmgit.domain.user.domain.QUser.user; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class CustomBojRepositoryImpl implements CustomBojRepository { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
@Override | ||
public List<BojResponseDto> findAllUserBojDesc() { | ||
return jpaQueryFactory | ||
.select(Projections.constructor(BojResponseDto.class, user, boj)) | ||
.from(boj) | ||
.innerJoin(user) | ||
.fetchJoin() | ||
.where(boj.bojId.isNotNull()) | ||
.distinct() | ||
.orderBy(boj.rating.desc()) | ||
.fetch(); | ||
} | ||
} |
22 changes: 8 additions & 14 deletions
22
src/main/java/bssm/db/bssmgit/domain/boj/service/BojInformationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,19 @@ | ||
package bssm.db.bssmgit.domain.boj.service; | ||
|
||
import bssm.db.bssmgit.domain.github.domain.repository.GitHubRepository; | ||
import bssm.db.bssmgit.domain.github.web.dto.response.GithubResponseDto; | ||
import lombok.AccessLevel; | ||
import bssm.db.bssmgit.domain.boj.domain.repository.CustomBojRepository; | ||
import bssm.db.bssmgit.domain.boj.web.dto.response.BojResponseDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class BojInformationService { | ||
|
||
private final GitHubRepository gitHubRepository; | ||
private final CustomBojRepository customBojRepository; | ||
|
||
public List<GithubResponseDto> findAllUserGitDesc() { | ||
return gitHubRepository.findAll().stream() | ||
.filter(g -> g.getGithubId() != null) | ||
.filter(g -> g.getCommits() != null) | ||
.map(GithubResponseDto::new) | ||
.collect(Collectors.toList()); | ||
public List<BojResponseDto> findAllUserBojDesc() { | ||
return customBojRepository.findAllUserBojDesc(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/bssm/db/bssmgit/domain/boj/web/api/BojInformationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package bssm.db.bssmgit.domain.boj.web.api; | ||
|
||
import bssm.db.bssmgit.domain.boj.service.BojInformationService; | ||
import bssm.db.bssmgit.domain.boj.web.dto.response.BojResponseDto; | ||
import bssm.db.bssmgit.global.generic.Result; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/boj") | ||
@RequiredArgsConstructor | ||
public class BojInformationController { | ||
private final BojInformationService bojInformationService; | ||
|
||
@GetMapping("/ranking") | ||
public Result<List<BojResponseDto>> findByGithubCommitDesc() { | ||
List<BojResponseDto> allUserBojDesc = bojInformationService.findAllUserBojDesc(); | ||
return new Result<>(allUserBojDesc.size(), allUserBojDesc); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/main/java/bssm/db/bssmgit/domain/github/service/GitHubInformationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package bssm.db.bssmgit.domain.github.service; | ||
|
||
import bssm.db.bssmgit.domain.github.domain.repository.CustomGithubRepository; | ||
import bssm.db.bssmgit.domain.github.web.dto.response.GithubResponseDto; | ||
import lombok.AccessLevel; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Transactional(readOnly = true) | ||
public class GitHubInformationService { | ||
|
||
private final CustomGithubRepository customGithubRepository; | ||
|
||
public List<GithubResponseDto> findAllUserGitDesc() { | ||
return customGithubRepository.getGitHubAndUser(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/bssm/db/bssmgit/domain/github/web/api/GitHubInformationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package bssm.db.bssmgit.domain.github.web.api; | ||
|
||
import bssm.db.bssmgit.domain.boj.web.dto.response.BojResponseDto; | ||
import bssm.db.bssmgit.domain.github.service.GitHubInformationService; | ||
import bssm.db.bssmgit.domain.github.web.dto.response.GithubResponseDto; | ||
import bssm.db.bssmgit.global.generic.Result; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/github") | ||
@RequiredArgsConstructor | ||
public class GitHubInformationController { | ||
|
||
private final GitHubInformationService gitHubInformationService; | ||
|
||
@GetMapping("/ranking") | ||
public Result<List<GithubResponseDto>> findByGithubCommitDesc() { | ||
List<GithubResponseDto> allUserGitDesc = gitHubInformationService.findAllUserGitDesc(); | ||
return new Result<>(allUserGitDesc.size(), allUserGitDesc); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/bssm/db/bssmgit/domain/github/web/dto/GitHubIdDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package bssm.db.bssmgit.domain.github.web.dto; | ||
|
||
import bssm.db.bssmgit.domain.github.domain.GitHub; | ||
import bssm.db.bssmgit.domain.user.domain.User; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class GitHubIdDto { | ||
|
||
private final String gitHubId; | ||
|
||
@Builder | ||
public GitHubIdDto(String gitHubId) { | ||
this.gitHubId = gitHubId; | ||
} | ||
|
||
public GitHub toGitHubHasThisId() { | ||
return GitHub.builder() | ||
.githubId(this.gitHubId) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.