-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 행사 참여자 전체 수정 로직 리펙토링 (#644)
* refactor: 행사 참여자 전체 수정 로직 리펙토링 * refactor: 메소드 분리 * refactor: UpdatedMembers 로 변경 * refactor: CurrentMember 쿼리 변경 * refactor: 변수명 변경 * test: 예외 메시지 변경 * style: 메소드 명 변경 * refactor: 배치 사이즈 조절 * refactor: Set 으로 변경 * refactor: 메소드 순서 변경 * refactor: 필요없는 객체 제거 * docs: 운영 배포 워크플로 수정 * docs: 도커 이미지 이름 변경
- Loading branch information
Showing
10 changed files
with
251 additions
and
131 deletions.
There are no files selected for viewing
This file contains 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 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
8 changes: 8 additions & 0 deletions
8
server/src/main/java/server/haengdong/application/request/MembersUpdateAppRequest.java
This file contains 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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
package server.haengdong.application.request; | ||
|
||
import java.util.List; | ||
import server.haengdong.domain.event.Event; | ||
import server.haengdong.domain.member.Member; | ||
|
||
public record MembersUpdateAppRequest(List<MemberUpdateAppRequest> members) { | ||
|
||
public List<Member> toMembers(Event event) { | ||
return members.stream() | ||
.map(memberRequest -> memberRequest.toMember(event)) | ||
.toList(); | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
server/src/main/java/server/haengdong/domain/bill/BillDetailRepository.java
This file was deleted.
Oops, something went wrong.
This file contains 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
67 changes: 67 additions & 0 deletions
67
server/src/main/java/server/haengdong/domain/member/UpdatedMembers.java
This file contains 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,67 @@ | ||
package server.haengdong.domain.member; | ||
|
||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import server.haengdong.exception.HaengdongErrorCode; | ||
import server.haengdong.exception.HaengdongException; | ||
|
||
public class UpdatedMembers { | ||
|
||
private final Set<Member> members; | ||
|
||
public UpdatedMembers(List<Member> members) { | ||
validateMemberUnique(members); | ||
validateNameUnique(members); | ||
this.members = new HashSet<>(members); | ||
} | ||
|
||
private void validateMemberUnique(List<Member> members) { | ||
if (members.size() != Set.copyOf(members).size()) { | ||
throw new HaengdongException(HaengdongErrorCode.MEMBER_NAME_CHANGE_DUPLICATE); | ||
} | ||
} | ||
|
||
private void validateNameUnique(List<Member> members) { | ||
Set<String> uniqueNames = members.stream() | ||
.map(Member::getName) | ||
.collect(Collectors.toSet()); | ||
if (members.size() != uniqueNames.size()) { | ||
throw new HaengdongException(HaengdongErrorCode.MEMBER_NAME_CHANGE_DUPLICATE); | ||
} | ||
} | ||
|
||
public void validateUpdatable(List<Member> originMembers) { | ||
Set<Member> uniqueMembers = Set.copyOf(originMembers); | ||
validateUpdatedMembersExist(uniqueMembers); | ||
validateUpdatedNamesUnique(uniqueMembers); | ||
} | ||
|
||
private void validateUpdatedMembersExist(Set<Member> originMembers) { | ||
if (!this.members.equals(originMembers)) { | ||
throw new HaengdongException(HaengdongErrorCode.MEMBER_UPDATE_MISMATCH); | ||
} | ||
} | ||
|
||
private void validateUpdatedNamesUnique(Set<Member> originMembers) { | ||
boolean duplicated = originMembers.stream() | ||
.anyMatch(this::isMemberNameUpdated); | ||
|
||
if (duplicated) { | ||
throw new HaengdongException(HaengdongErrorCode.MEMBER_NAME_DUPLICATE); | ||
} | ||
} | ||
|
||
private boolean isMemberNameUpdated(Member originMembers) { | ||
return this.members.stream() | ||
.filter(member -> !member.getId().equals(originMembers.getId())) | ||
.anyMatch(member -> member.hasName(originMembers.getName())); | ||
} | ||
|
||
public List<Member> getMembers() { | ||
return members.stream().toList(); | ||
} | ||
} | ||
|
||
|
This file contains 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 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.