From 4334e6c6e18f87cea39de886e176c058eac7c88c Mon Sep 17 00:00:00 2001 From: capDoYeonLee Date: Fri, 26 Jul 2024 13:09:02 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=ED=95=84=ED=84=B0=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20=EA=B8=B0=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 --- .../application/dto/UpdateFilteResponse.java | 14 +++++++++++ .../application/dto/UpdateFilterRequest.java | 16 +++++++++++++ .../filter/application/model/FilterModel.java | 7 ++++++ .../converter/FilterRequestConverter.java | 9 ++++++++ .../converter/FilterResponseConverter.java | 5 ++++ .../application/service/FilterService.java | 23 +++++++++++++++---- .../usecase/UpdateFilterUsecase.java | 8 +++++++ .../filter/presentation/FilterController.java | 16 ++++++++++--- 8 files changed, 91 insertions(+), 7 deletions(-) create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/dto/UpdateFilteResponse.java create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/dto/UpdateFilterRequest.java create mode 100644 BE/error/src/main/java/com/example/demo/filter/application/usecase/UpdateFilterUsecase.java diff --git a/BE/error/src/main/java/com/example/demo/filter/application/dto/UpdateFilteResponse.java b/BE/error/src/main/java/com/example/demo/filter/application/dto/UpdateFilteResponse.java new file mode 100644 index 00000000..f277b2a3 --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/dto/UpdateFilteResponse.java @@ -0,0 +1,14 @@ +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 UpdateFilteResponse { + private Long filterId; +} diff --git a/BE/error/src/main/java/com/example/demo/filter/application/dto/UpdateFilterRequest.java b/BE/error/src/main/java/com/example/demo/filter/application/dto/UpdateFilterRequest.java new file mode 100644 index 00000000..7a3f8bb1 --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/dto/UpdateFilterRequest.java @@ -0,0 +1,16 @@ +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 UpdateFilterRequest { + private Long filterId; + private String filterName; + private String filterColor; +} 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 index 249a211f..89bd6ff1 100644 --- 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 @@ -12,4 +12,11 @@ public class FilterModel implements AbstractModel { private Long filterId; private String filterName; private String filterColor; + + public FilterModel update(FilterModel requestModel) { + filterName = requestModel.getFilterName(); + filterColor = requestModel.filterColor; + + return this; + } } 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 index eb9051cb..7fe6fdb8 100644 --- 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 @@ -3,6 +3,7 @@ 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.dto.UpdateFilterRequest; import com.example.demo.filter.application.model.FilterModel; import com.example.demo.schedule.application.model.ScheduleModel; import org.springframework.stereotype.Component; @@ -20,6 +21,14 @@ public FilterModel from(CreateFilterRequest source) { .build(); } + public FilterModel from(Long filterId, UpdateFilterRequest 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 index 962b97d5..ec06bf09 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 @@ -2,6 +2,7 @@ import com.example.demo.filter.application.dto.AllFilterResponse; import com.example.demo.filter.application.dto.CreateFilterResponse; +import com.example.demo.filter.application.dto.UpdateFilteResponse; import com.example.demo.filter.application.model.FilterModel; import com.example.demo.schedule.application.dto.AllCalendarResponse; import com.example.demo.schedule.application.model.ScheduleModel; @@ -31,4 +32,8 @@ public List toAllModel(List models) { return response; } + public UpdateFilteResponse fromUpdate(Long filterId) { + return UpdateFilteResponse.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 index 041e2a7e..cd643faa 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,14 +1,13 @@ 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.dto.*; 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.DeleteFilterUsecase; import com.example.demo.filter.application.usecase.GetAllFilterUsecase; +import com.example.demo.filter.application.usecase.UpdateFilterUsecase; import com.example.demo.filter.persistence.FilterEntity; import com.example.demo.filter.persistence.FilterRepository; import com.example.demo.filter.application.usecase.CreateFilterUsecase; @@ -28,7 +27,8 @@ public class FilterService implements CreateFilterUsecase, GetAllFilterUsecase, - DeleteFilterUsecase { + DeleteFilterUsecase, + UpdateFilterUsecase { private final FilterRepository filterRepository; private final FilterRequestConverter requestConverter; @@ -72,4 +72,19 @@ private FilterModel findFilter(final Long filterId) { .orElseThrow(() -> new NoSuchElementException("no found eventId :" + filterId)); } + @Override + @Transactional + public UpdateFilteResponse update(Long filterId, UpdateFilterRequest request) { + FilterModel model = findFilter(filterId); + FilterModel requestModel = requestConverter.from(filterId, request); + updateFilter(model, requestModel); + + return responseConverter.fromUpdate(model.getFilterId()); + } + + private void updateFilter(FilterModel model, FilterModel requestModel) { + FilterModel update = model.update(requestModel); + FilterEntity entity = entityConverter.toEntity(update); + filterRepository.save(entity); + } } diff --git a/BE/error/src/main/java/com/example/demo/filter/application/usecase/UpdateFilterUsecase.java b/BE/error/src/main/java/com/example/demo/filter/application/usecase/UpdateFilterUsecase.java new file mode 100644 index 00000000..127b04cb --- /dev/null +++ b/BE/error/src/main/java/com/example/demo/filter/application/usecase/UpdateFilterUsecase.java @@ -0,0 +1,8 @@ +package com.example.demo.filter.application.usecase; + +import com.example.demo.filter.application.dto.UpdateFilteResponse; +import com.example.demo.filter.application.dto.UpdateFilterRequest; + +public interface UpdateFilterUsecase { + UpdateFilteResponse update(Long filterId, UpdateFilterRequest request); +} 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 95870689..d6d1e5dd 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,12 +4,11 @@ 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.dto.*; 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 com.example.demo.filter.application.usecase.UpdateFilterUsecase; import lombok.Getter; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -26,6 +25,7 @@ public class FilterController { private final CreateFilterUsecase createFilterUsecase; private final GetAllFilterUsecase getAllFilterUsecase; private final DeleteFilterUsecase deleteFilterUsecase; + private final UpdateFilterUsecase updateFilterUsecase; @PostMapping public ApiResponse> createFilter( @@ -48,4 +48,14 @@ public ApiResponse> delete( return ApiResponseGenerator.success(HttpStatus.OK, MessageCode.DELETE); } + + @PutMapping("/{filterId}") + public ApiResponse> update( + @RequestBody UpdateFilterRequest updateFilterRequest, + @PathVariable("filterId") Long filterId) + { + UpdateFilteResponse response = updateFilterUsecase.update(filterId, updateFilterRequest); + return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.UPDATE); + } + }