diff --git a/backend/app/controllers/posts_controller.rb b/backend/app/controllers/posts_controller.rb index 310c449..3c15d7c 100644 --- a/backend/app/controllers/posts_controller.rb +++ b/backend/app/controllers/posts_controller.rb @@ -127,7 +127,7 @@ class PostsController < ApplicationController post = Post.new(title:, url:, thumbnail_base: nil, uploaded_user: current_user, original_created_from:, original_created_before:) - post.thumbnail.attach(thumbnail) + post.thumbnail.attach(thumbnail) if thumbnail.present? ApplicationRecord.transaction do post.save! @@ -149,8 +149,8 @@ class PostsController < ApplicationController render json: PostRepr.base(post), status: :created rescue ArgumentError => e render json: { errors: [e.message] }, status: :unprocessable_entity - rescue ActiveRecord::RecordInvalid - render json: { errors: post.errors.full_messages }, status: :unprocessable_entity + rescue ActiveRecord::RecordInvalid => e + render json: { errors: e.record.errors.full_messages }, status: :unprocessable_entity rescue Tag::NicoTagNormalisationError head :bad_request end @@ -204,8 +204,8 @@ class PostsController < ApplicationController render json:, status: :ok rescue ArgumentError => e render json: { errors: [e.message] }, status: :unprocessable_entity - rescue ActiveRecord::RecordInvalid - render json: post.errors, status: :unprocessable_entity + rescue ActiveRecord::RecordInvalid => e + render json: { errors: e.record.errors.full_messages }, status: :unprocessable_entity rescue Tag::NicoTagNormalisationError head :bad_request end diff --git a/backend/app/models/post.rb b/backend/app/models/post.rb index 02b4c08..d036fae 100644 --- a/backend/app/models/post.rb +++ b/backend/app/models/post.rb @@ -56,7 +56,7 @@ class Post < ApplicationRecord def snapshot_tag_names = tags.joins(:tag_name).order('tag_names.name').pluck('tag_names.name') - def snapshot_parent_post_ids = parents.order(:parent_post_id).pluck(:parent_post_id) + def snapshot_parent_post_ids = parents.order(:id).pluck(:id) def related limit: nil ids = post_similarities.order(cos: :desc) diff --git a/frontend/src/components/PostEditForm.tsx b/frontend/src/components/PostEditForm.tsx index 5558e69..f584117 100644 --- a/frontend/src/components/PostEditForm.tsx +++ b/frontend/src/components/PostEditForm.tsx @@ -52,6 +52,9 @@ export default (({ post, onSave }: Props) => { onSave ({ ...post, title: data.title, tags: data.tags, + parentPosts: data.parentPosts, + childPosts: data.childPosts, + siblingPosts: data.siblingPosts, originalCreatedFrom: data.originalCreatedFrom, originalCreatedBefore: data.originalCreatedBefore } as Post) toast ({ description: '更新しました.' }) diff --git a/frontend/src/components/PostList.tsx b/frontend/src/components/PostList.tsx index 582762e..8bd6118 100644 --- a/frontend/src/components/PostList.tsx +++ b/frontend/src/components/PostList.tsx @@ -42,8 +42,8 @@ export default (({ posts, onClick }: Props) => { layoutId={layoutId} className={cn ('w-full h-full overflow-hidden rounded-xl shadow', 'transform-gpu will-change-transform', - (post.childPosts ?? []).length > 0 && 'border-4 border-green-500', - (post.parentPosts ?? []).length > 0 && 'border-4 border-yellow-500')} + (post.childPosts ?? []).length > 0 && 'outline-4 border-green-500', + (post.parentPosts ?? []).length > 0 && 'outline-4 border-yellow-500')} whileHover={{ scale: 1.02 }} onLayoutAnimationStart={() => { if (!(cardRef.current)) diff --git a/frontend/src/pages/posts/PostHistoryPage.tsx b/frontend/src/pages/posts/PostHistoryPage.tsx index 564ed79..825efe9 100644 --- a/frontend/src/pages/posts/PostHistoryPage.tsx +++ b/frontend/src/pages/posts/PostHistoryPage.tsx @@ -95,8 +95,8 @@ export default (() => { {/* タグ */} - {/* 親投稿 */} - + {/* TODO: 親投稿 */} + {/* */} {/* オリジナルの投稿日時 */} {/* 更新日時 */} @@ -112,7 +112,8 @@ export default (() => { タイトル URL タグ - 親投稿 + {/* TODO: 親投稿の履歴 */} + {/* 親投稿 */} オリジナルの投稿日時 更新日時 @@ -183,7 +184,8 @@ export default (() => { {tag.name} ))))} - + {/* TODO: 親投稿の履歴 */} + {/* {change.parentPosts.map ((pp, i) => ( pp.type === 'added' ? ( @@ -204,7 +206,7 @@ export default (() => { {pp.title} ))))} - + */} {change.versionNo === 1 ? originalCreatedAtString (change.originalCreatedFrom.current, @@ -251,7 +253,10 @@ export default (() => { .filter (t => t.slice (0, 5) !== 'nico:') .join (' '), parent_post_ids: - change.parentPosts.map (p => p.id).join (' '), + change.parentPosts + .filter (p => p.type !== 'removed') + .map (p => p.id) + .join (' '), original_created_from: change.originalCreatedFrom.current, original_created_before: