Skip to content

Commit

Permalink
Merge pull request #173 from JNU-econovation/feat/48/ouath
Browse files Browse the repository at this point in the history
feat: 필터 수정 기능 개발
  • Loading branch information
capDoYeonLee authored Jul 26, 2024
2 parents 7279832 + b838620 commit 1400cd6
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,4 +35,8 @@ public List<AllFilterResponse> toAllModel(List<FilterModel> models) {
return response;
}

public UpdateFilteResponse fromUpdate(Long filterId) {
return UpdateFilteResponse.builder().filterId(filterId).build();
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -30,7 +29,8 @@
public class FilterService implements
CreateFilterUsecase,
GetAllFilterUsecase,
DeleteFilterUsecase {
DeleteFilterUsecase,
UpdateFilterUsecase {

private final FilterRepository filterRepository;
private final FilterRequestConverter requestConverter;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +25,7 @@ public class FilterController {
private final CreateFilterUsecase createFilterUsecase;
private final GetAllFilterUsecase getAllFilterUsecase;
private final DeleteFilterUsecase deleteFilterUsecase;
private final UpdateFilterUsecase updateFilterUsecase;


@PostMapping
Expand All @@ -51,4 +51,14 @@ public ApiResponse<ApiResponseBody.SuccessBody<Void>> delete(
return ApiResponseGenerator.success(HttpStatus.OK, MessageCode.DELETE);
}


@PutMapping("/{filterId}")
public ApiResponse<ApiResponseBody.SuccessBody<UpdateFilteResponse>> update(
@RequestBody UpdateFilterRequest updateFilterRequest,
@PathVariable("filterId") Long filterId)
{
UpdateFilteResponse response = updateFilterUsecase.update(filterId, updateFilterRequest);
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.UPDATE);
}

}

0 comments on commit 1400cd6

Please sign in to comment.