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 0000000..f277b2a --- /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 0000000..7a3f8bb --- /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 249a211..89bd6ff 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 eb9051c..7fe6fdb 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 25f5866..5c43686 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 @@ -3,6 +3,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; @@ -34,4 +35,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 3935810..1a2c7c0 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,15 +1,14 @@ 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; @@ -30,7 +29,8 @@ public class FilterService implements CreateFilterUsecase, GetAllFilterUsecase, - DeleteFilterUsecase { + DeleteFilterUsecase, + UpdateFilterUsecase { private final FilterRepository filterRepository; private final FilterRequestConverter requestConverter; @@ -74,4 +74,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 0000000..127b04c --- /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 64b8b9f..f2b6dec 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 @@ -51,4 +51,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); + } + }