Skip to content

Commit

Permalink
[#30] refactor: 모임 유저 확정시 최대인원수 초과 validation추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sss4920 committed Dec 6, 2024
1 parent dd9328a commit 81ed513
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.office.networkoffice.gathering.controller.dto.request;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ public List<User> getConfiremedUserList() {
.toList();
}

public int getPresentGatheringMemberCount(){
return getConfiremedUserList().size();
}

private boolean isConfirmedUser(GatheringUser gatheringUser) {
return gatheringUser.getGatheringUserStatus()
.equals(GatheringUserStatus.CONFIRMED_USER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import dev.office.networkoffice.gatheringUser.domain.GatheringUser;
import dev.office.networkoffice.gatheringUser.domain.GatheringUserStatus;
import dev.office.networkoffice.gatheringUser.repository.GatheringUserRepository;
import dev.office.networkoffice.gatheringUser.service.GatheringUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -38,7 +37,7 @@ public GatheringResponseDto createGathering(Long userId, GatheringDto dto) {
User host = findUserById(userId);
Gathering gathering = createGatheringByRequest(dto, host);
Gathering savedGathering = gatheringRepository.save(gathering);
GatheringUser gatheringUser= gatheringUserRepository.save(
GatheringUser gatheringUser = gatheringUserRepository.save(
savedGathering.createGatheringUserByHost()
);
gatheringUser.updateApplicantStatus(GatheringUserStatus.CONFIRMED_USER, "호스트입니다.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ private void deportApplicants(String reason) {
}

private void confirmApplicants() {
checkMaxMembers();
this.gatheringUserStatus = GatheringUserStatus.CONFIRMED_USER;
}

Expand All @@ -90,4 +91,8 @@ public boolean isEligibleForReapplication() {
GatheringUserStatus status = gatheringUserStatus;
return !(status == GatheringUserStatus.DEPORTATION_USER || status == GatheringUserStatus.BLOCKED_USER);
}

private void checkMaxMembers() {
Assert.isTrue(gathering.getPresentGatheringMemberCount() + 1 <= gathering.getMaxMembers(), "모임 최대 인원을 초과했습니다.");
}
}

0 comments on commit 81ed513

Please sign in to comment.