diff --git a/src/main/java/org/hankki/hankkiserver/api/favorite/service/FavoriteFinder.java b/src/main/java/org/hankki/hankkiserver/api/favorite/service/FavoriteFinder.java new file mode 100644 index 00000000..7faefb26 --- /dev/null +++ b/src/main/java/org/hankki/hankkiserver/api/favorite/service/FavoriteFinder.java @@ -0,0 +1,19 @@ +package org.hankki.hankkiserver.api.favorite.service; + +import lombok.RequiredArgsConstructor; +import org.hankki.hankkiserver.common.code.FavoriteErrorCode; +import org.hankki.hankkiserver.common.exception.NotFoundException; +import org.hankki.hankkiserver.domain.favorite.model.Favorite; +import org.hankki.hankkiserver.domain.favorite.repository.FavoriteRepository; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class FavoriteFinder { + + private final FavoriteRepository favoriteRepository; + + public Favorite findById(final long id) { + return favoriteRepository.findById(id).orElseThrow(() -> new NotFoundException(FavoriteErrorCode.FAVORITE_NOT_FOUND)); + } +} diff --git a/src/main/java/org/hankki/hankkiserver/api/favorite/service/FavoriteQueryService.java b/src/main/java/org/hankki/hankkiserver/api/favorite/service/FavoriteQueryService.java new file mode 100644 index 00000000..9cdff807 --- /dev/null +++ b/src/main/java/org/hankki/hankkiserver/api/favorite/service/FavoriteQueryService.java @@ -0,0 +1,26 @@ +package org.hankki.hankkiserver.api.favorite.service; + +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.hankki.hankkiserver.api.favorite.service.response.FavoriteFindResponse; +import org.hankki.hankkiserver.domain.favorite.model.Favorite; +import org.hankki.hankkiserver.domain.favoritestore.model.FavoriteStore; +import org.hankki.hankkiserver.domain.store.model.Store; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class FavoriteQueryService { + + private final FavoriteFinder favoriteFinder; + + @Transactional(readOnly = true) + public FavoriteFindResponse findFavorite(final long id) { + + Favorite favorite = favoriteFinder.findById(id); + List stores = favorite.getFavoriteStores().stream().map(FavoriteStore::getStore).toList(); + + return FavoriteFindResponse.of(favorite, stores); + } +}