Skip to content

Commit

Permalink
feat: 멤버별 filter 조회 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
capDoYeonLee committed Oct 13, 2024
1 parent 88f0551 commit e1c5e4e
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.demo.filter.application.dto;

import com.example.demo.auth.persistence.MemberEntity;
import com.example.demo.common.support.dto.AbstractDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
Expand All @@ -14,4 +15,5 @@ public class AllFilterResponse implements AbstractDto {
private Long filterId;
private String filterName;
private String filterColor;
private MemberEntity member;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public List<AllFilterResponse> toAllModel(List<FilterModel> models) {
.filterId(model.getFilterId())
.filterName(model.getFilterName())
.filterColor(model.getFilterColor())
.member((model.getMember()))
.build();
response.add(filter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ public CreateFilterResponse createFilter(final CreateFilterRequest request, fina
}

@Override
public List<AllFilterResponse> getFilter() {
public List<AllFilterResponse> getFilter(Long memberId) {
// 필터를 조회할 때, 모든 데이터에서 param memberId와 같은 데이터만 조회하자
List<FilterModel> model = filterEntitiesByAll();
List<FilterModel> model = filterEntitiesByAll(memberId);
return responseConverter.toAllModel(model);
}

private List<FilterModel> filterEntitiesByAll() {
Stream<FilterEntity> entities = filterRepository.streamAll();
private List<FilterModel> filterEntitiesByAll(Long memberId) {
Stream<FilterEntity> entities = filterRepository.streamAll(memberId);
return entities
.map(entityConverter::from)
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
import java.util.List;

public interface GetAllFilterUsecase {
List<AllFilterResponse> getFilter();
List<AllFilterResponse> getFilter(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
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();
//@Query("select p from FilterEntity p") Stream<FilterEntity> streamAll();
@Query("select p from FilterEntity p where p.member = :memberId")
Stream<FilterEntity> streamAll(Long memberId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ public ApiResponse<ApiResponseBody.SuccessBody<CreateFilterResponse>> createFilt
}


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

Expand Down

0 comments on commit e1c5e4e

Please sign in to comment.