diff --git a/src/main/java/com/blackshoe/esthete/service/FilterServiceImpl.java b/src/main/java/com/blackshoe/esthete/service/FilterServiceImpl.java index 3092d40..412967e 100644 --- a/src/main/java/com/blackshoe/esthete/service/FilterServiceImpl.java +++ b/src/main/java/com/blackshoe/esthete/service/FilterServiceImpl.java @@ -228,45 +228,37 @@ public void deleteTemporaryFilter(UUID userId, UUID temporaryFilterId) { @Transactional(readOnly = true) @Override public Page readTemporaryFilter(UUID userId, int page, int size) { - Pageable pageable = PageRequest.of(page, size, Sort.by("createdAt").descending()); - List temporaryFilters = temporaryFilterRepository.findByUserId(userId, pageable); List readTemporaryDetailsInfoResponse = new ArrayList<>(); - List representationImgCloudfrontUrl = new ArrayList<>(); - List filterTagList = new ArrayList<>(); for(TemporaryFilter temporaryFilter : temporaryFilters){ - List representationImgUrls = representationImgUrlRepository.findAllByTemporaryFilter(temporaryFilter).orElseGet( - ArrayList::new - ); - - for(RepresentationImgUrl representationImgUrl : representationImgUrls){ - representationImgCloudfrontUrl.add(representationImgUrl.getCloudfrontUrl()); - } - - List filterTags = filterTagRepository.findAllByTemporaryFilter(temporaryFilter).orElseGet( - ArrayList::new - ); - - for(FilterTag filterTag : filterTags){ - filterTagList.add(filterTag.getTag().getStringId()); + List representationImgCloudfrontUrl = representationImgUrlRepository + .findAllByTemporaryFilter(temporaryFilter) + .orElseGet(ArrayList::new) + .stream() + .map(RepresentationImgUrl::getCloudfrontUrl) + .collect(Collectors.toList()); + + List filterTagList = filterTagRepository + .findAllByTemporaryFilter(temporaryFilter) + .orElseGet(ArrayList::new) + .stream() + .map(filterTag -> filterTag.getTag().getStringId()) + .collect(Collectors.toList()); + + Attribute attribute = temporaryFilter.getAttribute(); + if (attribute == null) { + attribute = Attribute.builder().build(); } - Attribute attribute = temporaryFilter.getAttribute() != null ? temporaryFilter.getAttribute() : Attribute.builder().build(); - String thumbnailUrl = temporaryFilter.getThumbnailUrl() != null ? temporaryFilter.getThumbnailUrl().getCloudfrontUrl() : ""; - FilterDto.ReadTemporaryDetailsInfoResponse readTemporaryDetailsInfo = FilterDto.ReadTemporaryDetailsInfoResponse.builder() .filterName(temporaryFilter.getName()) .description(temporaryFilter.getDescription()) - .representationImgList(FilterDto.RepresentationImgListResponse.builder() - .representationImgList(representationImgCloudfrontUrl) - .build()) - .filterTagList(FilterDto.FilterTagListResponse.builder() - .filterTagList(filterTagList) - .build()) + .representationImgList(new FilterDto.RepresentationImgListResponse(representationImgCloudfrontUrl)) + .filterTagList(new FilterDto.FilterTagListResponse(filterTagList)) .temporaryFilterId(temporaryFilter.getTemporaryFilterId()) - .filterThumbnail(thumbnailUrl) + .filterThumbnail(temporaryFilter.getThumbnailUrl() != null ? temporaryFilter.getThumbnailUrl().getCloudfrontUrl() : "") .filterAttributes(FilterDto.AttributeResponse.builder() .brightness(attribute.getBrightness()) .contrast(attribute.getContrast()) @@ -283,8 +275,6 @@ public Page readTemporaryFilter(UUID readTemporaryDetailsInfoResponse.add(readTemporaryDetailsInfo); } - Page readBasicInfoOfTemporaryFilter = new PageImpl<>(readTemporaryDetailsInfoResponse, pageable, temporaryFilters.size()); - - return readBasicInfoOfTemporaryFilter; + return new PageImpl<>(readTemporaryDetailsInfoResponse, pageable, temporaryFilters.size()); } }