Skip to content

Commit

Permalink
Merge pull request #302 from Hous-Release/fix/#301
Browse files Browse the repository at this point in the history
#301 [fix] Rule 수정시 이름 중복 검사 로직 수정
  • Loading branch information
orijoon98 authored Feb 24, 2023
2 parents 82bd677 + c4ecd0b commit a98bddb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/hous/server/service/rule/RuleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void createRule(CreateRuleRequestDto request, Long userId) {
public void updateRules(UpdateRuleRequestDto request, Long userId) {
User user = UserServiceUtils.findUserById(userRepository, userId);
Room room = RoomServiceUtils.findParticipatingRoom(user);
RuleServiceUtils.existsRuleByRoomRules(room, request.getRules().stream().map(RuleInfo::getName).collect(Collectors.toList()));
RuleServiceUtils.existsRuleByRules(request.getRules().stream().map(RuleInfo::getName).collect(Collectors.toList()));
for (int idx = 0; idx < request.getRules().size(); idx++) {
Rule rule = RuleServiceUtils.findRuleByIdAndRoom(ruleRepository, request.getRules().get(idx).getId(), room);
RuleServiceUtils.validateRuleName(room, request.getRules().get(idx).getName());
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/hous/server/service/rule/RuleServiceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -53,8 +54,14 @@ public static void existsRuleByRoomRules(Room room, List<String> requestRules) {
List<String> rules = room.getRules().stream().map(Rule::getName).collect(Collectors.toList());
for (String ruleName : requestRules) {
if (rules.contains(ruleName)) {
throw new ConflictException(String.format("방 (%s) 에 이미 존재하는 todo (%s) 입니다.", room.getId(), ruleName), CONFLICT_RULE_EXCEPTION);
throw new ConflictException(String.format("방 (%s) 에 이미 존재하는 규칙 (%s) 입니다.", room.getId(), ruleName), CONFLICT_RULE_EXCEPTION);
}
}
}

public static void existsRuleByRules(List<String> requestRules) {
if (requestRules.size() != new HashSet<>(requestRules).size()) {
throw new ConflictException("규칙 이름 중복입니다.", CONFLICT_RULE_EXCEPTION);
}
}
}

0 comments on commit a98bddb

Please sign in to comment.