Skip to content

Commit

Permalink
♻️ Recycle: 기존 모임 참여자 수정 로직과 모임 참여자 생성 로직 통합
Browse files Browse the repository at this point in the history
<footer>
- 관련: #419
  • Loading branch information
joowojr committed Dec 1, 2024
1 parent a0b9c01 commit 3a62e8c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public ResponseDto<String> inviteMeetingParticipants(
@PathVariable Long meetingScheduleId,
@Valid @RequestBody MeetingScheduleRequest.PostMeetingParticipantsDto request,
@AuthenticationPrincipal SecurityUserDetails memberInfo) {
validateParticipantCount(request.getParticipants().size());
validateUniqueParticipantIds(memberInfo.getUserId(), request.getParticipants());
meetingScheduleUsecase.createMeetingParticipants(meetingScheduleId, request, memberInfo);
return ResponseDto.onSuccess("모임 초대 성공");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.namo.spring.application.external.api.schedule.service;

import com.namo.spring.application.external.api.record.enums.DiaryFilter;
import com.namo.spring.application.external.api.schedule.dto.MeetingScheduleRequest;
import com.namo.spring.application.external.global.utils.PeriodValidationUtils;
import com.namo.spring.core.common.code.status.ErrorStatus;
import com.namo.spring.db.mysql.domains.schedule.entity.Participant;
import com.namo.spring.db.mysql.domains.schedule.entity.Schedule;
import com.namo.spring.db.mysql.domains.schedule.exception.ParticipantException;
import com.namo.spring.db.mysql.domains.schedule.exception.ScheduleException;
import com.namo.spring.db.mysql.domains.schedule.service.ParticipantService;
import com.namo.spring.db.mysql.domains.schedule.type.ParticipantRole;
import com.namo.spring.db.mysql.domains.schedule.type.Period;
import com.namo.spring.db.mysql.domains.user.entity.Friendship;
import com.namo.spring.db.mysql.domains.user.entity.Member;
Expand All @@ -26,6 +26,8 @@
import java.util.List;
import java.util.stream.Collectors;

import static com.namo.spring.application.external.global.utils.MeetingParticipantValidationUtils.validateParticipantCount;

@Slf4j
@Service
@RequiredArgsConstructor
Expand All @@ -39,6 +41,8 @@ public void createScheduleOwner(Member member, Schedule schedule, Long categoryI
}

public void createMeetingParticipants(Member owner, Schedule schedule, List<Long> memberIds){
// 방장의 인원 제외하고 참여자 계산
validateParticipantCount(schedule.getParticipantCount() - 1 + memberIds.size());
List<Member> participants = getFriendshipValidatedParticipants(owner.getId(), memberIds);
participantMaker.makeMeetingScheduleParticipants(schedule, participants);
List<String> participantNicknames = new ArrayList<>();
Expand All @@ -56,6 +60,22 @@ public List<Member> getFriendshipValidatedParticipants(Long ownerId, List<Long>
return friends;
}

/**
* 모임 일정에 대한 모든 참여자의 ID를 반환합니다,
* 반환 값에는 활성, 비활성 모든 상태의 참여자가 포함됩니다.
* 모임 일정 초대 인원 수를 검증하기 위해 사용합니다.
*
* @param scheduleId
* @return 모임 일정에 대한 모든 참여자의 ID 배열
*/
public List<Long> getScheduleParticipantIds(Long scheduleId) {
return participantService.readParticipantsByScheduleId(scheduleId).stream()
.filter(participant -> participant.getIsOwner() == ParticipantRole.NON_OWNER.getValue())
.map(Participant::getMember)
.map(Member::getId)
.collect(Collectors.toList());
}

/**
* scheduleId와 memberId로 찾은
* Participant 객체를 Member, Schedule과 함께 로딩하여 반환합니다.
Expand All @@ -74,14 +94,6 @@ public void deleteParticipant(Participant participant, Schedule schedule) {
schedule.removeParticipant(participant.getMember().getNickname());
}

public void updateMeetingScheduleParticipants(Long ownerId, Schedule schedule,
MeetingScheduleRequest.PatchMeetingScheduleDto dto) {
if (!dto.getParticipantsToAdd().isEmpty()) {
List<Member> participantsToAdd = getFriendshipValidatedParticipants(ownerId, dto.getParticipantsToAdd());
participantMaker.makeMeetingScheduleParticipants(schedule, participantsToAdd);
}
}

private void removeParticipants(Schedule schedule, List<Participant> participants) {
List<User> users = participants.stream().map(Participant::getUser).collect(Collectors.toList());
schedule.removeParticipants(users.stream().map(User::getNickname).collect(Collectors.toList()));
Expand Down

0 comments on commit 3a62e8c

Please sign in to comment.