From 32f9228ff025c0c835943b8dc2483926df067b54 Mon Sep 17 00:00:00 2001 From: song hyeongyu Date: Thu, 15 May 2025 13:13:28 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EC=97=B0=EA=B4=80=20=EA=B4=80?= =?UTF-8?q?=EA=B3=84=20=EC=88=98=EC=A0=95=20(#16)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduler/ContributionScheduler.java | 8 ++++++-- .../conal/github_repo/domain/GithubRepo.java | 6 +----- .../github_repo/dto/GithubRepoMapper.java | 5 ++++- .../dto/response/GithubRepoGetResponse.java | 3 --- .../service/GithubRepoService.java | 3 ++- .../domain/NotificationAgreement.java | 14 +++++--------- .../NotificationAgreementRepository.java | 10 +++++----- .../service/NotificationAgreementQuery.java | 2 +- .../conal/vote/scheduler/VoteScheduler.java | 19 +++++++++---------- 9 files changed, 33 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/specialwarriors/conal/contribution/scheduler/ContributionScheduler.java b/src/main/java/com/specialwarriors/conal/contribution/scheduler/ContributionScheduler.java index 44384c0..02e7fcd 100644 --- a/src/main/java/com/specialwarriors/conal/contribution/scheduler/ContributionScheduler.java +++ b/src/main/java/com/specialwarriors/conal/contribution/scheduler/ContributionScheduler.java @@ -3,6 +3,7 @@ import com.specialwarriors.conal.contribution.service.ContributionService; import com.specialwarriors.conal.contributor.domain.Contributor; import com.specialwarriors.conal.github_repo.domain.GithubRepo; +import com.specialwarriors.conal.github_repo.repository.GithubRepoRepository; import com.specialwarriors.conal.notification.domain.NotificationAgreement; import com.specialwarriors.conal.notification.enums.NotificationType; import com.specialwarriors.conal.notification.service.NotificationAgreementQuery; @@ -17,6 +18,7 @@ public class ContributionScheduler { private final NotificationAgreementQuery notificationAgreementQuery; + private final GithubRepoRepository githubRepoRepository; private final ContributionService contributionService; private final MailUtil mailUtil; @@ -26,10 +28,12 @@ public void sendContribution() { List notificationAgreements = notificationAgreementQuery .findAllByType(NotificationType.CONTRIBUTION); - List githubRepos = notificationAgreements.stream() - .map(NotificationAgreement::getGithubRepo) + List githubRepoId = notificationAgreements.stream() + .map(NotificationAgreement::getGithubRepoId) .toList(); + List githubRepos = githubRepoRepository.findAllById(githubRepoId); + for (GithubRepo githubRepo : githubRepos) { for (Contributor contributor : githubRepo.getContributors()) { mailUtil.sendContributionForm( diff --git a/src/main/java/com/specialwarriors/conal/github_repo/domain/GithubRepo.java b/src/main/java/com/specialwarriors/conal/github_repo/domain/GithubRepo.java index fa46cce..02d5c96 100644 --- a/src/main/java/com/specialwarriors/conal/github_repo/domain/GithubRepo.java +++ b/src/main/java/com/specialwarriors/conal/github_repo/domain/GithubRepo.java @@ -43,9 +43,6 @@ public class GithubRepo { @OneToMany(mappedBy = "githubRepo", cascade = CascadeType.ALL) private List contributors = new ArrayList<>(); - @OneToMany(mappedBy = "githubRepo") - private List notificationAgreements = new ArrayList<>(); - @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; @@ -67,8 +64,7 @@ public void addContributors(List contributors) { public void setNotificationAgreement(List agreements) { for (NotificationAgreement agreement : agreements) { - this.notificationAgreements.add(agreement); - agreement.setGitHubRepo(this); + agreement.setGitHubRepoId(this.getId()); } } diff --git a/src/main/java/com/specialwarriors/conal/github_repo/dto/GithubRepoMapper.java b/src/main/java/com/specialwarriors/conal/github_repo/dto/GithubRepoMapper.java index b3ad718..1d80e86 100644 --- a/src/main/java/com/specialwarriors/conal/github_repo/dto/GithubRepoMapper.java +++ b/src/main/java/com/specialwarriors/conal/github_repo/dto/GithubRepoMapper.java @@ -18,6 +18,7 @@ public interface GithubRepoMapper { default GithubRepoCreateResponse toGithubRepoCreateResponse(String owner, String reponame) { + return new GithubRepoCreateResponse( owner, reponame @@ -26,12 +27,12 @@ default GithubRepoCreateResponse toGithubRepoCreateResponse(String owner, default GithubRepoGetResponse toGithubRepoGetResponse(GithubRepo repo, String owner, String reponame, Long userId) { + return new GithubRepoGetResponse( userId, repo.getId(), repo.getName(), repo.getUrl(), - repo.getNotificationAgreements(), repo.getEndDate(), owner, reponame @@ -42,6 +43,7 @@ default GithubRepoGetResponse toGithubRepoGetResponse(GithubRepo repo, String ow GithubRepoSummary toGithubRepoSummary(GithubRepo repo); default GithubRepoPageResponse toGithubRepoPageResponse(Page page, Long userId) { + return new GithubRepoPageResponse( page.getContent().stream() .map(this::toGithubRepoSummary) @@ -54,6 +56,7 @@ default GithubRepoPageResponse toGithubRepoPageResponse(Page page, L } default GithubRepoDeleteResponse toGithubDeleteRepoResponse() { + return new GithubRepoDeleteResponse( true ); diff --git a/src/main/java/com/specialwarriors/conal/github_repo/dto/response/GithubRepoGetResponse.java b/src/main/java/com/specialwarriors/conal/github_repo/dto/response/GithubRepoGetResponse.java index 3f7fe27..1d02b9b 100644 --- a/src/main/java/com/specialwarriors/conal/github_repo/dto/response/GithubRepoGetResponse.java +++ b/src/main/java/com/specialwarriors/conal/github_repo/dto/response/GithubRepoGetResponse.java @@ -1,15 +1,12 @@ package com.specialwarriors.conal.github_repo.dto.response; -import com.specialwarriors.conal.notification.domain.NotificationAgreement; import java.time.LocalDate; -import java.util.List; public record GithubRepoGetResponse( Long userId, Long repoId, String name, String url, - List agreement, LocalDate endDate, String owner, String repo diff --git a/src/main/java/com/specialwarriors/conal/github_repo/service/GithubRepoService.java b/src/main/java/com/specialwarriors/conal/github_repo/service/GithubRepoService.java index 73bc5e5..6fd5e6e 100644 --- a/src/main/java/com/specialwarriors/conal/github_repo/service/GithubRepoService.java +++ b/src/main/java/com/specialwarriors/conal/github_repo/service/GithubRepoService.java @@ -79,6 +79,7 @@ private List createAndSaveContributors(Set emails) { } private List createAndAttachNotifications() { + return notificationAgreementRepository.saveAll( List.of( new NotificationAgreement(NotificationType.VOTE), @@ -109,7 +110,7 @@ public GithubRepoPageResponse getGithubRepoInfos(Long userId, int page) { public GithubRepoDeleteResponse deleteRepo(Long userId, Long repositoryId) { GithubRepo repo = githubRepoQuery.findByUserIdAndRepositoryId(userId, repositoryId); contributorRepository.deleteAllByGithubRepo(repo); - notificationAgreementRepository.deleteByGithubRepo(repo); + notificationAgreementRepository.deleteByGithubRepoId(repo.getId()); githubRepoRepository.delete(repo); return githubRepoMapper.toGithubDeleteRepoResponse(); diff --git a/src/main/java/com/specialwarriors/conal/notification/domain/NotificationAgreement.java b/src/main/java/com/specialwarriors/conal/notification/domain/NotificationAgreement.java index 630fc44..72e57a6 100644 --- a/src/main/java/com/specialwarriors/conal/notification/domain/NotificationAgreement.java +++ b/src/main/java/com/specialwarriors/conal/notification/domain/NotificationAgreement.java @@ -1,16 +1,13 @@ package com.specialwarriors.conal.notification.domain; -import com.specialwarriors.conal.github_repo.domain.GithubRepo; import com.specialwarriors.conal.notification.converter.NotificationTypeConverter; import com.specialwarriors.conal.notification.enums.NotificationType; +import jakarta.persistence.Column; import jakarta.persistence.Convert; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import lombok.AccessLevel; import lombok.Getter; @@ -28,9 +25,8 @@ public class NotificationAgreement { private boolean isAgree; - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "github_repo_id") - private GithubRepo githubRepo; + @Column(name = "github_repo_id", nullable = false) + private Long githubRepoId; @Convert(converter = NotificationTypeConverter.class) private NotificationType notificationType; @@ -43,8 +39,8 @@ public void disagree() { this.isAgree = false; } - public void setGitHubRepo(GithubRepo githubRepo) { - this.githubRepo = githubRepo; + public void setGitHubRepoId(Long githubRepoId) { + this.githubRepoId = githubRepoId; } public NotificationAgreement(NotificationType notificationType) { diff --git a/src/main/java/com/specialwarriors/conal/notification/repository/NotificationAgreementRepository.java b/src/main/java/com/specialwarriors/conal/notification/repository/NotificationAgreementRepository.java index d7c6a09..70f566e 100644 --- a/src/main/java/com/specialwarriors/conal/notification/repository/NotificationAgreementRepository.java +++ b/src/main/java/com/specialwarriors/conal/notification/repository/NotificationAgreementRepository.java @@ -1,6 +1,5 @@ package com.specialwarriors.conal.notification.repository; -import com.specialwarriors.conal.github_repo.domain.GithubRepo; import com.specialwarriors.conal.notification.domain.NotificationAgreement; import com.specialwarriors.conal.notification.enums.NotificationType; import java.util.List; @@ -8,12 +7,13 @@ import org.springframework.stereotype.Repository; @Repository -public interface NotificationAgreementRepository extends JpaRepository { +public interface NotificationAgreementRepository extends + JpaRepository { - List findAllByGithubRepoAndNotificationType(GithubRepo githubRepo, - NotificationType notificationType); + List findAllByGithubRepoIdAndNotificationType(Long githubRepoId, + NotificationType notificationType); List findAllByNotificationType(NotificationType notificationType); - void deleteByGithubRepo(GithubRepo repo); + void deleteByGithubRepoId(Long githubRepoId); } diff --git a/src/main/java/com/specialwarriors/conal/notification/service/NotificationAgreementQuery.java b/src/main/java/com/specialwarriors/conal/notification/service/NotificationAgreementQuery.java index 5c7bbe0..399dba0 100644 --- a/src/main/java/com/specialwarriors/conal/notification/service/NotificationAgreementQuery.java +++ b/src/main/java/com/specialwarriors/conal/notification/service/NotificationAgreementQuery.java @@ -22,7 +22,7 @@ public NotificationAgreement findByGithubRepoAndType(GithubRepo githubRepo, NotificationType type) { return notificationAgreementRepository - .findAllByGithubRepoAndNotificationType(githubRepo, type) + .findAllByGithubRepoIdAndNotificationType(githubRepo.getId(), type) .stream() .findFirst() .orElseThrow(() -> new GeneralException( diff --git a/src/main/java/com/specialwarriors/conal/vote/scheduler/VoteScheduler.java b/src/main/java/com/specialwarriors/conal/vote/scheduler/VoteScheduler.java index dc5d1f6..d417150 100644 --- a/src/main/java/com/specialwarriors/conal/vote/scheduler/VoteScheduler.java +++ b/src/main/java/com/specialwarriors/conal/vote/scheduler/VoteScheduler.java @@ -1,6 +1,5 @@ package com.specialwarriors.conal.vote.scheduler; -import com.specialwarriors.conal.github_repo.domain.GithubRepo; import com.specialwarriors.conal.notification.domain.NotificationAgreement; import com.specialwarriors.conal.notification.enums.NotificationType; import com.specialwarriors.conal.notification.service.NotificationAgreementQuery; @@ -23,7 +22,7 @@ public class VoteScheduler { @Scheduled(cron = "0 0 9 ? * FRI") public void openWeeklyVote() { List notificationAgreements = notificationAgreementQuery - .findAllByType(NotificationType.VOTE); + .findAllByType(NotificationType.VOTE); List repositoryIds = extractGithubRepoIdsFrom(notificationAgreements); @@ -33,7 +32,7 @@ public void openWeeklyVote() { @Scheduled(cron = "0 0 18 ? * FRI") public void sendWeeklyVoteForm() { List notificationAgreements = notificationAgreementQuery - .findAllByType(NotificationType.VOTE); + .findAllByType(NotificationType.VOTE); List repositoryIds = extractGithubRepoIdsFrom(notificationAgreements); @@ -45,12 +44,12 @@ public void sendWeeklyVoteForm() { @Scheduled(cron = "0 0 9 ? * MON") public void sendWeeklyVoteResult() { List notificationAgreements = notificationAgreementQuery - .findAllByType(NotificationType.VOTE); + .findAllByType(NotificationType.VOTE); List repositoryIds = extractGithubRepoIdsFrom(notificationAgreements); List voteResults = repositoryIds.stream() - .map(voteService::getVoteResult) - .toList(); + .map(voteService::getVoteResult) + .toList(); for (VoteResultResponse voteResult : voteResults) { List emails = voteResult.emails(); @@ -60,11 +59,11 @@ public void sendWeeklyVoteResult() { private List extractGithubRepoIdsFrom( - List notificationAgreements) { + List notificationAgreements) { return notificationAgreements.stream() - .map(NotificationAgreement::getGithubRepo) - .map(GithubRepo::getId) - .toList(); + .map(NotificationAgreement::getGithubRepoId) + .distinct() + .toList(); } } From b1bba377d2aaa864c7bcd56ccb8b1fff7f0c6ab0 Mon Sep 17 00:00:00 2001 From: song hyeongyu Date: Thu, 15 May 2025 14:22:55 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20dto=20=EC=82=AD=EC=A0=9C=20(#1?= =?UTF-8?q?6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/GithubRepoController.java | 17 ++++++++--------- .../conal/github_repo/dto/GithubRepoMapper.java | 12 ++---------- .../dto/response/GithubRepoDeleteResponse.java | 7 ------- .../github_repo/service/GithubRepoService.java | 7 ++----- 4 files changed, 12 insertions(+), 31 deletions(-) delete mode 100644 src/main/java/com/specialwarriors/conal/github_repo/dto/response/GithubRepoDeleteResponse.java diff --git a/src/main/java/com/specialwarriors/conal/github_repo/controller/GithubRepoController.java b/src/main/java/com/specialwarriors/conal/github_repo/controller/GithubRepoController.java index 6023c59..125235e 100644 --- a/src/main/java/com/specialwarriors/conal/github_repo/controller/GithubRepoController.java +++ b/src/main/java/com/specialwarriors/conal/github_repo/controller/GithubRepoController.java @@ -3,7 +3,6 @@ import com.specialwarriors.conal.github.service.GitHubService; import com.specialwarriors.conal.github_repo.dto.request.GithubRepoCreateRequest; import com.specialwarriors.conal.github_repo.dto.response.GithubRepoCreateResponse; -import com.specialwarriors.conal.github_repo.dto.response.GithubRepoDeleteResponse; import com.specialwarriors.conal.github_repo.dto.response.GithubRepoGetResponse; import com.specialwarriors.conal.github_repo.dto.response.GithubRepoPageResponse; import com.specialwarriors.conal.github_repo.service.GithubRepoService; @@ -30,7 +29,7 @@ public class GithubRepoController { @GetMapping("/new") public String showCreateForm(@SessionAttribute Long userId, Model model) { model.addAttribute("repoRequest", - new GithubRepoCreateRequest(userId, "", "", null, Set.of())); + new GithubRepoCreateRequest(userId, "", "", null, Set.of())); model.addAttribute("userId", userId); return "repo/form"; @@ -39,7 +38,7 @@ public String showCreateForm(@SessionAttribute Long userId, Model model) { // 저장 (POST) @PostMapping public String createGitHubRepo(@SessionAttribute Long userId, - @ModelAttribute GithubRepoCreateRequest request) { + @ModelAttribute GithubRepoCreateRequest request) { GithubRepoCreateResponse response = githubRepoService.createGithubRepo(userId, request); gitHubService.updateRepoContribution(response.owner(), response.repo()).subscribe(); @@ -49,8 +48,8 @@ public String createGitHubRepo(@SessionAttribute Long userId, // 목록 조회 (GET) @GetMapping public String getGithubRepos(@SessionAttribute Long userId, - @RequestParam(defaultValue = "0") int page, - Model model) { + @RequestParam(defaultValue = "0") int page, + Model model) { GithubRepoPageResponse response = githubRepoService.getGithubRepoInfos(userId, page); model.addAttribute("repositories", response); @@ -62,8 +61,8 @@ public String getGithubRepos(@SessionAttribute Long userId, // 단일 조회 (GET) @GetMapping("/{repositoryId}") public String getRepositoryId(@SessionAttribute Long userId, - @PathVariable long repositoryId, - Model model) { + @PathVariable long repositoryId, + Model model) { GithubRepoGetResponse response = githubRepoService.getGithubRepoInfo(userId, repositoryId); model.addAttribute("repoInfo", response); @@ -72,8 +71,8 @@ public String getRepositoryId(@SessionAttribute Long userId, @PostMapping("/{repositoryId}") public String deleteRepository(@SessionAttribute Long userId, - @PathVariable long repositoryId) { - GithubRepoDeleteResponse response = githubRepoService.deleteRepo(userId, repositoryId); + @PathVariable long repositoryId) { + githubRepoService.deleteRepo(userId, repositoryId); return "redirect:/home"; } diff --git a/src/main/java/com/specialwarriors/conal/github_repo/dto/GithubRepoMapper.java b/src/main/java/com/specialwarriors/conal/github_repo/dto/GithubRepoMapper.java index 1d80e86..a819ee1 100644 --- a/src/main/java/com/specialwarriors/conal/github_repo/dto/GithubRepoMapper.java +++ b/src/main/java/com/specialwarriors/conal/github_repo/dto/GithubRepoMapper.java @@ -4,7 +4,6 @@ import com.specialwarriors.conal.github_repo.domain.GithubRepo; import com.specialwarriors.conal.github_repo.dto.request.GithubRepoCreateRequest; import com.specialwarriors.conal.github_repo.dto.response.GithubRepoCreateResponse; -import com.specialwarriors.conal.github_repo.dto.response.GithubRepoDeleteResponse; import com.specialwarriors.conal.github_repo.dto.response.GithubRepoGetResponse; import com.specialwarriors.conal.github_repo.dto.response.GithubRepoPageResponse; import com.specialwarriors.conal.github_repo.dto.response.GithubRepoPageResponse.GithubRepoSummary; @@ -43,7 +42,7 @@ default GithubRepoGetResponse toGithubRepoGetResponse(GithubRepo repo, String ow GithubRepoSummary toGithubRepoSummary(GithubRepo repo); default GithubRepoPageResponse toGithubRepoPageResponse(Page page, Long userId) { - + return new GithubRepoPageResponse( page.getContent().stream() .map(this::toGithubRepoSummary) @@ -54,12 +53,5 @@ default GithubRepoPageResponse toGithubRepoPageResponse(Page page, L page.getTotalElements() ); } - - default GithubRepoDeleteResponse toGithubDeleteRepoResponse() { - - return new GithubRepoDeleteResponse( - true - ); - } - + } diff --git a/src/main/java/com/specialwarriors/conal/github_repo/dto/response/GithubRepoDeleteResponse.java b/src/main/java/com/specialwarriors/conal/github_repo/dto/response/GithubRepoDeleteResponse.java deleted file mode 100644 index 413d87e..0000000 --- a/src/main/java/com/specialwarriors/conal/github_repo/dto/response/GithubRepoDeleteResponse.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.specialwarriors.conal.github_repo.dto.response; - -public record GithubRepoDeleteResponse( - boolean result -) { - -} diff --git a/src/main/java/com/specialwarriors/conal/github_repo/service/GithubRepoService.java b/src/main/java/com/specialwarriors/conal/github_repo/service/GithubRepoService.java index 6fd5e6e..c072e7f 100644 --- a/src/main/java/com/specialwarriors/conal/github_repo/service/GithubRepoService.java +++ b/src/main/java/com/specialwarriors/conal/github_repo/service/GithubRepoService.java @@ -7,7 +7,6 @@ import com.specialwarriors.conal.github_repo.dto.GithubRepoMapper; import com.specialwarriors.conal.github_repo.dto.request.GithubRepoCreateRequest; import com.specialwarriors.conal.github_repo.dto.response.GithubRepoCreateResponse; -import com.specialwarriors.conal.github_repo.dto.response.GithubRepoDeleteResponse; import com.specialwarriors.conal.github_repo.dto.response.GithubRepoGetResponse; import com.specialwarriors.conal.github_repo.dto.response.GithubRepoPageResponse; import com.specialwarriors.conal.github_repo.exception.GithubRepoException; @@ -79,7 +78,7 @@ private List createAndSaveContributors(Set emails) { } private List createAndAttachNotifications() { - + return notificationAgreementRepository.saveAll( List.of( new NotificationAgreement(NotificationType.VOTE), @@ -107,12 +106,10 @@ public GithubRepoPageResponse getGithubRepoInfos(Long userId, int page) { } @Transactional - public GithubRepoDeleteResponse deleteRepo(Long userId, Long repositoryId) { + public void deleteRepo(Long userId, Long repositoryId) { GithubRepo repo = githubRepoQuery.findByUserIdAndRepositoryId(userId, repositoryId); contributorRepository.deleteAllByGithubRepo(repo); notificationAgreementRepository.deleteByGithubRepoId(repo.getId()); githubRepoRepository.delete(repo); - - return githubRepoMapper.toGithubDeleteRepoResponse(); } } From 687c66093b119bb9baa03e62615f0efe572ec187 Mon Sep 17 00:00:00 2001 From: song hyeongyu Date: Thu, 15 May 2025 14:44:49 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20pr=20review=20=EB=B0=98=EC=98=81=20?= =?UTF-8?q?(#16)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../contribution/scheduler/ContributionScheduler.java | 4 ++-- .../conal/github_repo/domain/GithubRepo.java | 9 +++++---- .../conal/github_repo/service/GithubRepoService.java | 2 +- .../conal/notification/domain/NotificationAgreement.java | 4 ++-- .../repository/NotificationAgreementRepository.java | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/specialwarriors/conal/contribution/scheduler/ContributionScheduler.java b/src/main/java/com/specialwarriors/conal/contribution/scheduler/ContributionScheduler.java index 02e7fcd..939a71b 100644 --- a/src/main/java/com/specialwarriors/conal/contribution/scheduler/ContributionScheduler.java +++ b/src/main/java/com/specialwarriors/conal/contribution/scheduler/ContributionScheduler.java @@ -28,11 +28,11 @@ public void sendContribution() { List notificationAgreements = notificationAgreementQuery .findAllByType(NotificationType.CONTRIBUTION); - List githubRepoId = notificationAgreements.stream() + List githubRepoIds = notificationAgreements.stream() .map(NotificationAgreement::getGithubRepoId) .toList(); - List githubRepos = githubRepoRepository.findAllById(githubRepoId); + List githubRepos = githubRepoRepository.findAllById(githubRepoIds); for (GithubRepo githubRepo : githubRepos) { for (Contributor contributor : githubRepo.getContributors()) { diff --git a/src/main/java/com/specialwarriors/conal/github_repo/domain/GithubRepo.java b/src/main/java/com/specialwarriors/conal/github_repo/domain/GithubRepo.java index 02d5c96..06b56b5 100644 --- a/src/main/java/com/specialwarriors/conal/github_repo/domain/GithubRepo.java +++ b/src/main/java/com/specialwarriors/conal/github_repo/domain/GithubRepo.java @@ -62,12 +62,13 @@ public void addContributors(List contributors) { } } - public void setNotificationAgreement(List agreements) { - for (NotificationAgreement agreement : agreements) { - agreement.setGitHubRepoId(this.getId()); - } + public void assignRepoIdToNotificationAgreements( + List notificationAgreements) { + + notificationAgreements.forEach(agreement -> agreement.setGitHubRepoId(this.getId())); } + public void setUser(User user) { this.user = user; user.addGithubRepo(this); diff --git a/src/main/java/com/specialwarriors/conal/github_repo/service/GithubRepoService.java b/src/main/java/com/specialwarriors/conal/github_repo/service/GithubRepoService.java index c072e7f..94a3cc3 100644 --- a/src/main/java/com/specialwarriors/conal/github_repo/service/GithubRepoService.java +++ b/src/main/java/com/specialwarriors/conal/github_repo/service/GithubRepoService.java @@ -53,7 +53,7 @@ public GithubRepoCreateResponse createGithubRepo(Long userId, GithubRepoCreateRe GithubRepo githubRepo = githubRepoMapper.toGithubRepo(request); githubRepo.setUser(user); githubRepo.addContributors(contributors); - githubRepo.setNotificationAgreement(agreements); + githubRepo.assignRepoIdToNotificationAgreements(agreements); githubRepo = githubRepoRepository.save(githubRepo); String[] ownerAndRepo = UrlUtil.urlToOwnerAndReponame(githubRepo.getUrl()); diff --git a/src/main/java/com/specialwarriors/conal/notification/domain/NotificationAgreement.java b/src/main/java/com/specialwarriors/conal/notification/domain/NotificationAgreement.java index 72e57a6..ea57acf 100644 --- a/src/main/java/com/specialwarriors/conal/notification/domain/NotificationAgreement.java +++ b/src/main/java/com/specialwarriors/conal/notification/domain/NotificationAgreement.java @@ -25,8 +25,8 @@ public class NotificationAgreement { private boolean isAgree; - @Column(name = "github_repo_id", nullable = false) - private Long githubRepoId; + @Column(name = "github_repo_id") + private long githubRepoId; @Convert(converter = NotificationTypeConverter.class) private NotificationType notificationType; diff --git a/src/main/java/com/specialwarriors/conal/notification/repository/NotificationAgreementRepository.java b/src/main/java/com/specialwarriors/conal/notification/repository/NotificationAgreementRepository.java index 70f566e..9daccd4 100644 --- a/src/main/java/com/specialwarriors/conal/notification/repository/NotificationAgreementRepository.java +++ b/src/main/java/com/specialwarriors/conal/notification/repository/NotificationAgreementRepository.java @@ -15,5 +15,5 @@ List findAllByGithubRepoIdAndNotificationType(Long github List findAllByNotificationType(NotificationType notificationType); - void deleteByGithubRepoId(Long githubRepoId); + void deleteByGithubRepoId(long githubRepoId); }