-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed4ea5c
commit a48450c
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/main/java/org/hankki/hankkiserver/api/favorite/service/FavoriteFinder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/org/hankki/hankkiserver/api/favorite/service/FavoriteQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<Store> stores = favorite.getFavoriteStores().stream().map(FavoriteStore::getStore).toList(); | ||
|
||
return FavoriteFindResponse.of(favorite, stores); | ||
} | ||
} |