Skip to content

Commit

Permalink
Merge pull request #165 from pknu-wap/feature/또또추가사항
Browse files Browse the repository at this point in the history
깃허브 레포 수정
  • Loading branch information
JONG-KYEONG authored Nov 29, 2023
2 parents d5cf122 + da313d8 commit 86187b5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ResponseEntity<String> registerRepository(@CurrentUser UserPrincipal user
@RequestParam String repo) {
User user = userRepository.findById(userPrincipal.getId()).get();
if(!gitHubService.regiRepo(user, categoryId, repo)){
return new ResponseEntity<>("Fail Register Repository",HttpStatus.OK);
return new ResponseEntity<>("Fail Register Repository",HttpStatus.NOT_ACCEPTABLE);
}

return new ResponseEntity<>("Success Register Repository",HttpStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ public class GithubRepository {
@OneToOne(fetch = FetchType.LAZY)
private Category category;

@NotNull
private Boolean isCategoryRegi;

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

@Repository
public interface GithubRepoRepository extends JpaRepository<GithubRepository, Long> {
@Query("SELECT gr FROM GithubRepository gr WHERE gr.user.id = :userId AND gr.repoName= :reponame")
@Query("SELECT gr FROM GithubRepository gr WHERE gr.user.id = :userId AND gr.repoName= :reponame AND gr.isCategoryRegi=false")
Optional <GithubRepository> findByRepoName(@Param("userId") Long userid , @Param("reponame") String reponame);

@Query("SELECT gr FROM GithubRepository gr WHERE gr.user.id = :userId AND gr.repoName=:repo")
Optional <GithubRepository> findRepoByUserId(@Param("userId") Long userid, @Param("repo") String repo);

@Query("SELECT gr.repoName FROM GithubRepository gr WHERE gr.user.id = :userId")
@Query("SELECT gr.repoName FROM GithubRepository gr WHERE gr.user.id = :userId AND gr.isCategoryRegi=false")
List<String> findRepoNameByUserId(@Param("userId") Long userid);
}
12 changes: 11 additions & 1 deletion server/src/main/java/com/project/Glog/service/GitHubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,23 @@ public Boolean regiRepo(User user, Long categoryId, String repo){
if(githubRepository.getCategory() != null){
return false;
}
if(category.getReopsitoryUrl() != null){
if(!category.getReopsitoryUrl().equals("")){
return false;
}

category.setIsPrcategory(true);
category.setReopsitoryUrl(repo);
githubRepository.setCategory(category);
githubRepository.setIsCategoryRegi(true);

GithubRepository newGr = new GithubRepository();
newGr.setRepoName(repo);
newGr.setUser(user);
newGr.setOwnerName(githubRepository.getOwnerName());
newGr.setIsCategoryRegi(false);

githubRepositoryRepository.save(githubRepository);
githubRepositoryRepository.save(newGr);
categoryRepository.save(category);

return true;
Expand All @@ -138,6 +147,7 @@ public RepositoryResponse saveAndGetRepo(List<GithubRepositoryInfo> githubReposi
githubRepository.setUser(user);
githubRepository.setRepoName(repo.getName());
githubRepository.setOwnerName(repo.getOwner().getLogin());
githubRepository.setIsCategoryRegi(false);

if(!isPresentRepo(user.getId(), githubRepository.getRepoName())) {
githubRepositoryRepository.save(githubRepository);
Expand Down
7 changes: 4 additions & 3 deletions server/src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ VALUES(1, '2023-11-01 12:39:35.630800', 'hello', 1, 1),


INSERT INTO category(id, category_name, is_prcategory, reopsitory_url, blog_id)
VALUES(1, 'category1', 0, NULL, 1),
(2, 'category2', 0, NULL, 3),
(3, 'githubCategory', 0, NULL, 4);
VALUES(1, 'category1', 0, '', 1),
(2, 'category2', 0, '', 3),
(3, 'githubCategory', 0, '', 4),
(4, '2githubCategory', 0, '', 4);

INSERT INTO post(id, blog_url, content, created_at, thumbnail, is_pr, is_private, likes_count, title, views_count, blog_id, category_id, user_id, pr_post_id)
VALUES(1, 'dueit', 'It is a post 1', '2023-10-08 13:14:07.377201' , NULL, 0, 0, 0, 'post1', 0, 1, 1, 1,NULL),
Expand Down

0 comments on commit 86187b5

Please sign in to comment.