-
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
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughCardSet에 작성자(author) 필드를 추가하고, 매니저 할당/업데이트 로직을 CardSetManagerWriter 서비스로 옮기며 관련 요청 모델(Create/Update)에 managers 필드를 도입하고 저장소에 매니저 조회/삭제 메서드를 추가했습니다. 또한 API 문서화 인터페이스에 getCardSets 및 deleteCardSet 시그니처가 추가되었습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant CardSetService
participant CardSetManagerWriter
participant CardSetManagerRepository
participant Database
Client->>CardSetService: createCardSet(CreateCardSetRequest)
CardSetService->>CardSetService: build CardSet entity (includes author)
CardSetService->>CardSetManagerWriter: assignManagers(cardSet, managerIds)
CardSetManagerWriter->>CardSetManagerWriter: includeAuthor(authorId) (ensure author in set)
CardSetManagerWriter->>CardSetManagerRepository: saveAll(CardSetManager entities)
CardSetManagerRepository->>Database: INSERT manager associations
Database-->>CardSetManagerRepository: OK
CardSetManagerRepository-->>CardSetManagerWriter: persisted entities
CardSetManagerWriter-->>CardSetService: done
CardSetService-->>Client: return created CardSet
sequenceDiagram
participant Client
participant CardSetService
participant CardSetManagerWriter
participant CardSetManagerRepository
participant Database
Client->>CardSetService: updateCardSet(cardSetId, UpdateRequest)
CardSetService->>CardSetManagerWriter: updateManagers(cardSet, newManagerIds)
CardSetManagerWriter->>CardSetManagerRepository: findUserIdsByCardSetId(cardSetId)
CardSetManagerRepository->>Database: SELECT existing manager IDs
Database-->>CardSetManagerRepository: existing IDs
CardSetManagerRepository-->>CardSetManagerWriter: returns existing IDs
CardSetManagerWriter->>CardSetManagerWriter: compute toDelete = existing - new, toAdd = new - existing
CardSetManagerWriter->>CardSetManagerRepository: deleteByCardSet_IdAndUser_IdIn(cardSetId, toDelete)
CardSetManagerRepository->>Database: DELETE old associations
CardSetManagerWriter->>CardSetManagerRepository: saveAll(new CardSetManager entities)
CardSetManagerRepository->>Database: INSERT new associations
Database-->>CardSetManagerRepository: OK
CardSetManagerRepository-->>CardSetManagerWriter: persisted
CardSetManagerWriter-->>CardSetService: done
CardSetService-->>Client: return updated CardSet
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🤖 Fix all issues with AI agents
In `@src/main/java/project/flipnote/cardset/entity/CardSet.java`:
- Around line 35-36: CardSet.author was changed to `@Column`(nullable = false)
which will break existing DB rows; create a DB migration that (1) adds the new
author column as nullable (or with a sensible DEFAULT), (2) backfills existing
rows with a valid user id (e.g., system user id) via an UPDATE, and only then
(3) alters the column to NOT NULL; alternatively, temporarily change the entity
CardSet.author to `@Column`(nullable = true) until the migration/backfill runs,
then switch it to nullable = false and deploy the final migration. Ensure the
migration references the CardSet table/author column and that the chosen
backfill value corresponds to a real user or a documented system user id.
In `@src/main/java/project/flipnote/cardset/model/CardSetUpdateRequest.java`:
- Around line 27-28: The managers field in CardSetUpdateRequest currently only
has `@Size`(min = 1) which doesn't prevent null, so update the validation on the
managers field (in class CardSetUpdateRequest) to require non-null by adding
`@NotNull` or use `@NotEmpty` alongside `@Size`(min = 1); also add the corresponding
import (e.g., javax.validation.constraints.NotNull or
org.hibernate.validator.constraints.NotEmpty) so null values can't bypass the
"at least one manager" rule.
In `@src/main/java/project/flipnote/cardset/model/CreateCardSetRequest.java`:
- Around line 26-27: The managers Set in CreateCardSetRequest is annotated with
`@Size`(min = 1) but that allows null, so add a null-check annotation (e.g.,
`@NotNull` or `@NotEmpty`) to the managers field in the CreateCardSetRequest class
to enforce presence; update imports to include the chosen constraint
(javax.validation.constraints.NotNull or
org.hibernate.validator.constraints.NotEmpty) and keep `@Size`(min = 1) to enforce
at least one element.
In `@src/main/java/project/flipnote/cardset/service/CardSetManagerWriter.java`:
- Around line 51-56: updateManagers currently computes diffs directly from
newManagerIds which can remove the card author as a manager; ensure the author
is always included by adding the card's author id to the set used for diffing
before computing toDelete/toAdd. Concretely, obtain the author id from cardSet
(e.g., cardSet.getAuthorId() or cardSet.getAuthor().getId()), create a copy of
newManagerIds that adds that author id (if missing), and then compute
difference(currentManagerIds, adjustedNewManagerIds) and
difference(adjustedNewManagerIds, currentManagerIds) for toDelete and toAdd
respectively in updateManagers.
src/main/java/project/flipnote/cardset/model/CardSetUpdateRequest.java
Outdated
Show resolved
Hide resolved
src/main/java/project/flipnote/cardset/model/CreateCardSetRequest.java
Outdated
Show resolved
Hide resolved
| 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); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
업데이트에서도 작성자 강제 포함 필요
현재 updateManagers는 newManagerIds에 작성자가 없으면 작성자 매니저가 삭제될 수 있습니다. “작성자는 항상 매니저”라는 규칙을 유지하려면 업데이트에서도 작성자를 포함한 집합으로 diff를 계산해야 합니다.
✅ 수정 제안
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
In `@src/main/java/project/flipnote/cardset/service/CardSetManagerWriter.java`
around lines 51 - 56, updateManagers currently computes diffs directly from
newManagerIds which can remove the card author as a manager; ensure the author
is always included by adding the card's author id to the set used for diffing
before computing toDelete/toAdd. Concretely, obtain the author id from cardSet
(e.g., cardSet.getAuthorId() or cardSet.getAuthor().getId()), create a copy of
newManagerIds that adds that author id (if missing), and then compute
difference(currentManagerIds, adjustedNewManagerIds) and
difference(adjustedNewManagerIds, currentManagerIds) for toDelete and toAdd
respectively in updateManagers.
📝 변경 내용
✅ 체크리스트
💬 기타 참고 사항
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.