Skip to content
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

[BE] 인원 수정 및 삭제 API 통합 #964

Open
wants to merge 2 commits into
base: be-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,19 @@ public void updateMembers(String token, MembersUpdateAppRequest request) {
List<EventMember> originEventMembers = eventMemberRepository.findAllByEvent(event);

updatedMembers.validateUpdatable(originEventMembers);

deleteMembers(token, originEventMembers, updatedMembers);
eventMemberRepository.saveAll(updatedMembers.getMembers());
}

private void deleteMembers(String token, List<EventMember> originEventMembers, UpdatedMembers updatedMembers) {
for (EventMember originEventMember : originEventMembers) {
if (!updatedMembers.contain(originEventMember)) {
deleteMember(token, originEventMember);
}
}
}

Comment on lines +74 to +86
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pr에 써주신 것처럼
1,2,3이 있다고 했을 때, 1은 상태 변화가 있고 2,3은 없다면. 그리고 3을 삭제하고 싶다면
1,2만 PUT 요청하면 된다는 것이죠?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞아요! 프론트 작업 끝나면 같이 머지해야겠네요.

@Transactional
public void deleteMember(String token, Long memberId) {
eventMemberRepository.findById(memberId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,9 @@ private void validateNameUnique(List<EventMember> eventMembers) {

public void validateUpdatable(List<EventMember> originEventMembers) {
Set<EventMember> uniqueEventMembers = Set.copyOf(originEventMembers);
validateUpdatedMembersExist(uniqueEventMembers);
validateUpdatedNamesUnique(uniqueEventMembers);
}

private void validateUpdatedMembersExist(Set<EventMember> originEventMembers) {
if (!this.eventMembers.equals(originEventMembers)) {
throw new HaengdongException(HaengdongErrorCode.MEMBER_UPDATE_MISMATCH);
}
}

private void validateUpdatedNamesUnique(Set<EventMember> originEventMembers) {
boolean duplicated = originEventMembers.stream()
.anyMatch(this::isMemberNameUpdated);
Expand All @@ -63,6 +56,10 @@ private boolean isMemberNameUpdated(EventMember originMembers) {
public List<EventMember> getMembers() {
return eventMembers.stream().toList();
}

public boolean contain(EventMember eventMember) {
return eventMembers.contains(eventMember);
}
}


Loading