From 0a15b8865396d693db6b643287caca58f67da183 Mon Sep 17 00:00:00 2001 From: yxhwxn Date: Tue, 6 Aug 2024 20:27:36 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EC=84=A4=EB=AC=B8=20=EA=B8=B0=EB=B0=98?= =?UTF-8?q?=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EC=82=AD=EC=A0=9C=20API=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cmc/suppin/event/events/controller/EventApi.java | 7 +++++++ .../event/events/controller/dto/EventResponseDTO.java | 1 + .../suppin/event/events/converter/EventConverter.java | 1 + .../cmc/suppin/event/events/service/EventService.java | 10 ++++++++++ 4 files changed, 19 insertions(+) diff --git a/src/main/java/com/cmc/suppin/event/events/controller/EventApi.java b/src/main/java/com/cmc/suppin/event/events/controller/EventApi.java index 011b18c..d8f88fa 100644 --- a/src/main/java/com/cmc/suppin/event/events/controller/EventApi.java +++ b/src/main/java/com/cmc/suppin/event/events/controller/EventApi.java @@ -59,4 +59,11 @@ public ResponseEntity> 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> deleteEvent(@PathVariable Long eventId, @CurrentAccount Account account) { + eventService.deleteEvent(eventId, account.userId()); + return ResponseEntity.ok(ApiResponse.of(ResponseCode.SUCCESS)); + } } diff --git a/src/main/java/com/cmc/suppin/event/events/controller/dto/EventResponseDTO.java b/src/main/java/com/cmc/suppin/event/events/controller/dto/EventResponseDTO.java index 7fa0fdb..3645962 100644 --- a/src/main/java/com/cmc/suppin/event/events/controller/dto/EventResponseDTO.java +++ b/src/main/java/com/cmc/suppin/event/events/controller/dto/EventResponseDTO.java @@ -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; diff --git a/src/main/java/com/cmc/suppin/event/events/converter/EventConverter.java b/src/main/java/com/cmc/suppin/event/events/converter/EventConverter.java index 4d27c34..9b828a1 100644 --- a/src/main/java/com/cmc/suppin/event/events/converter/EventConverter.java +++ b/src/main/java/com/cmc/suppin/event/events/converter/EventConverter.java @@ -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()) diff --git a/src/main/java/com/cmc/suppin/event/events/service/EventService.java b/src/main/java/com/cmc/suppin/event/events/service/EventService.java index 8f25fb7..d4ba61a 100644 --- a/src/main/java/com/cmc/suppin/event/events/service/EventService.java +++ b/src/main/java/com/cmc/suppin/event/events/service/EventService.java @@ -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); + } }