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] 미팅 생성 #102

Merged
merged 14 commits into from
May 4, 2024
Merged

[BE] 미팅 생성 #102

merged 14 commits into from
May 4, 2024

Conversation

320Hwany
Copy link
Member

@320Hwany 320Hwany commented May 3, 2024

#️⃣연관된 이슈

#70

📝작업 내용

단일 미팅 생성
정기 미팅 생성
미팅 생성시 미팅 참여 목록 등록
미팅 생성시 참여한 회원의 스케줄 등록
스케줄 반환 필드 수정
테스트 코드 작성

💬리뷰 요구사항(선택)

미팅 생성시 미팅 뿐만 아니라 참여 회원 정보 등록/스케줄 등록등의 부가 작업을 해주어야 해서 조금 복잡합니다.
또 1회 미팅인지 정기 미팅인지에 따라 등록 정보가 달라집니다.
MeetingManager 에서 이 작업을 하기 때문에 여기 로직 위주로 봐주시면 될 것 같습니당

@320Hwany 320Hwany added feat⚙️ 기능 추가 refactor 리팩토링 labels May 3, 2024
@320Hwany 320Hwany requested review from Anak-2 and jerry3269 May 3, 2024 08:54
@320Hwany 320Hwany self-assigned this May 3, 2024
@320Hwany 320Hwany force-pushed the be/feat/meeting-create branch 5 times, most recently from 49a58d4 to 0a23d7a Compare May 3, 2024 15:08
@320Hwany 320Hwany force-pushed the be/feat/meeting-create branch from 0a23d7a to 0bb83d0 Compare May 4, 2024 00:49
Copy link
Contributor

@Anak-2 Anak-2 left a comment

Choose a reason for hiding this comment

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

잘 봤습니다!

Comment on lines 85 to 100
private void createSchedules(final String moimTitle, final MeetingJpaEntity meetingJpaEntity) {
List<Long> memberIds = joinedMeetingFinder.findAllMemberId(meetingJpaEntity.getId());
List<CompletableFuture<Void>> futures = new ArrayList<>();

for (long memberId : memberIds) {
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
ScheduleJpaEntity scheduleJpaEntity = ScheduleJpaEntity.toEntity(memberId, moimTitle, meetingJpaEntity);
scheduleAppender.createSchedule(scheduleJpaEntity);
});

futures.add(future);
}

CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

비동기로 처리하는 부분이 인상깊네여

Comment on lines 13 to 40
class JoinedMeetingManagerTest extends ImplementTest {

@Autowired
private JoinedMeetingAppender joinedMeetingAppender;

@DisplayName("모임 참여자를 바탕으로 미팅 참여 정보를 추가한다.")
@Test
void saveJoinedMeeting() {
// given
long moimId = 1L;
long meetingId = 2L;

for (long i = 0; i < 3; i++) {
JoinedMoimJpaEntity joinedMoimJpaEntity = JoinedMoimJpaEntity.builder()
.memberId(i)
.moimId(moimId)
.build();

joinedMoimRepository.save(joinedMoimJpaEntity);
}

// when
joinedMeetingAppender.saveJoinedMeeting(moimId, meetingId);

// then
assertThat(joinedMeetingRepository.count()).isEqualTo(3);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

JoinedMeetingManager 테스트인데 Appender 만 쓰고있고, JoinedMeetingManager 파일이 기존과, 생성된 것이 없는 것 같은데 한번 확인 부탁드려요!

Copy link
Member Author

Choose a reason for hiding this comment

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

헉 그러게요 ㅋㅋㅋ 삭제하겠습니당

Copy link
Contributor

@jerry3269 jerry3269 left a comment

Choose a reason for hiding this comment

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

👍 잘봣습니당

Comment on lines 27 to 31
for (long memberId : memberIds) {
JoinedMeetingJpaEntity joinedMeetingJpaEntity =
JoinedMeetingJpaEntity.toEntity(meetingId, memberId, true);
joinedMeetingRepository.save(joinedMeetingJpaEntity);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

이러면 조회된 ID만큼 save가 날라갈 것 같은데, saveAll을 호출하는게 좋을 것 같습니당

Copy link
Member Author

Choose a reason for hiding this comment

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

네넹 수정하는게 좋을 것 같네용

Comment on lines +55 to +83
private void createSingleMeeting(final MeetingCreateRequest meetingCreateRequest, final String moimTitle) {
MeetingJpaEntity meetingJpaEntity = meetingCreateRequest.toEntity(
meetingCreateRequest.startDateTime(),
meetingCreateRequest.endDateTime()
);

meetingAppender.saveMeeting(meetingJpaEntity);
joinedMeetingAppender.saveJoinedMeeting(meetingCreateRequest.moimId(), meetingJpaEntity.getId());
createSchedules(moimTitle, meetingJpaEntity);
}

private void createRegularMeeting(final MeetingCreateRequest meetingCreateRequest, final String moimTitle) {
MoimDateResponse moimDateResponse = moimFinder.findMoimDate(meetingCreateRequest.moimId());
LocalDate startDate = moimDateResponse.startDate();
LocalDate endDate = moimDateResponse.endDate();

LocalTime startTime = meetingCreateRequest.startDateTime().toLocalTime();
LocalTime endTime = meetingCreateRequest.endDateTime().toLocalTime();

for (LocalDate date = startDate; !date.isAfter(endDate); date = date.plusWeeks(ONE_WEEK.time())) {
LocalDateTime startDateTime = LocalDateTime.of(date, startTime);
LocalDateTime endDateTime = LocalDateTime.of(date, endTime);

MeetingJpaEntity meetingJpaEntity = meetingCreateRequest.toEntity(startDateTime, endDateTime);
meetingAppender.saveMeeting(meetingJpaEntity);
joinedMeetingAppender.saveJoinedMeeting(meetingCreateRequest.moimId(), meetingJpaEntity.getId());
createSchedules(moimTitle, meetingJpaEntity);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

이부분 전체 트랜잭션을 고민해봐야 할것 같습니다.
전체 트랜잭션을 안 걸게되면 롤백 시 중복 저장이 될 수 도 있을 것 같습니다.
일정 생성시 겹치는 일정이 있으면 예외를 던지지 않고 넘어가고 전체적으로 트랜잭션을 걸어야 할 것 같습니당.

Copy link
Member Author

Choose a reason for hiding this comment

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

네넵 예외처리 발생할 때 비동기로 그냥 넘어가도록 했는데 중간에 예외 발생할 수도 있을 것 같아서 하나로 묶을게용

@320Hwany 320Hwany force-pushed the be/feat/meeting-create branch from 4ee58bf to 5c7f6e2 Compare May 4, 2024 05:39
@320Hwany 320Hwany merged commit 3e509b1 into backend-main May 4, 2024
1 check passed
@320Hwany 320Hwany deleted the be/feat/meeting-create branch May 4, 2024 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat⚙️ 기능 추가 refactor 리팩토링
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants