Skip to content

Commit

Permalink
fix: 일정 상세 로직 수정 (빈 리스트도 가능하게끔, 더불어서 삭제 제대로 동작하도록 수정)
Browse files Browse the repository at this point in the history
  • Loading branch information
k9want committed Sep 23, 2024
1 parent 2fe56e7 commit 69e77da
Showing 1 changed file with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,23 @@ public ArticleScheduleUpdateResponse updateSchedules(Long userId, Long articleId
for (ArticleSchedule existingSchedule : existingSchedules) {
// 기존 일정에는 있는데 요청에 없다면? 삭제 처리
if (!requestMap.containsKey(existingSchedule.getId())) {
existingSchedule.delete(user);
articleScheduleJpaRepository.save(ArticleScheduleEntity.from(existingSchedule.delete(user)));
}
}

// (3) 작성, 수정 처리
for (ArticleScheduleRequest request : requests) {
ArticleSchedule articleSchedule;
if (request.scheduleId() == null) {
// id x -> 새로운 일정 생성
articleSchedule = ArticleSchedule.create(user, article, request);
} else {
// id o -> 기존 일정 수정
articleSchedule = getExistingScheduleById(existingSchedules, request.scheduleId()).update(user, request);
if (!requests.isEmpty()) {
// (3) 작성, 수정 처리
for (ArticleScheduleRequest request : requests) {
ArticleSchedule articleSchedule;
if (request.scheduleId() == null) {
// id x -> 새로운 일정 생성
articleSchedule = ArticleSchedule.create(user, article, request);
} else {
// id o -> 기존 일정 수정
articleSchedule = getExistingScheduleById(existingSchedules, request.scheduleId()).update(user, request);
}
articleScheduleJpaRepository.save(ArticleScheduleEntity.from(articleSchedule));
}
articleScheduleJpaRepository.save(ArticleScheduleEntity.from(articleSchedule));
}

return ArticleScheduleUpdateResponse.from(articleEntity.getId());
Expand Down

0 comments on commit 69e77da

Please sign in to comment.