diff --git a/src/main/java/com/bm/getin/controller/AdminController.java b/src/main/java/com/bm/getin/controller/AdminController.java index 7b99143..1c5fcea 100644 --- a/src/main/java/com/bm/getin/controller/AdminController.java +++ b/src/main/java/com/bm/getin/controller/AdminController.java @@ -4,8 +4,6 @@ import com.bm.getin.constant.ErrorCode; import com.bm.getin.constant.EventStatus; import com.bm.getin.constant.PlaceType; -import com.bm.getin.domain.Admin; -import com.bm.getin.domain.Event; import com.bm.getin.domain.Place; import com.bm.getin.dto.*; import com.bm.getin.exception.GeneralException; @@ -84,6 +82,21 @@ public String upsertPlace( return "redirect:/admin/confirm"; } + @ResponseStatus(HttpStatus.SEE_OTHER) + @PostMapping("/places/{placeId}/delete") + public String deletePlace( + @PathVariable Long placeId, + RedirectAttributes redirectAttributes + ) { + placeService.removePlace(placeId); + + redirectAttributes.addFlashAttribute("adminOperationStatus", AdminOperationStatus.DELETE); + redirectAttributes.addFlashAttribute("redirectUrl", "/admin/places"); + + return "redirect:/admin/confirm"; + } + + @GetMapping("/places/{placeId}/newEvent") public String newEvent(@PathVariable Long placeId, Model model) { EventResponse event = placeService.getPlace(placeId) @@ -99,13 +112,13 @@ public String newEvent(@PathVariable Long placeId, Model model) { @ResponseStatus(HttpStatus.SEE_OTHER) @PostMapping("/places/{placeId}/events") - public String createEvent( + public String upsertEvent( @Valid EventRequest eventRequest, @PathVariable Long placeId, RedirectAttributes redirectAttributes ) { AdminOperationStatus status = eventRequest.id() != null ? AdminOperationStatus.MODIFY : AdminOperationStatus.CREATE; - eventService.createEvent(eventRequest.toDto(PlaceDto.idOnly(placeId))); + eventService.upsertEvent(eventRequest.toDto(PlaceDto.idOnly(placeId))); redirectAttributes.addFlashAttribute("adminOperationStatus", status); redirectAttributes.addFlashAttribute("redirectUrl", "/admin/places/" + placeId); @@ -113,19 +126,18 @@ public String createEvent( return "redirect:/admin/confirm"; } + @ResponseStatus(HttpStatus.SEE_OTHER) + @GetMapping("/events/{eventId}/delete") + public String deleteEvent( + @PathVariable Long eventId, + RedirectAttributes redirectAttributes + ) { + eventService.removeEvent(eventId); - @GetMapping("/events") - public ModelAndView adminEvents(@QuerydslPredicate(root = Event.class) Predicate predicate) { - - List events = eventService.getEvents(predicate) - .stream() - .map(EventResponse::from) - .toList(); + redirectAttributes.addFlashAttribute("adminOperationStatus", AdminOperationStatus.DELETE); + redirectAttributes.addFlashAttribute("redirectUrl", "/admin/events"); - return new ModelAndView("admin/events", Map.of( - "events", events, - "eventStatusOption", EventStatus.values() - )); + return "redirect:/admin/confirm"; } @GetMapping("/events/{eventId}") diff --git a/src/main/java/com/bm/getin/domain/Place.java b/src/main/java/com/bm/getin/domain/Place.java index d3f171b..64a704a 100644 --- a/src/main/java/com/bm/getin/domain/Place.java +++ b/src/main/java/com/bm/getin/domain/Place.java @@ -74,7 +74,7 @@ public class Place { @ToString.Exclude @OrderBy("id") - @OneToMany(mappedBy = "place") + @OneToMany(mappedBy = "place", cascade = CascadeType.REMOVE) private final Set adminPlaceMaps = new LinkedHashSet<>(); protected Place() {} diff --git a/src/main/resources/templates/admin/event-detail.html b/src/main/resources/templates/admin/event-detail.html index befa2ae..a75475e 100644 --- a/src/main/resources/templates/admin/event-detail.html +++ b/src/main/resources/templates/admin/event-detail.html @@ -54,6 +54,7 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/admin/event-detail.th.xml b/src/main/resources/templates/admin/event-detail.th.xml index da1fe48..fac4286 100644 --- a/src/main/resources/templates/admin/event-detail.th.xml +++ b/src/main/resources/templates/admin/event-detail.th.xml @@ -15,5 +15,6 @@ + \ No newline at end of file diff --git a/src/main/resources/templates/admin/place-detail.html b/src/main/resources/templates/admin/place-detail.html index 43ded00..2875188 100644 --- a/src/main/resources/templates/admin/place-detail.html +++ b/src/main/resources/templates/admin/place-detail.html @@ -46,6 +46,7 @@ +
diff --git a/src/main/resources/templates/admin/place-detail.th.xml b/src/main/resources/templates/admin/place-detail.th.xml index f9a671c..21a6a22 100644 --- a/src/main/resources/templates/admin/place-detail.th.xml +++ b/src/main/resources/templates/admin/place-detail.th.xml @@ -14,6 +14,7 @@
+ - + \ No newline at end of file