Skip to content

Commit

Permalink
Feat: 설문 기반 이벤트 삭제 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
yxhwxn committed Aug 6, 2024
1 parent dc8d973 commit 0a15b88
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,11 @@ public ResponseEntity<ApiResponse<Void>> updateEvent(@PathVariable Long eventId,
eventService.updateEvent(eventId, request, account.userId());
return ResponseEntity.ok(ApiResponse.of(ResponseCode.SUCCESS));
}

@DeleteMapping("/{eventId}")
@Operation(summary = "이벤트 삭제 API", description = "PathVariable: eventId, JWT 토큰만 주시면 됩니다.")
public ResponseEntity<ApiResponse<Void>> deleteEvent(@PathVariable Long eventId, @CurrentAccount Account account) {
eventService.deleteEvent(eventId, account.userId());
return ResponseEntity.ok(ApiResponse.of(ResponseCode.SUCCESS));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class EventResponseDTO {
@NoArgsConstructor
@AllArgsConstructor
public static class EventInfoDTO {
private Long eventId;
private EventType type;
private String title;
private String url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public static EventResponseDTO.CommentEventDetailDTO toEventDetailDTO(Event even
public static EventResponseDTO.EventInfoDTO toEventInfoDTO(Event event) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
return EventResponseDTO.EventInfoDTO.builder()
.eventId(event.getId())
.type(event.getType())
.title(event.getTitle())
.url(event.getUrl())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,14 @@ public void updateEvent(Long eventId, EventRequestDTO.EventUpdateDTO request, St
updatedEvent.setId(event.getId()); // 유지하려는 ID 설정
eventRepository.save(updatedEvent);
}

public void deleteEvent(Long eventId, String userId) {
Member member = memberRepository.findByUserIdAndStatusNot(userId, UserStatus.DELETED)
.orElseThrow(() -> new IllegalArgumentException("Member not found"));

Event event = eventRepository.findByIdAndMemberId(eventId, member.getId())
.orElseThrow(() -> new IllegalArgumentException("Event not found"));

eventRepository.delete(event);
}
}

0 comments on commit 0a15b88

Please sign in to comment.