Open shm11C3 opened 1 year ago
中間テーブルを用いてポリモーフィック関連を回避したい
p.67
erDiagram
posts_reactions }o--|| posts: ""
posts_reactions }o--|| reactions: ""
comments ||--o{ comments_reactions: ""
reactions ||--o{ comments_reactions: ""
posts_comments }o--|| posts: ""
posts_comments }o--|| comments: ""
users {
string auth_id
string name
string username
integer country_id
string profile_img_uri
integer delete_flg
timestamp created_at
timestamp updated_at
}
posts {
string ulid
string auth_id
string category_uuid
string title
string content
integer is_draft
integer is_publish
integer is_edited
integer is_deleted
timestamp created_at
timestamp updated_at
}
posts_reactions {
string post_ulid
string reaction_ulid
}
comments_reactions {
string reaction_ulid
string comment_ulid
}
posts_comments {
string post_ulid
string comment_ulid
}
reactions {
string ulid
string user_auth_id
string reaction_type
}
comments {
string ulid
string user_auth_id
string post_ulid
string comment
timestamp updated_at
}
テーブルの追加
reactions
comments
エンドポイント
GET:/reaction-types
POST:/reaction
DELETE:/reaction
POST:/comment
GET:/comment
PUT:/comment
DELETE:/comment
ReactionController.php
reactions
,comments
のCRUD処理AddReactionRequest.php
POST:/reaction
で使用post_ulid
required|ulid
リアクションの親要素 親要素存在チェックはコントローラで行うreaction_type
required
Rule
を作成し、reaction_type
が正しいかバリデーションするDeleteReactionRequest.php
DELETE:/reaction
で使用ulid
required|ulid|exists:reactions,ulid
AddCommentRequest.php
POST:/comment
で使用post_ulid
required|ulid
リアクションの親要素 親要素存在チェックはコントローラで行うcomment
required|string|max:255
UpdateCommentRequest.php
PUT:/comment
で使用ulid
required|exists:reactions,ulid
comment
required|string|max:255
DeleteCommentRequest.php
DELETE:/comment
で使用ulid
required|exists:reactions,ulid
Reaction.php
reactions.reaction_type
の値を定数として管理