Skip to content

Commit

Permalink
Merge pull request #338 from Namo-log/feature/337
Browse files Browse the repository at this point in the history
[Feature/337] 일정 삭제 API 구현
  • Loading branch information
hosunglee222 authored Sep 26, 2024
2 parents 153566c + 4a1ab9c commit 90272a4
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@ ResponseDto<Long> createPersonalSchedule(
@ApiErrorCodes(value = {
ErrorStatus.INVALID_FORMAT_FAILURE})
ResponseDto<List<PersonalScheduleResponse.GetMonthlyScheduleDto>> getMyMonthlySchedules(
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate endDate,
@RequestParam LocalDate startDate,
@RequestParam LocalDate endDate,
@AuthenticationPrincipal SecurityUserDetails member);

@Operation(summary = "개인 캘린더 - 친구 생일 조회", description = "친구 생일을 조회합니다.")
ResponseDto<List<PersonalScheduleResponse.GetMonthlyFriendBirthdayDto>> getMonthlyFriendsBirthday(
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate endDate,
@RequestParam LocalDate startDate,
@RequestParam LocalDate endDate,
@AuthenticationPrincipal SecurityUserDetails member);

@Operation(summary = "친구 캘린더 조회", description = "친구의 캘린더을 조회합니다.")
@ApiErrorCodes(value = {ErrorStatus.NOT_FRIENDSHIP_MEMBER})
ResponseDto<List<PersonalScheduleResponse.GetFriendMonthlyScheduleDto>> getFriendMonthlySchedules(
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate endDate,
@RequestParam LocalDate startDate,
@RequestParam LocalDate endDate,
@Parameter(description = "친구 유저 ID") @RequestParam Long memberId,
@AuthenticationPrincipal SecurityUserDetails member);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.MediaType;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -78,8 +79,8 @@ public ResponseDto<List<MeetingScheduleResponse.GetMeetingScheduleSummaryDto>> g
})
@GetMapping(path = "/preview")
public ResponseDto<List<MeetingScheduleResponse.GetMonthlyMembersScheduleDto>> getMonthlyParticipantSchedules(
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate endDate,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate,
@RequestParam List<Long> participantIds,
@AuthenticationPrincipal SecurityUserDetails memberInfo) {
return ResponseDto.onSuccess(
Expand All @@ -96,8 +97,8 @@ public ResponseDto<List<MeetingScheduleResponse.GetMonthlyMembersScheduleDto>> g
@GetMapping(path = "/{meetingScheduleId}/calender")
public ResponseDto<List<MeetingScheduleResponse.GetMonthlyMeetingParticipantScheduleDto>> getMonthlyMeetingParticipantSchedules(
@PathVariable Long meetingScheduleId,
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate endDate,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate,
@AuthenticationPrincipal SecurityUserDetails memberInfo) {
return ResponseDto.onSuccess(
meetingScheduleUsecase.getMonthlyMeetingParticipantSchedules(meetingScheduleId, startDate, endDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

import java.time.LocalDate;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.Valid;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.MediaType;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -53,8 +52,8 @@ public ResponseDto<Long> createPersonalSchedule(
*/
@GetMapping("/calendar")
public ResponseDto<List<PersonalScheduleResponse.GetMonthlyScheduleDto>> getMyMonthlySchedules(
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate endDate,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate,
@AuthenticationPrincipal SecurityUserDetails member) {
return ResponseDto.onSuccess(personalScheduleUsecase.getMyMonthlySchedules(startDate, endDate, member));
}
Expand All @@ -65,8 +64,8 @@ public ResponseDto<List<PersonalScheduleResponse.GetMonthlyScheduleDto>> getMyMo
*/
@GetMapping("/calendar/friends/birthdays")
public ResponseDto<List<PersonalScheduleResponse.GetMonthlyFriendBirthdayDto>> getMonthlyFriendsBirthday(
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate endDate,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate,
@AuthenticationPrincipal SecurityUserDetails member) {
return ResponseDto.onSuccess(personalScheduleUsecase.getMonthlyFriendsBirthday(startDate, endDate, member));
}
Expand All @@ -76,8 +75,8 @@ public ResponseDto<List<PersonalScheduleResponse.GetMonthlyFriendBirthdayDto>> g
*/
@GetMapping("/calendar/friends")
public ResponseDto<List<PersonalScheduleResponse.GetFriendMonthlyScheduleDto>> getFriendMonthlySchedules(
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") LocalDate endDate,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate,
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate,
@RequestParam Long memberId,
@AuthenticationPrincipal SecurityUserDetails member) {
return ResponseDto.onSuccess(personalScheduleUsecase.getFriendMonthlySchedules(startDate, endDate, memberId, member));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public ResponseDto<ScheduleResponse.ScheduleSummaryDto> getScheduleSummary(
NOT_SCHEDULE_PARTICIPANT,
NOT_FOUND_MOBILE_DEVICE_FAILURE,
NOT_SUPPORTED_DEVICE_TYPE

})
@PutMapping("/{scheduleId}/notifications")
public ResponseDto<String> updateScheduleReminder(@Parameter(description = "일정 ID") @PathVariable Long scheduleId,
Expand All @@ -53,4 +52,17 @@ public ResponseDto<String> updateScheduleReminder(@Parameter(description = "일
return ResponseDto.onSuccess("알림 수정 성공");
}

@Operation(summary = "일정 삭제", description = "일정을 삭제합니다.")
@ApiErrorCodes(value = {
NOT_FOUND_SCHEDULE_FAILURE,
NOT_SCHEDULE_PARTICIPANT,
NOT_SCHEDULE_OWNER
})
@DeleteMapping("/{scheduleId}")
public ResponseDto<String> deleteSchedule(@Parameter(description = "일정 ID") @PathVariable Long scheduleId,
@AuthenticationPrincipal SecurityUserDetails member) {
scheduleUsecase.deleteSchedule(scheduleId, member);
return ResponseDto.onSuccess("일정 삭제 성공");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,9 @@ public Participant validateAndGetScheduleOwner(Schedule schedule, Long memberId)
return participant;
}

public void deleteSchedule(Schedule schedule, Long memberId){
validateAndGetScheduleOwner(schedule, memberId);
scheduleService.deleteSchedule(schedule.getId());
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.namo.spring.application.external.api.schedule.usecase;

import com.namo.spring.application.external.api.schedule.service.ScheduleManageService;
import com.namo.spring.core.common.code.status.ErrorStatus;
import com.namo.spring.db.mysql.domains.schedule.entity.Schedule;
import com.namo.spring.db.mysql.domains.schedule.exception.ScheduleException;
import com.namo.spring.db.mysql.domains.schedule.service.ScheduleService;
import com.namo.spring.db.mysql.domains.schedule.type.ParticipantRole;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -23,6 +29,7 @@ public class ScheduleUsecase {
private final MemberManageService memberManageService;
private final NotificationManageService notificationManageService;
private final ParticipantManageService participantManageService;
private final ScheduleManageService scheduleManageService;

@Transactional(readOnly = true)
public ScheduleResponse.ScheduleSummaryDto getScheduleSummary(Long memberId, Long scheduleId) {
Expand All @@ -37,4 +44,10 @@ public void updateOrCreateScheduleReminder(ScheduleRequest.PutScheduleReminderDt
notificationManageService.updateOrCreateScheduleReminderNotification(scheduleId, member,
dto.getReminderTrigger());
}

@Transactional
public void deleteSchedule(Long scheduleId, SecurityUserDetails memberInfo) {
Schedule schedule= scheduleManageService.getSchedule(scheduleId);
scheduleManageService.deleteSchedule(schedule, memberInfo.getUserId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Arrays;
import java.util.List;

import com.namo.spring.db.mysql.domains.notification.entity.Notification;
import com.namo.spring.db.mysql.domains.schedule.type.ScheduleType;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
Expand Down Expand Up @@ -62,11 +63,14 @@ public class Schedule extends BaseTimeEntity {
private String participantNicknames;

@OneToMany(mappedBy = "schedule", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Activity> activityList;
private List<Activity> activityList = new ArrayList<>();

@OneToMany(mappedBy = "schedule")
@OneToMany(mappedBy = "schedule", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Participant> participantList = new ArrayList<>();

@OneToMany(mappedBy = "schedule", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Notification> notifications = new ArrayList<>();

@Builder
public Schedule(String title, Period period, Location location, int scheduleType, String imageUrl,
Integer participantCount, String participantNicknames) {
Expand Down

0 comments on commit 90272a4

Please sign in to comment.