From 15e22a1732cab23d2e13cdfe26d8702566fd480b Mon Sep 17 00:00:00 2001 From: capDoYeonLee Date: Thu, 25 Jul 2024 17:45:18 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=83=81=EC=84=B8=20=ED=95=84=ED=84=B0?= =?UTF-8?q?=20=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/service/FilterService.java | 21 +++++++++++++++++-- .../usecase/DeleteFilterUsecase.java | 5 +++++ .../filter/presentation/FilterController.java | 10 +++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/usecase/DeleteFilterUsecase.java diff --git a/BE/error/src/main/java/com/example/demo/filter/application/service/FilterService.java b/BE/error/src/main/java/com/example/demo/filter/application/service/FilterService.java index f760955..041e2a7 100644 --- a/BE/error/src/main/java/com/example/demo/filter/application/service/FilterService.java +++ b/BE/error/src/main/java/com/example/demo/filter/application/service/FilterService.java @@ -7,17 +7,18 @@ import com.example.demo.filter.application.model.converter.FilterEntityConverter; import com.example.demo.filter.application.model.converter.FilterRequestConverter; import com.example.demo.filter.application.model.converter.FilterResponseConverter; +import com.example.demo.filter.application.usecase.DeleteFilterUsecase; import com.example.demo.filter.application.usecase.GetAllFilterUsecase; import com.example.demo.filter.persistence.FilterEntity; import com.example.demo.filter.persistence.FilterRepository; import com.example.demo.filter.application.usecase.CreateFilterUsecase; import com.example.demo.schedule.application.model.ScheduleModel; -import com.example.demo.schedule.persistence.ScheduleEntity; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.NoSuchElementException; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -26,7 +27,8 @@ @Transactional(readOnly = true) public class FilterService implements CreateFilterUsecase, - GetAllFilterUsecase { + GetAllFilterUsecase, + DeleteFilterUsecase { private final FilterRepository filterRepository; private final FilterRequestConverter requestConverter; @@ -55,4 +57,19 @@ private List filterEntitiesByAll() { .map(entityConverter::from) .collect(Collectors.toList()); } + + @Override + @Transactional + public void delete(final Long filterId) { + FilterModel filter = findFilter(filterId); + filterRepository.deleteById(filter.getFilterId()); + } + + private FilterModel findFilter(final Long filterId) { + return filterRepository + .findById(filterId) + .map(entityConverter::from) + .orElseThrow(() -> new NoSuchElementException("no found eventId :" + filterId)); + } + } diff --git a/BE/error/src/main/java/com/example/demo/filter/application/usecase/DeleteFilterUsecase.java b/BE/error/src/main/java/com/example/demo/filter/application/usecase/DeleteFilterUsecase.java new file mode 100644 index 0000000..525f8d0 --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/usecase/DeleteFilterUsecase.java @@ -0,0 +1,5 @@ +package com.example.demo.filter.application.usecase; + +public interface DeleteFilterUsecase { + void delete(Long filterId); +} diff --git a/BE/error/src/main/java/com/example/demo/filter/presentation/FilterController.java b/BE/error/src/main/java/com/example/demo/filter/presentation/FilterController.java index 4618c99..9587068 100644 --- a/BE/error/src/main/java/com/example/demo/filter/presentation/FilterController.java +++ b/BE/error/src/main/java/com/example/demo/filter/presentation/FilterController.java @@ -8,6 +8,7 @@ import com.example.demo.filter.application.dto.CreateFilterRequest; import com.example.demo.filter.application.dto.CreateFilterResponse; import com.example.demo.filter.application.usecase.CreateFilterUsecase; +import com.example.demo.filter.application.usecase.DeleteFilterUsecase; import com.example.demo.filter.application.usecase.GetAllFilterUsecase; import lombok.Getter; import lombok.RequiredArgsConstructor; @@ -24,6 +25,7 @@ public class FilterController { private final CreateFilterUsecase createFilterUsecase; private final GetAllFilterUsecase getAllFilterUsecase; + private final DeleteFilterUsecase deleteFilterUsecase; @PostMapping public ApiResponse> createFilter( @@ -38,4 +40,12 @@ public ApiResponse>> getFilt return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.GET); } + @DeleteMapping("/{filterId}") + public ApiResponse> delete( + @PathVariable("filterId") Long filterId + ) { + deleteFilterUsecase.delete(filterId); + return ApiResponseGenerator.success(HttpStatus.OK, MessageCode.DELETE); + } + }