diff --git a/src/main/java/com/groom/orbit/schedule/app/ScheduleCommandService.java b/src/main/java/com/groom/orbit/schedule/app/ScheduleCommandService.java index 49c88e7..23b3e3a 100644 --- a/src/main/java/com/groom/orbit/schedule/app/ScheduleCommandService.java +++ b/src/main/java/com/groom/orbit/schedule/app/ScheduleCommandService.java @@ -37,13 +37,12 @@ public CommonSuccessDto createSchedule(Long memberId, ScheduleRequestDto request return CommonSuccessDto.fromEntity(true); } - public CommonSuccessDto updateSchedule( - Long memberId, Long scheduleId, ScheduleRequestDto requestDto) { + public CommonSuccessDto updateSchedule(Long memberId, Long scheduleId, ScheduleRequestDto dto) { Schedule schedule = scheduleQueryService.findSchedule(scheduleId); Member member = schedule.getMember(); member.validateId(memberId); - schedule.updateSchedule(requestDto); + schedule.update(dto.content(), dto.startDate(), dto.endDate()); return CommonSuccessDto.fromEntity(true); } @@ -53,7 +52,7 @@ public CommonSuccessDto deleteSchedule(Long memberId, Long scheduleId) { Member member = schedule.getMember(); member.validateId(memberId); - scheduleRepository.deleteById(scheduleId); + scheduleRepository.delete(schedule); return CommonSuccessDto.fromEntity(true); } diff --git a/src/main/java/com/groom/orbit/schedule/dao/Schedule.java b/src/main/java/com/groom/orbit/schedule/dao/Schedule.java index 7883638..032a100 100644 --- a/src/main/java/com/groom/orbit/schedule/dao/Schedule.java +++ b/src/main/java/com/groom/orbit/schedule/dao/Schedule.java @@ -12,8 +12,9 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; +import org.hibernate.annotations.DynamicUpdate; + import com.groom.orbit.member.dao.jpa.entity.Member; -import com.groom.orbit.schedule.app.dto.ScheduleRequestDto; import lombok.AllArgsConstructor; import lombok.Builder; @@ -25,6 +26,7 @@ @NoArgsConstructor @AllArgsConstructor @Builder +@DynamicUpdate @Table(name = "schedule") public class Schedule { @@ -45,9 +47,15 @@ public class Schedule { @JoinColumn(name = "member_id") private Member member; - public void updateSchedule(ScheduleRequestDto requestDto) { - this.content = requestDto.content(); - this.startDate = requestDto.startDate(); - this.endDate = requestDto.endDate(); + public void update(String content, LocalDate startDate, LocalDate endDate) { + if (content != null) { + this.content = content; + } + if (startDate != null) { + this.startDate = startDate; + } + if (endDate != null) { + this.endDate = endDate; + } } }