From f81cccf2a8e7bbdc259aca03fa450e2f487e7cd4 Mon Sep 17 00:00:00 2001 From: Tony <86696759+capDoYeonLee@users.noreply.github.com> Date: Tue, 23 Jul 2024 15:16:31 +0900 Subject: [PATCH] =?UTF-8?q?Filter=20=EC=83=9D=EC=84=B1=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B0=9C=EB=B0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: filter 생성 controller 기능 개발 * feat: 필터 entity 생성 * feat: filter repository 생성 * feat: filter 생성 dto 추가 * feat: filter 생성 converter 기능 개발 * feat: filter model 추가 * feat: filter 생성 서비스 기능 개발 * feat: create filter usecase 추가 * fix: CreateFilterUsecase path 수정 * fix: CreateFilterUsecase path 수정 --- .../application/dto/CreateFilterRequest.java | 18 ++++++ .../application/dto/CreateFilterResponse.java | 17 ++++++ .../filter/application/model/FilterModel.java | 15 +++++ .../converter/FilterEntityConverter.java | 28 +++++++++ .../converter/FilterRequestConverter.java | 28 +++++++++ .../converter/FilterResponseConverter.java | 13 +++++ .../application/service/FilterService.java | 34 +++++++++++ .../usecase/CreateFilterUsecase.java | 8 +++ .../demo/filter/persistence/FilterEntity.java | 30 ++++++++++ .../filter/persistence/FilterRepository.java | 9 +++ .../filter/presentation/FilterController.java | 57 +++++++++++++++++++ 11 files changed, 257 insertions(+) create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/dto/CreateFilterRequest.java create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/dto/CreateFilterResponse.java create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/model/FilterModel.java create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterEntityConverter.java create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterRequestConverter.java create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterResponseConverter.java create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/service/FilterService.java create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/usecase/CreateFilterUsecase.java create mode 100644 BE/error/src/main/java/com/example/demo/filter/persistence/FilterEntity.java create mode 100644 BE/error/src/main/java/com/example/demo/filter/persistence/FilterRepository.java create mode 100644 BE/error/src/main/java/com/example/demo/filter/presentation/FilterController.java diff --git a/BE/error/src/main/java/com/example/demo/filter/application/dto/CreateFilterRequest.java b/BE/error/src/main/java/com/example/demo/filter/application/dto/CreateFilterRequest.java new file mode 100644 index 00000000..a1bdc887 --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/dto/CreateFilterRequest.java @@ -0,0 +1,18 @@ +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 CreateFilterRequest implements AbstractDto { + private Long filterId; + private String filterName; + private String filterColor; +} diff --git a/BE/error/src/main/java/com/example/demo/filter/application/dto/CreateFilterResponse.java b/BE/error/src/main/java/com/example/demo/filter/application/dto/CreateFilterResponse.java new file mode 100644 index 00000000..b5fb7e63 --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/dto/CreateFilterResponse.java @@ -0,0 +1,17 @@ +package com.example.demo.filter.application.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + + +@Getter +@AllArgsConstructor +@NoArgsConstructor +@Builder(toBuilder = true) +public class CreateFilterResponse { + private Long filterId; +} + + diff --git a/BE/error/src/main/java/com/example/demo/filter/application/model/FilterModel.java b/BE/error/src/main/java/com/example/demo/filter/application/model/FilterModel.java new file mode 100644 index 00000000..249a211f --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/model/FilterModel.java @@ -0,0 +1,15 @@ +package com.example.demo.filter.application.model; + +import com.example.demo.common.support.AbstractModel; +import lombok.*; + +@Getter +@ToString +@AllArgsConstructor +@NoArgsConstructor +@Builder(toBuilder = true) +public class FilterModel implements AbstractModel { + private Long filterId; + private String filterName; + private String filterColor; +} diff --git a/BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterEntityConverter.java b/BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterEntityConverter.java new file mode 100644 index 00000000..4f704dac --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterEntityConverter.java @@ -0,0 +1,28 @@ +package com.example.demo.filter.application.model.converter; + +import com.example.demo.common.support.converter.AbstractEntityConverter; +import com.example.demo.filter.application.model.FilterModel; +import com.example.demo.filter.persistence.FilterEntity; +import org.springframework.stereotype.Component; + +@Component +public class FilterEntityConverter implements AbstractEntityConverter { + + @Override + public FilterModel from(FilterEntity source) { + return FilterModel.builder() + .filterId(source.getFilterId()) + .filterName(source.getFilterName()) + .filterColor(source.getFilterColor()) + .build(); + } + + @Override + public FilterEntity toEntity(FilterModel source) { + return FilterEntity.builder() + .filterId(source.getFilterId()) + .filterName(source.getFilterName()) + .filterColor(source.getFilterColor()) + .build(); + } +} diff --git a/BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterRequestConverter.java b/BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterRequestConverter.java new file mode 100644 index 00000000..eb9051cb --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterRequestConverter.java @@ -0,0 +1,28 @@ +package com.example.demo.filter.application.model.converter; + +import com.example.demo.common.support.converter.AbstractDtoConverter; +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.schedule.application.model.ScheduleModel; +import org.springframework.stereotype.Component; + +@Component +public class FilterRequestConverter implements AbstractDtoConverter { + + + @Override + public FilterModel from(CreateFilterRequest source) { + return FilterModel.builder() + .filterId(source.getFilterId()) + .filterName(source.getFilterName()) + .filterColor(source.getFilterColor()) + .build(); + } + + + + + + +} 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 new file mode 100644 index 00000000..4db57377 --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/model/converter/FilterResponseConverter.java @@ -0,0 +1,13 @@ +package com.example.demo.filter.application.model.converter; + +import com.example.demo.filter.application.dto.CreateFilterResponse; +import org.springframework.stereotype.Component; + +@Component +public class FilterResponseConverter { + + public CreateFilterResponse from(Long filterId) { + return CreateFilterResponse.builder().filterId(filterId).build(); + } + +} 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 new file mode 100644 index 00000000..5cee9196 --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/service/FilterService.java @@ -0,0 +1,34 @@ +package com.example.demo.filter.application.service; + +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.persistence.FilterEntity; +import com.example.demo.filter.persistence.FilterRepository; +import com.example.demo.filter.application.usecase.CreateFilterUsecase; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class FilterService implements CreateFilterUsecase { + + private final FilterRepository filterRepository; + private final FilterRequestConverter requestConverter; + private final FilterEntityConverter entityConverter; + private final FilterResponseConverter responseConverter; + + + @Override + public CreateFilterResponse createFilter(CreateFilterRequest request) { + FilterModel model = requestConverter.from(request); + FilterEntity entity = entityConverter.toEntity(model); + FilterEntity save = filterRepository.save(entity); + return responseConverter.from(save.getFilterId()); + } +} diff --git a/BE/error/src/main/java/com/example/demo/filter/application/usecase/CreateFilterUsecase.java b/BE/error/src/main/java/com/example/demo/filter/application/usecase/CreateFilterUsecase.java new file mode 100644 index 00000000..5161f3bd --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/usecase/CreateFilterUsecase.java @@ -0,0 +1,8 @@ +package com.example.demo.filter.application.usecase; + +import com.example.demo.filter.application.dto.CreateFilterRequest; +import com.example.demo.filter.application.dto.CreateFilterResponse; + +public interface CreateFilterUsecase { + CreateFilterResponse createFilter(CreateFilterRequest request); +} diff --git a/BE/error/src/main/java/com/example/demo/filter/persistence/FilterEntity.java b/BE/error/src/main/java/com/example/demo/filter/persistence/FilterEntity.java new file mode 100644 index 00000000..bc432e09 --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/persistence/FilterEntity.java @@ -0,0 +1,30 @@ +package com.example.demo.filter.persistence; + +import com.example.demo.common.persistence.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import lombok.experimental.SuperBuilder; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + + +@Getter +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor(access = AccessLevel.PRIVATE) +@ToString +@Entity +@SuperBuilder(toBuilder = true) +@Table(name = "filter") +@EntityListeners(AuditingEntityListener.class) +public class FilterEntity extends BaseEntity { + + @Id + @GeneratedValue + @Column(nullable = false) + private Long filterId; + + @Column(nullable = false) + private String filterName; + + @Column(nullable = false) + private String filterColor; +} 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 new file mode 100644 index 00000000..17529180 --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/persistence/FilterRepository.java @@ -0,0 +1,9 @@ +package com.example.demo.filter.persistence; + +import com.example.demo.schedule.persistence.ScheduleEntity; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface FilterRepository extends JpaRepository { +} 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 new file mode 100644 index 00000000..1d71a6db --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/presentation/FilterController.java @@ -0,0 +1,57 @@ +package com.example.demo.filter.presentation; + +import com.example.demo.common.presentation.response.ApiResponse; +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.CreateFilterRequest; +import com.example.demo.filter.application.dto.CreateFilterResponse; +import com.example.demo.filter.application.usecase.CreateFilterUsecase; +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; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/filter") +public class FilterController { + + private final CreateFilterUsecase createFilterUsecase; + + @PostMapping + public ApiResponse> createFilter( + @RequestBody CreateFilterRequest request) { + CreateFilterResponse response = createFilterUsecase.createFilter(request); + return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.CREATE); + } + + + + + + + + + + + + + + + + + + + + + + + + + + + +}