-
Notifications
You must be signed in to change notification settings - Fork 0
Feat: [FN-264] 카드셋 생성 및 수정시 매니저 설정 기능 구현 #59
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
83 changes: 83 additions & 0 deletions
83
src/main/java/project/flipnote/cardset/service/CardSetManagerWriter.java
This file contains hidden or 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,83 @@ | ||
| package project.flipnote.cardset.service; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import project.flipnote.cardset.entity.CardSet; | ||
| import project.flipnote.cardset.entity.CardSetManager; | ||
| import project.flipnote.cardset.repository.CardSetManagerRepository; | ||
| import project.flipnote.user.repository.UserProfileRepository; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| public class CardSetManagerWriter { | ||
|
|
||
| private final CardSetManagerRepository cardSetManagerRepository; | ||
| private final UserProfileRepository userProfileRepository; | ||
|
|
||
| /** | ||
| * 카드셋에 매니저들을 할당 | ||
| * 카드셋 생성시 생성자는 항상 매니저로 포함됨 | ||
| * | ||
| * @param cardSet 매니저를 할당할 카드셋 | ||
| * @param managerIds 요청된 매니저 ID 목록 | ||
| * @author 윤정환 | ||
| */ | ||
| public void assignManagers(CardSet cardSet, Set<Long> managerIds) { | ||
| Set<Long> finalManagerIds = includeAuthor(cardSet.getAuthor(), managerIds); | ||
|
|
||
| List<CardSetManager> managers = finalManagerIds.stream() | ||
| .map(id -> CardSetManager.builder() | ||
| .cardSet(cardSet) | ||
| .user(userProfileRepository.getReferenceById(id)) | ||
| .build()) | ||
| .toList(); | ||
|
|
||
| cardSetManagerRepository.saveAll(managers); | ||
| } | ||
|
|
||
| /** | ||
| * 카드셋의 매니저를 수정 | ||
| * 차집합을 이용해 삭제/추가할 매니저만 처리 | ||
| * | ||
| * @param cardSet 매니저를 수정할 카드셋 | ||
| * @param newManagerIds 새로운 매니저 ID 목록 | ||
| * @author 윤정환 | ||
| */ | ||
| public void updateManagers(CardSet cardSet, Set<Long> newManagerIds) { | ||
| Set<Long> currentManagerIds = cardSetManagerRepository.findUserIdsByCardSetId(cardSet.getId()); | ||
|
|
||
| Set<Long> toDelete = difference(currentManagerIds, newManagerIds); | ||
| Set<Long> toAdd = difference(newManagerIds, currentManagerIds); | ||
|
|
||
|
Comment on lines
+51
to
+56
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. 업데이트에서도 작성자 강제 포함 필요 현재 ✅ 수정 제안 public void updateManagers(CardSet cardSet, Set<Long> newManagerIds) {
- Set<Long> currentManagerIds = cardSetManagerRepository.findUserIdsByCardSetId(cardSet.getId());
-
- Set<Long> toDelete = difference(currentManagerIds, newManagerIds);
- Set<Long> toAdd = difference(newManagerIds, currentManagerIds);
+ Set<Long> finalManagerIds = includeAuthor(cardSet.getAuthor(), newManagerIds);
+ Set<Long> currentManagerIds = cardSetManagerRepository.findUserIdsByCardSetId(cardSet.getId());
+
+ Set<Long> toDelete = difference(currentManagerIds, finalManagerIds);
+ Set<Long> toAdd = difference(finalManagerIds, currentManagerIds);🤖 Prompt for AI Agents |
||
| if (!toDelete.isEmpty()) { | ||
| cardSetManagerRepository.deleteByCardSet_IdAndUser_IdIn(cardSet.getId(), toDelete); | ||
| } | ||
|
|
||
| if (!toAdd.isEmpty()) { | ||
| List<CardSetManager> managers = toAdd.stream() | ||
| .map(id -> CardSetManager.builder() | ||
| .cardSet(cardSet) | ||
| .user(userProfileRepository.getReferenceById(id)) | ||
| .build()) | ||
| .toList(); | ||
| cardSetManagerRepository.saveAll(managers); | ||
| } | ||
| } | ||
|
|
||
| private Set<Long> includeAuthor(Long authorId, Set<Long> managerIds) { | ||
| Set<Long> result = new HashSet<>(managerIds); | ||
| result.add(authorId); | ||
| return result; | ||
| } | ||
|
|
||
| private Set<Long> difference(Set<Long> a, Set<Long> b) { | ||
| Set<Long> result = new HashSet<>(a); | ||
| result.removeAll(b); | ||
| return result; | ||
| } | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.