Skip to content

Commit

Permalink
Merge pull request #275 from 9oormthon-univ/fix/#273
Browse files Browse the repository at this point in the history
fix: schedule 동적 update되도록 수정
  • Loading branch information
koosco authored Dec 6, 2024
2 parents 77d1e93 + d795d11 commit be8309f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/com/groom/orbit/schedule/dao/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +26,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Builder
@DynamicUpdate
@Table(name = "schedule")
public class Schedule {

Expand All @@ -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;
}
}
}

0 comments on commit be8309f

Please sign in to comment.