Skip to content

feat: implement Infra layer for favorite heritages list API / お気に入り一覧APIのInfra層実装 #566

Description

@zigzagdev

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 で対応。

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions