Parent Issue / 親Issue
#550
Motivation / 目的
Implement the Domain layer for the Favorite Heritage API as part of #550: the repository interface and the migration for the new intermediate table. No FavoriteEntity is introduced — a favorite has no behavior/invariants beyond the (user, heritage) pair existing, so the repository interface works directly with primitive IDs instead of wrapping them in an Entity.
お気に入りAPIのDomain層(#550)として、リポジトリインターフェースと中間テーブルのmigrationを実装します。FavoriteEntityは作成しません。お気に入りは(user, heritage)の組が存在するだけで振る舞い・不変条件を持たないため、Entityでラップせずリポジトリインターフェースは素のIDを直接扱います。
What to do / 実施内容
Migration
create_favorite_heritages_table
Repository Interface
FavoriteRepositoryInterface.php
add(int $userId, int $worldHeritageId): void
remove(int $userId, int $worldHeritageId): void
existsForUser(int $userId, int $worldHeritageId): bool
findHeritageIdsByUserId(int $userId): array
Exception
FavoriteAlreadyExistsException: 既に登録済みのお気に入りを再登録しようとした場合にスロー
FavoriteNotFoundException: 未登録のお気に入りを解除しようとした場合にスロー
Tests / テスト
- Migration実行後、
favorite_heritages テーブルが期待するカラム・FK・unique制約を持つことの確認
Parent Issue / 親Issue
#550
Motivation / 目的
Implement the Domain layer for the Favorite Heritage API as part of #550: the repository interface and the migration for the new intermediate table. No
FavoriteEntityis introduced — a favorite has no behavior/invariants beyond the (user, heritage) pair existing, so the repository interface works directly with primitive IDs instead of wrapping them in an Entity.お気に入りAPIのDomain層(#550)として、リポジトリインターフェースと中間テーブルのmigrationを実装します。
FavoriteEntityは作成しません。お気に入りは(user, heritage)の組が存在するだけで振る舞い・不変条件を持たないため、Entityでラップせずリポジトリインターフェースは素のIDを直接扱います。What to do / 実施内容
Migration
create_favorite_heritages_tableiduser_id(FKusers.id,cascadeOnDelete)world_heritage_site_id(FKworld_heritage_sites.id,cascadeOnDelete)timestampsunique(['user_id', 'world_heritage_site_id'])Repository Interface
FavoriteRepositoryInterface.phpadd(int $userId, int $worldHeritageId): voidremove(int $userId, int $worldHeritageId): voidexistsForUser(int $userId, int $worldHeritageId): boolfindHeritageIdsByUserId(int $userId): arrayException
FavoriteAlreadyExistsException: 既に登録済みのお気に入りを再登録しようとした場合にスローFavoriteNotFoundException: 未登録のお気に入りを解除しようとした場合にスローTests / テスト
favorite_heritagesテーブルが期待するカラム・FK・unique制約を持つことの確認