Skip to content

Commit

Permalink
Merge pull request #135 from JNU-econovation/feat/48/ouath
Browse files Browse the repository at this point in the history
feat: filter 조회 기능 개발
  • Loading branch information
capDoYeonLee authored Jul 23, 2024
2 parents f992ab3 + 917df9d commit b241841
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
package com.example.demo.filter.application.model.converter;

import com.example.demo.filter.application.dto.AllFilterResponse;
import com.example.demo.filter.application.dto.CreateFilterResponse;
import com.example.demo.filter.application.model.FilterModel;
import com.example.demo.schedule.application.dto.AllCalendarResponse;
import com.example.demo.schedule.application.model.ScheduleModel;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Component
public class FilterResponseConverter {

public CreateFilterResponse from(Long filterId) {
return CreateFilterResponse.builder().filterId(filterId).build();
}

public List<AllFilterResponse> toAllModel(List<FilterModel> models) {
List<AllFilterResponse> response = new ArrayList<>();
for (FilterModel model : models) {
AllFilterResponse filter = AllFilterResponse.builder()
.filterId(model.getFilterId())
.filterName(model.getFilterName())
.filterColor(model.getFilterColor())
.build();
response.add(filter);
}
return response;
}

}
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
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.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.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.stream.Collectors;
import java.util.stream.Stream;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class FilterService implements CreateFilterUsecase {
public class FilterService implements
CreateFilterUsecase,
GetAllFilterUsecase {

private final FilterRepository filterRepository;
private final FilterRequestConverter requestConverter;
Expand All @@ -31,4 +41,17 @@ public CreateFilterResponse createFilter(CreateFilterRequest request) {
FilterEntity save = filterRepository.save(entity);
return responseConverter.from(save.getFilterId());
}

@Override
public List<AllFilterResponse> getFilter() {
List<FilterModel> model = filterEntitiesByAll();
return responseConverter.toAllModel(model);
}

private List<FilterModel> filterEntitiesByAll() {
Stream<FilterEntity> entities = filterRepository.streamAll();
return entities
.map(entityConverter::from)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import com.example.demo.schedule.persistence.ScheduleEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.stream.Stream;

@Repository
public interface FilterRepository extends JpaRepository<FilterEntity, Long> {
@Query("select p from FilterEntity p") Stream<FilterEntity> streamAll();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@
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.usecase.CreateFilterUsecase;
import com.example.demo.filter.application.usecase.GetAllFilterUsecase;
import lombok.Getter;
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;
import org.springframework.web.bind.annotation.*;
import org.w3c.dom.stylesheets.LinkStyle;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/filter")
public class FilterController {

private final CreateFilterUsecase createFilterUsecase;
private final GetAllFilterUsecase getAllFilterUsecase;

@PostMapping
public ApiResponse<ApiResponseBody.SuccessBody<CreateFilterResponse>> createFilter(
Expand All @@ -28,30 +32,10 @@ public ApiResponse<ApiResponseBody.SuccessBody<CreateFilterResponse>> createFilt
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.CREATE);
}


























@GetMapping
public ApiResponse<ApiResponseBody.SuccessBody<List<AllFilterResponse>>> getFilter() {
List<AllFilterResponse> response = getAllFilterUsecase.getFilter();
return ApiResponseGenerator.success(response, HttpStatus.OK, MessageCode.GET);
}

}

0 comments on commit b241841

Please sign in to comment.