Skip to content

Commit

Permalink
refactor[#137] : category 별로 fetch를 보내도록 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
gomster96 committed Jun 29, 2022
1 parent 294148c commit 6afd58e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.handong.rebon.shop.application.dto.request.ShopLikeRequestDto;
import com.handong.rebon.shop.application.dto.request.ShopRequestDto;
import com.handong.rebon.shop.application.dto.request.ShopSearchDto;
import com.handong.rebon.shop.application.dto.response.LikeShopResponseDto;
import com.handong.rebon.shop.application.dto.response.ShopLikeResponseDto;
import com.handong.rebon.shop.application.dto.response.ShopResponseDto;
import com.handong.rebon.shop.application.dto.response.ShopSimpleResponseDto;
Expand All @@ -23,9 +22,7 @@
import com.handong.rebon.shop.domain.content.ShopContent;
import com.handong.rebon.shop.domain.content.ShopImage;
import com.handong.rebon.shop.domain.content.ShopImages;
import com.handong.rebon.shop.domain.like.Likes;
import com.handong.rebon.shop.domain.location.Location;
import com.handong.rebon.shop.domain.repository.LikesRepository;
import com.handong.rebon.shop.domain.repository.ShopImageRepository;
import com.handong.rebon.shop.domain.repository.ShopRepository;
import com.handong.rebon.tag.application.TagService;
Expand All @@ -49,7 +46,6 @@ public class ShopService {
private final ShopRepository shopRepository;
private final ImageUploader imageUploader;
private final ShopImageRepository shopImageRepository;
private final LikesRepository likesRepository;

@Transactional
public Long create(ShopRequestDto shopRequestDto) {
Expand Down Expand Up @@ -190,14 +186,18 @@ private ShopImages changeImages(Shop shop, ShopRequestDto shopRequestDto) {
}

@Transactional(readOnly = true)
public List<LikeShopResponseDto> findLikeShops(Long memberId) {
public List<ShopSimpleResponseDto> findLikeShops(Long memberId, Long categoryId) {

Category category = categoryService.findById(categoryId);
Member member = memberService.findById(memberId);
List<Likes> likes = likesRepository.findByMember(member);
return likes.stream()
.map(like -> LikeShopResponseDto.from(like.getShop()))
.collect(Collectors.toList());

return member.getLikes().stream()
.filter(like -> like.getShop().sameCategory(category))
.map(ShopSimpleResponseDto::from)
.collect(Collectors.toList());
}


@Transactional(readOnly = true)
public boolean isLike(Long id, LoginMember loginMember) {
Shop shop = findById(id);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.handong.rebon.auth.domain.LoginMember;
import com.handong.rebon.shop.application.dto.response.tag.ShopTagResponseDto;
import com.handong.rebon.shop.domain.Shop;
import com.handong.rebon.shop.domain.like.Likes;

import lombok.AccessLevel;
import lombok.Builder;
Expand Down Expand Up @@ -33,17 +34,26 @@ public ShopSimpleResponseDto(Long id, String name, double star, boolean like, Li
}

public static ShopSimpleResponseDto of(Shop shop, LoginMember loginMember) {
List<ShopTagResponseDto> tags = shop.getShopTags().stream()
.map(shopTag -> ShopTagResponseDto.from(shopTag.getTag()))
.collect(Collectors.toList());

return ShopSimpleResponseDto.builder()
.id(shop.getId())
.name(shop.getName())
.star(shop.getStar())
.like(shop.containLike(loginMember))
.tags(tags)
.tags(ShopTagResponseDto.toDtos(shop))
.image(shop.getMainImage())
.build();
}

public static ShopSimpleResponseDto from(Likes like) {

return ShopSimpleResponseDto.builder()
.id(like.getShop().getId())
.name(like.getShop().getName())
.star(like.getShop().getStar())
.like(true)
.tags(ShopTagResponseDto.toDtos(like.getShop()))
.image(like.getShop().getMainImage())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.handong.rebon.shop.application.dto.response.tag;

import java.util.List;
import java.util.stream.Collectors;

import com.handong.rebon.shop.domain.Shop;
import com.handong.rebon.tag.domain.Tag;

import lombok.AccessLevel;
Expand All @@ -20,4 +24,10 @@ public ShopTagResponseDto(Long id, String name) {
public static ShopTagResponseDto from(Tag tag) {
return new ShopTagResponseDto(tag.getId(), tag.getName());
}

public static List<ShopTagResponseDto> toDtos(Shop shop) {
return shop.getShopTags().stream()
.map(shopTag -> ShopTagResponseDto.from(shopTag.getTag()))
.collect(Collectors.toList());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
import com.handong.rebon.shop.application.ShopService;
import com.handong.rebon.shop.application.dto.request.ShopLikeRequestDto;
import com.handong.rebon.shop.application.dto.request.ShopSearchDto;
import com.handong.rebon.shop.application.dto.response.LikeShopResponseDto;
import com.handong.rebon.shop.application.dto.response.ShopLikeResponseDto;
import com.handong.rebon.shop.application.dto.response.ShopResponseDto;
import com.handong.rebon.shop.application.dto.response.ShopSimpleResponseDto;
import com.handong.rebon.shop.presentation.dto.request.ShopSearchRequest;
import com.handong.rebon.shop.presentation.dto.response.LikeShopResponse;
import com.handong.rebon.shop.presentation.dto.response.ShopLikeResponse;
import com.handong.rebon.shop.presentation.dto.response.ShopResponse;
import com.handong.rebon.shop.presentation.dto.response.ShopSimpleResponse;
Expand Down Expand Up @@ -79,8 +77,11 @@ public ResponseEntity<ShopLikeResponse> unlike(

@RequiredLogin
@GetMapping("/shops/likes")
public ResponseEntity<List<LikeShopResponse>> getLikeShops(@Login LoginMember loginMember) {
List<LikeShopResponseDto> likeShopDtos = shopService.findLikeShops(loginMember.getId());
return ResponseEntity.ok(LikeShopResponse.convert(likeShopDtos));
public ResponseEntity<List<ShopSimpleResponse>> getLikeShops(
@Login LoginMember loginMember,
@RequestParam Long categoryId
) {
List<ShopSimpleResponseDto> responses = shopService.findLikeShops(loginMember.getId(), categoryId);
return ResponseEntity.ok(ShopSimpleResponse.convert(responses));
}
}

This file was deleted.

0 comments on commit 6afd58e

Please sign in to comment.