Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/petlog/docs/ScheduleControllerDocs.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface ScheduleControllerDocs {

@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "일정 상세 내용 수정에 성공하였습니다.")
@Operation(summary = "일정 상세 내용 수정 API")
ResponseEntity<ApiResponse<Void>> updateSchedule(@PathVariable final Long groupId, @PathVariable final Long scheduleId, @RequestBody final UpdateScheduleRequestDto request);
ResponseEntity<ApiResponse<Void>> updateSchedule(@Authenticated final Long memberId, @PathVariable final Long groupId, @PathVariable final Long scheduleId, @RequestBody final UpdateScheduleRequestDto request);

@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "일정 삭제에 성공하였습니다.")
@Operation(summary = "일정 삭제 API")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.petlog.schedule.service.ScheduleService;
import com.petlog.schedule.service.dto.CreateScheduleDto;
import com.petlog.schedule.service.dto.GetScheduleInfoDto;
import com.petlog.schedule.service.dto.UpdateScheduleDto;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -76,10 +77,22 @@ public ResponseEntity<ApiResponse<GetMonthlyScheduleResponseDto>> getAllSchedule

@PatchMapping("/{scheduleId}")
public ResponseEntity<ApiResponse<Void>> updateSchedule(
@Authenticated final Long memberId,
@PathVariable final Long groupId,
@PathVariable final Long scheduleId,
@RequestBody final UpdateScheduleRequestDto request
) {
final UpdateScheduleDto dto = new UpdateScheduleDto(
request.title(),
request.isAllDay(),
request.startTime(),
request.endTime(),
request.remindNotificationAt(),
request.tag(),
request.memo()
);
scheduleService.updateSchedule(memberId, groupId, scheduleId, dto);

return ResponseEntity.ok(
ApiResponse.success(UPDATE_SCHEDULE)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public record UpdateScheduleRequestDto(
@Schema(description = "isAllDay가 true면 해당 날짜의 자정 시간으로 보내야함")
LocalDateTime endTime,

LocalDateTime remindNotificationAt,

@Schema(description = "YELLOW/GREEN/BLUE")
ScheduleType tag,

LocalDateTime remindNotificationAt,

@Schema(description = "300글자 제한")
String memo

Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/petlog/schedule/entity/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,22 @@ public Schedule(
this.type = type;
this.memo = memo;
}

public void update(
final String title,
final boolean isAllDay,
final LocalDateTime startTime,
final LocalDateTime endTime,
final LocalDateTime remindNotificationAt,
final ScheduleType tag,
final String memo
) {
this.title = title;
this.isAllDay = isAllDay;
this.startAt = startTime;
this.endAt = endTime;
this.remindAt = remindNotificationAt;
this.type = tag;
this.memo = memo;
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/petlog/schedule/service/ScheduleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.petlog.schedule.repository.ScheduleRepository;
import com.petlog.schedule.service.dto.CreateScheduleDto;
import com.petlog.schedule.service.dto.GetScheduleInfoDto;
import com.petlog.schedule.service.dto.UpdateScheduleDto;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -87,4 +88,35 @@ public List<GetScheduleInfoDto> getMonthlySchedule(final Long memberId, final Lo
))
.toList();
}

@Transactional
public void updateSchedule(final Long memberId, final Long groupId, final Long scheduleId, final UpdateScheduleDto dto) {
final Member member = getMember(memberId);
final PetGroup petGroup = getPetGroup(groupId);
getPetGroupMember(member, petGroup);

final Schedule schedule = getSchedule(scheduleId);
validateIsScheduleWriter(member, schedule);

schedule.update(
dto.title(),
dto.isAllDay(),
dto.startTime(),
dto.endTime(),
dto.remindNotificationAt(),
dto.tag(),
dto.memo()
);
}

private Schedule getSchedule(final Long scheduleId) {
return scheduleRepository.findById(scheduleId)
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 일정입니다."));
}

private void validateIsScheduleWriter(final Member member, final Schedule schedule) {
if(!schedule.getMember().equals(member)) {
throw new IllegalArgumentException("일정 작성자만 수정할 수 있습니다.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.petlog.schedule.service.dto;

import com.petlog.schedule.entity.ScheduleType;

import java.time.LocalDateTime;

public record UpdateScheduleDto(

String title,
boolean isAllDay,
LocalDateTime startTime,
LocalDateTime endTime,
LocalDateTime remindNotificationAt,
ScheduleType tag,
String memo

) {
}
Loading