From 66b364428db4475820386f70c360a595490c3896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=86=E3=83=84=E3=83=8E=E3=83=8B=E3=82=B8=E3=82=AB?= <969+codex-bot@noreply.localhost> Date: Mon, 23 Nov 2026 03:09:52 +0900 Subject: [PATCH] =?UTF-8?q?AI:=20#439=20=E6=8A=95=E7=A8=BF=E3=81=AE=20?= =?UTF-8?q?=E2=80=9C=E9=96=B2=E8=A6=A7=E6=B8=88=E2=80=9D=20=E3=82=92?= =?UTF-8?q?=E5=86=AA=E7=AD=89=E3=81=AB=E3=81=99=E3=82=8B=20(#468)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs #439 Branch mode: `new`; base: `main`; head: `feature/439` Implementation model: `gpt-6-luna` / reasoning: `low` ## Automated implementation (requires human review) `POST /posts/:id/viewed` の登録を `UserPostView.create_or_find_by!` に変更しました。同じユーザーが同じ投稿を繰り返し閲覧済みにしても、複合キーの重複エラーになりません。 テスト、lint、ビルド等は実行していません。 ## Verification - Tests/builds/migrations were not authorized and were not invoked by the controller. - Codex was instructed not to run them; inspect its command transcript. - The repository owner alone reviews changes. No AI review is executed. - Do not merge before human acceptance and required checks. --------- Co-authored-by: みてるぞ Co-authored-by: Codex Night Worker Reviewed-on: https://git.miteruzo.com/miteruzo/btrc-hub/pulls/468 Co-authored-by: テツノニジカ <969+codex-bot@noreply.localhost> --- backend/app/controllers/posts_controller.rb | 4 +++- backend/spec/requests/posts_spec.rb | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/app/controllers/posts_controller.rb b/backend/app/controllers/posts_controller.rb index 2b4d7cd..fdd69ce 100644 --- a/backend/app/controllers/posts_controller.rb +++ b/backend/app/controllers/posts_controller.rb @@ -314,7 +314,9 @@ class PostsController < ApplicationController def viewed return head :unauthorized unless current_user - current_user.viewed_posts << Post.find(params[:id]) + UserPostView.create_or_find_by!( + user: current_user, + post: Post.find(params[:id])) head :no_content end diff --git a/backend/spec/requests/posts_spec.rb b/backend/spec/requests/posts_spec.rb index bee89c9..e994ca7 100644 --- a/backend/spec/requests/posts_spec.rb +++ b/backend/spec/requests/posts_spec.rb @@ -2637,6 +2637,21 @@ RSpec.describe 'Posts API', type: :request do expect(user.reload.viewed?(post_record)).to be(true) end + + it '204 and keeps one view on repeated requests' do + sign_in_as(user) + + expect { + post "/posts/#{ post_record.id }/viewed" + }.to change(UserPostView, :count).by(1) + expect(response).to have_http_status(:no_content) + + expect { + post "/posts/#{ post_record.id }/viewed" + }.not_to change(UserPostView, :count) + expect(response).to have_http_status(:no_content) + expect(user.reload.viewed?(post_record)).to be(true) + end end describe 'DELETE /posts/:id/viewed' do