fix: rollback#88
Conversation
Walkthrough/stores エンドポイントと StoresController を追加し、フロントは /stores から検証付きで店舗一覧を取得してマーカー表示。種データは db/seeds/stores/**/*.json を読んで rails db:seed で投入。stores.tel カラムと関連マイグレーションを追加。検索UIとフッターの検索フォームを導入。 Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant Browser
participant MapsJS as MapsController(JS)
participant Rails as Rails Router
participant StoresCtrl as StoresController#index
participant DB
User->>Browser: ページ表示
Browser->>MapsJS: Stimulus connect
MapsJS->>Rails: GET /stores
Rails->>StoresCtrl: ルーティング
StoresCtrl->>DB: SELECT stores (id,name,lat,lon,open_time,address,tel)
DB-->>StoresCtrl: レコード
StoresCtrl-->>MapsJS: JSON 配列
MapsJS->>MapsJS: StoreSchema で検証(valibot)
MapsJS->>Browser: マーカー生成/更新
sequenceDiagram
autonumber
actor Dev as Developer
participant Rails as Rails (db:seed)
participant FS as FileSystem
participant JSON as JSON Parser
participant DB
Dev->>Rails: rails db:seed
Rails->>FS: enumerate db/seeds/stores/**/*.json
loop 各ファイル
Rails->>JSON: parse file
JSON-->>Rails: entries[]
loop 各エントリ
Rails->>Rails: validate/normalize fields (name,address,lat,lon,tel,open_time)
Rails->>DB: check existence (coords OR name+address)
alt not exists
Rails->>DB: INSERT store (lat,lon,name,address,open_time?,tel?)
else
Rails->>Rails: skip & collect warning
end
end
end
Rails-->>Dev: 日本語の作成/スキップ/警告サマリ
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (1)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/assets/stylesheets/main.scss (1)
350-365: フォームに幅60pxが強制され検索バーがはみ出す—検索用クラスを追加して解消.form に footer__button を使うと width: 60px が当たり、検索バー(150px)がレイアウト崩れします。検索専用のクラスを追加して幅を自動に。
.footer { &__container { @@ } &__button { @extend %button-reset; @include flexbox($justify: center, $align: center); width: 60px; } + + &__search { + @extend %button-reset; + @include flexbox($justify: center, $align: center); + width: auto; + } }ビュー側では form の class を footer__search に変更(別コメントのdiff参照)。
🧹 Nitpick comments (9)
app/helpers/stores_helper.rb (1)
1-2: 空のヘルパーは不要なら削除、または直近で使う予定のヘルパーを追加現状未使用です。将来追加予定がなければ削除して差分ノイズを減らすと良いです。
app/assets/stylesheets/main.scss (1)
369-378: アセットパイプライン連携のため background-image は image-url を推奨fingerprint対応・CDN配信互換のため、SCSS内では image-url を使うと安全です。
- background-image: url("search-bar-center.png"); + background-image: image-url("search-bar-center.png");Sprockets/Sass-Rails を使用している前提です。別ツールチェーンの場合は相応のヘルパ(asset-url 等)へ調整ください。
app/javascript/controllers/maps_controller.js (1)
36-57: サーバが返す shareInfo をスキーマに含めて明示対応(表示欠落のリスク回避)コード全体で shop.shareInfo を参照していますが、StoreSchema に定義がありません。バリデーションで未知キーが削除・無視される場合、表示が崩れます。オプショナルで良いので schema に追加を推奨。
const StoreSchema = v.object({ id: v.number(), name: v.string(), lat: v.number(), lon: v.number(), open_time: v.nullable( @@ address: v.string(), eco: v.boolean(), foodshare: v.boolean(), tel: v.nullable(v.string()), + shareInfo: v.optional( + v.object({ + itemName: v.string(), + description: v.string(), + takeDownTime: v.string(), + }) + ), });valibot の object 振る舞い(未知キーの保持/破棄)に依存します。現在のランタイムで unknown keys が保持されるかをご確認ください。保持されない場合は上記追加が必須です。
config/routes.rb (1)
27-28: API用途ならエンドポイントを絞り JSON をデフォルトに不要なCRUDを公開しないために index のみに限定し、JSON既定化を推奨。フロントからの取得安定性も向上します。
- resources :stores + resources :stores, only: [:index], defaults: { format: :json }この変更により HTML 画面が必要な場合は別途ルートが必要です。UI上で /stores HTML を使う要件がないか確認してください。
.gitignore (1)
40-42: シード用ディレクトリをサブディレクトリごと明示的に無視する将来の構成変更に強くするため、ワイルドカードを
**にしておくと意図が明確になります(現状でも多くの場合は動きますが、明示が安心)。-/db/seeds/stores/* +/db/seeds/stores/** !/db/seeds/stores/.keeptest/fixtures/stores.yml (1)
2-10: open_time の表現が混在(プレーン文字列 vs JSON文字列)フィクスチャ内で表現が異なるため、利用側のパースが不安定になります。どちらかに統一してください(例: すべてプレーン文字列として保存、または複雑な場合のみJSON化して保存し、API側でキー名を統一)。
フロントエンドが期待するキーとフォーマット(open_time か openTime、JSONか文字列)を確認お願いします。
Also applies to: 13-21
test/controllers/stores_controller_test.rb (1)
1-7: ダミーではなく /stores の統合テストを追加しましょう基本的な200/JSON形状の検証を入れてリグレッションを防ぎましょう。
require "test_helper" class StoresControllerTest < ActionDispatch::IntegrationTest - # test "the truth" do - # assert true - # end + test "GET /stores returns stores JSON" do + get stores_url # resources :stores がある前提 + assert_response :success + + json = JSON.parse(response.body) + assert_kind_of Array, json + assert json.first.key?("id") + assert json.first.key?("name") + assert json.first.key?("lat") + assert json.first.key?("lon") + assert json.first.key?("address") + assert json.first.key?("tel") + # open_time か openTime のどちらを返すかはAPI仕様に合わせて調整 + end endREADME.md (1)
241-248: コマンド例の$先頭は外す(markdownlint: MD014)lint回避のため、コマンド先頭の
$は外すのが無難です。-```bash -$ rails db:seed -``` +```bash +rails db:seed +```app/controllers/stores_controller.rb (1)
4-13: 必要カラム取得と座標フィルタリング、JSONキーopen_time維持
.select(:id, :name, :lat, :lon, :open_time, :address, :tel).where.not(lat: nil, lon: nil)で不要データ排除- フロントが
shop.open_timeを参照しているため、キーはsnake_caseのままにapp/controllers/stores_controller.rb - @stores = Store.all + @stores = Store + .select(:id, :name, :lat, :lon, :open_time, :address, :tel) + .where.not(lat: nil, lon: nil)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (5)
app/assets/images/search-bar-center.pngis excluded by!**/*.pngapp/assets/images/search-bar-left.pngis excluded by!**/*.pngapp/assets/images/search-bar-right.pngis excluded by!**/*.pngapp/assets/images/search-bar.pngis excluded by!**/*.pngapp/assets/images/search-btn.pngis excluded by!**/*.png
📒 Files selected for processing (15)
.gitignore(1 hunks)README.md(1 hunks)app/assets/stylesheets/main.scss(7 hunks)app/controllers/home_controller.rb(0 hunks)app/controllers/stores_controller.rb(1 hunks)app/helpers/stores_helper.rb(1 hunks)app/javascript/controllers/maps_controller.js(12 hunks)app/views/shared/_footer.html.erb(1 hunks)config/routes.rb(1 hunks)db/migrate/20251009221009_add_tel_to_stores.rb(1 hunks)db/schema.rb(1 hunks)db/seeds.rb(1 hunks)lib/tasks/import_stores.rake(0 hunks)test/controllers/stores_controller_test.rb(1 hunks)test/fixtures/stores.yml(1 hunks)
💤 Files with no reviewable changes (2)
- app/controllers/home_controller.rb
- lib/tasks/import_stores.rake
🧰 Additional context used
🧬 Code graph analysis (3)
app/controllers/stores_controller.rb (3)
app/controllers/home_controller.rb (3)
allow_unauthenticated_access(1-11)index(6-34)allow_unauthenticated_access(1-42)app/controllers/admin/stores_controller.rb (3)
layout(1-67)index(6-9)select(11-15)db/migrate/20251007000000_create_stores.rb (2)
change(1-15)change(2-14)
app/helpers/stores_helper.rb (4)
app/helpers/admin/stores_helper.rb (1)
module Admin::StoresHelper(1-2)app/helpers/application_helper.rb (1)
module ApplicationHelper(1-2)db/migrate/20251007000000_create_stores.rb (2)
change(2-14)change(1-15)db/migrate/20251010163305_add_store_id_to_measurements.rb (1)
change(1-5)
db/seeds.rb (1)
app/javascript/controllers/maps_controller.js (1)
json(503-503)
🪛 markdownlint-cli2 (0.18.1)
README.md
247-247: Dollar signs used before commands without showing output
(MD014, commands-show-output)
🔇 Additional comments (3)
app/javascript/controllers/maps_controller.js (1)
501-509: JSONレスポンスは既に明示的に返されています
StoresController#indexでrender json:を使用しているため、/storesへのリクエストでも常にJSONが返却されます。Acceptヘッダーや.json拡張子の指定は不要です。db/schema.rb (1)
71-72: LGTM(tel カラムの追加)スキーマ反映は問題ありません。
db/migrate/20251009221009_add_tel_to_stores.rb (1)
1-5: LGTM(tel の追加)マイグレーションは簡潔で問題ありません。必要なら将来的にフォーマットバリデーションはモデル側で。
| if files.empty? | ||
| puts "No seed files found to import (pattern=#{pattern})." | ||
| return | ||
| end |
There was a problem hiding this comment.
seeds.rb の実行停止バグ(トップレベル return)と open_time の二重エンコード回避
- Line 11 のトップレベル
returnはrails db:seed実行時にLocalJumpErrorになり得ます。除去してください。 open_timeが文字列のときまでJSON.generateすると二重にクオートされた文字列が保存されます。型で分岐しましょう。- 警告メッセージの余分な
)を削除。
if files.empty?
puts "No seed files found to import (pattern=#{pattern})."
- return
end
@@
- attrs[:open_time] = JSON.generate(open_time) if open_time.present?
+ if open_time.present?
+ attrs[:open_time] = open_time.is_a?(String) ? open_time : JSON.generate(open_time)
+ end
attrs[:tel] = tel if tel.present?
@@
- warnings << "保存に失敗しました: #{file}) - #{name} #{store.errors.full_messages.join(', ')}"
+ warnings << "保存に失敗しました: #{file} - #{name} #{store.errors.full_messages.join(', ')}"補足:
- 全体をトランザクションで包むと途中失敗の整合性が上がります(任意)。
Also applies to: 81-83, 88-88
🤖 Prompt for AI Agents
In db/seeds.rb around lines 9-12 (also apply same fix pattern at 81-83 and 88),
remove the top-level `return` so `rails db:seed` won't raise LocalJumpError;
change the warning print to remove the extra closing parenthesis; and when
writing `open_time`, avoid double-encoding by only calling `JSON.generate` if
the value is not already a String (branch on the value's class and otherwise use
it directly). Optionally, wrap the seed import loop in a transaction to ensure
atomicity on partial failures.
|
@anmoti 良いならマージを |
|
ダメやこれ地図のピン出えへんわ |
|
@anmoti 俺ではどうしていいかよくわからん 多分ロールバック処理自体ミスってるんでこのPRはcloseで |
|
時間ねえぞ |
Summary by CodeRabbit
新機能
スタイル
ドキュメント
リファクタ
雑務