From 913bf08e6e75dcd50808645811275e341a64ad7b Mon Sep 17 00:00:00 2001 From: Tony <86696759+capDoYeonLee@users.noreply.github.com> Date: Tue, 23 Jul 2024 19:03:19 +0900 Subject: [PATCH] =?UTF-8?q?filter=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B0=9C=EB=B0=9C=20(#136)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: filter 조회 기능 개발 * feat: filter 조회 기능 추가 개발 --- .../application/dto/AllFilterResponse.java | 17 ++++++++ .../converter/FilterResponseConverter.java | 21 ++++++++++ .../application/service/FilterService.java | 25 ++++++++++- .../usecase/GetAllFilterUsecase.java | 11 +++++ .../filter/persistence/FilterRepository.java | 4 ++ .../filter/presentation/FilterController.java | 42 ++++++------------- 6 files changed, 90 insertions(+), 30 deletions(-) create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/dto/AllFilterResponse.java create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/usecase/GetAllFilterUsecase.java diff --git a/BE/error/src/main/java/com/example/demo/filter/application/dto/AllFilterResponse.java b/BE/error/src/main/java/com/example/demo/filter/application/dto/AllFilterResponse.java new file mode 100644 index 00000000..4d0f2920 --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/dto/AllFilterResponse.java @@ -0,0 +1,17 @@ +package com.example.demo.filter.application.dto; + +import com.example.demo.common.support.dto.AbstractDto; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder(toBuilder = true) +public class AllFilterResponse implements AbstractDto { + private Long filterId; + private String filterName; + private String filterColor; +} \ No newline at end of file diff --git a/BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterResponseConverter.java b/BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterResponseConverter.java index 4db57377..962b97d5 100644 --- a/BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterResponseConverter.java +++ b/BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterResponseConverter.java @@ -1,8 +1,16 @@ package com.example.demo.filter.application.model.converter; +import com.example.demo.filter.application.dto.AllFilterResponse; import com.example.demo.filter.application.dto.CreateFilterResponse; +import com.example.demo.filter.application.model.FilterModel; +import com.example.demo.schedule.application.dto.AllCalendarResponse; +import com.example.demo.schedule.application.model.ScheduleModel; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + @Component public class FilterResponseConverter { @@ -10,4 +18,17 @@ public CreateFilterResponse from(Long filterId) { return CreateFilterResponse.builder().filterId(filterId).build(); } + public List toAllModel(List models) { + List response = new ArrayList<>(); + for (FilterModel model : models) { + AllFilterResponse filter = AllFilterResponse.builder() + .filterId(model.getFilterId()) + .filterName(model.getFilterName()) + .filterColor(model.getFilterColor()) + .build(); + response.add(filter); + } + return response; + } + } 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 5cee9196..10f6a85c 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 @@ -1,22 +1,32 @@ package com.example.demo.filter.application.service; +import com.example.demo.filter.application.dto.AllFilterResponse; import com.example.demo.filter.application.dto.CreateFilterRequest; import com.example.demo.filter.application.dto.CreateFilterResponse; import com.example.demo.filter.application.model.FilterModel; 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.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.stream.Collectors; +import java.util.stream.Stream; + @Service @RequiredArgsConstructor @Transactional(readOnly = true) -public class FilterService implements CreateFilterUsecase { +public class FilterService implements + CreateFilterUsecase, + GetAllFilterUsecase { private final FilterRepository filterRepository; private final FilterRequestConverter requestConverter; @@ -31,4 +41,17 @@ public CreateFilterResponse createFilter(CreateFilterRequest request) { FilterEntity save = filterRepository.save(entity); return responseConverter.from(save.getFilterId()); } + + @Override + public List getFilter() { + List model = filterEntitiesByAll(); + return responseConverter.toAllModel(model); + } + + private List filterEntitiesByAll() { + Stream entities = filterRepository.streamAll(); + return entities + .map(entityConverter::from) + .collect(Collectors.toList()); + } } diff --git a/BE/error/src/main/java/com/example/demo/filter/application/usecase/GetAllFilterUsecase.java b/BE/error/src/main/java/com/example/demo/filter/application/usecase/GetAllFilterUsecase.java new file mode 100644 index 00000000..1665f042 --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/usecase/GetAllFilterUsecase.java @@ -0,0 +1,11 @@ +package com.example.demo.filter.application.usecase; + +import com.example.demo.filter.application.dto.AllFilterResponse; +import com.example.demo.filter.application.dto.CreateFilterRequest; +import com.example.demo.filter.application.dto.CreateFilterResponse; + +import java.util.List; + +public interface GetAllFilterUsecase { + List getFilter(); +} diff --git a/BE/error/src/main/java/com/example/demo/filter/persistence/FilterRepository.java b/BE/error/src/main/java/com/example/demo/filter/persistence/FilterRepository.java index 17529180..dfc11634 100644 --- a/BE/error/src/main/java/com/example/demo/filter/persistence/FilterRepository.java +++ b/BE/error/src/main/java/com/example/demo/filter/persistence/FilterRepository.java @@ -2,8 +2,12 @@ import com.example.demo.schedule.persistence.ScheduleEntity; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; +import java.util.stream.Stream; + @Repository public interface FilterRepository extends JpaRepository { + @Query("select p from FilterEntity p") Stream streamAll(); } 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 1d71a6db..4618c99b 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 @@ -4,15 +4,18 @@ import com.example.demo.common.presentation.response.ApiResponseBody; import com.example.demo.common.presentation.response.ApiResponseGenerator; import com.example.demo.common.presentation.response.MessageCode; +import com.example.demo.filter.application.dto.AllFilterResponse; 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.GetAllFilterUsecase; +import lombok.Getter; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import org.w3c.dom.stylesheets.LinkStyle; + +import java.util.List; @RestController @RequiredArgsConstructor @@ -20,6 +23,7 @@ public class FilterController { private final CreateFilterUsecase createFilterUsecase; + private final GetAllFilterUsecase getAllFilterUsecase; @PostMapping public ApiResponse> createFilter( @@ -28,30 +32,10 @@ public ApiResponse> createFilt return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.CREATE); } - - - - - - - - - - - - - - - - - - - - - - - - - + @GetMapping + public ApiResponse>> getFilter() { + List response = getAllFilterUsecase.getFilter(); + return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.GET); + } }