Skip to content

Commit

Permalink
Merge pull request #163 from JNU-econovation/BE
Browse files Browse the repository at this point in the history
feat: 상세 filter 삭제 기능 구현
  • Loading branch information
capDoYeonLee authored Jul 25, 2024
2 parents 68e532f + 9e6e271 commit e8d5ede
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@
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.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.NoSuchElementException;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -28,7 +29,8 @@
@Transactional(readOnly = true)
public class FilterService implements
CreateFilterUsecase,
GetAllFilterUsecase {
GetAllFilterUsecase,
DeleteFilterUsecase {

private final FilterRepository filterRepository;
private final FilterRequestConverter requestConverter;
Expand Down Expand Up @@ -57,4 +59,19 @@ private List<FilterModel> filterEntitiesByAll() {
.map(entityConverter::from)
.collect(Collectors.toList());
}

@Override
@Transactional
public void delete(final Long filterId) {
FilterModel filter = findFilter(filterId);
filterRepository.deleteById(filter.getFilterId());
}

private FilterModel findFilter(final Long filterId) {
return filterRepository
.findById(filterId)
.map(entityConverter::from)
.orElseThrow(() -> new NoSuchElementException("no found eventId :" + filterId));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.example.demo.filter.application.usecase;

public interface DeleteFilterUsecase {
void delete(Long filterId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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.DeleteFilterUsecase;
import com.example.demo.filter.application.usecase.GetAllFilterUsecase;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand All @@ -24,6 +25,7 @@ public class FilterController {

private final CreateFilterUsecase createFilterUsecase;
private final GetAllFilterUsecase getAllFilterUsecase;
private final DeleteFilterUsecase deleteFilterUsecase;


@PostMapping
Expand All @@ -39,4 +41,14 @@ public ApiResponse<ApiResponseBody.SuccessBody<List<AllFilterResponse>>> getFilt
List<AllFilterResponse> response = getAllFilterUsecase.getFilter();
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.GET);
}


@DeleteMapping("/{filterId}")
public ApiResponse<ApiResponseBody.SuccessBody<Void>> delete(
@PathVariable("filterId") Long filterId
) {
deleteFilterUsecase.delete(filterId);
return ApiResponseGenerator.success(HttpStatus.OK, MessageCode.DELETE);
}

}

0 comments on commit e8d5ede

Please sign in to comment.