Parent Issue / 親Issue
#565
Motivation / 目的
Add a way to fetch the world heritage site ids a user has favorited, reusing the favorites() relation already added for addFavorite() (#552).
お気に入り一覧API(#565)のInfra層として、ユーザーがお気に入り登録した世界遺産IDの一覧を取得できるようにする。addFavorite()用に追加済みのfavorites()リレーションを再利用する。
What to do / 実施内容
FavoriteRepositoryInterface::getFavoriteWorldHeritageIds(int $userId): array を追加
FavoriteRepository に実装。お気に入り登録が新しい順(user_favorite.created_at desc)でIDを返す。ユーザーが存在しない場合は addFavorite() と同様に Exception('User not found.') をスロー
User::favorites() に withTimestamps() を追加し、attach() 時にpivotの created_at が自動設定されるようにする
Tests / テスト
実DB(heritage-mysql-test)を使ったインテグレーションテスト
test_getFavoriteWorldHeritageIds_returns_ids_ordered_by_most_recently_favorited
test_getFavoriteWorldHeritageIds_returns_empty_array_when_no_favorites
test_getFavoriteWorldHeritageIds_throws_exception_when_user_not_found
Status
実装済み。#564 で対応。
Parent Issue / 親Issue
#565
Motivation / 目的
Add a way to fetch the world heritage site ids a user has favorited, reusing the
favorites()relation already added foraddFavorite()(#552).お気に入り一覧API(#565)のInfra層として、ユーザーがお気に入り登録した世界遺産IDの一覧を取得できるようにする。
addFavorite()用に追加済みのfavorites()リレーションを再利用する。What to do / 実施内容
FavoriteRepositoryInterface::getFavoriteWorldHeritageIds(int $userId): arrayを追加FavoriteRepositoryに実装。お気に入り登録が新しい順(user_favorite.created_at desc)でIDを返す。ユーザーが存在しない場合はaddFavorite()と同様にException('User not found.')をスローUser::favorites()にwithTimestamps()を追加し、attach()時にpivotのcreated_atが自動設定されるようにするTests / テスト
実DB(
heritage-mysql-test)を使ったインテグレーションテストtest_getFavoriteWorldHeritageIds_returns_ids_ordered_by_most_recently_favoritedtest_getFavoriteWorldHeritageIds_returns_empty_array_when_no_favoritestest_getFavoriteWorldHeritageIds_throws_exception_when_user_not_foundStatus
実装済み。#564 で対応。