Skip to content

Commit

Permalink
[feat] implements service
Browse files Browse the repository at this point in the history
  • Loading branch information
PicturePark1101 committed Jul 9, 2024
1 parent ed4ea5c commit a48450c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
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));
}
}
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);
}
}

0 comments on commit a48450c

Please sign in to comment.