fix #4436 custom_entries Web API の page パラメータが機能しない問題を修正 - #4521
Merged
Conversation
公開 Web API GET /baser/api/bc-custom-content/custom_entries.json に page クエリパラメータを付けても、常に先頭から limit 件が返り、2ページ目以降の データが取得できなかった。 CustomEntriesService::getIndex() に page の処理が実装されておらず、limit の みが適用されていたことが原因。同プラグインの CustomContentsService::getIndex() には page 対応があり、ドキュメントにも page が使える旨の記載があるため、 実装漏れと判断した。 CustomContentsService::getIndex() と同じ方式で、limit が指定されている場合に page を適用するようにした。あわせて、条件生成へ渡す前に page を除外している。 createIndexConditions() は残ったキーをカスタムフィールド名として扱うため、 limit や order と同様に除外しておく必要がある。 なお limit の指定がない場合に page を無視する挙動は、CakePHP の Query::page() が limit 未指定時に 25 件を暗黙で適用してしまうためで、CustomContentsService と揃えている。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
既存サービスの実装方針に揃えた最小限の変更で、回帰を防ぐテスト追加も含まれているため。
Pull request overview
公開 Web API(GET /baser/api/bc-custom-content/custom_entries.json)で page クエリパラメータが limit と組み合わせても反映されず、常に先頭から同じ件数が返る問題(#4436)を修正し、既存の CustomContentsService::getIndex() と同様のページング挙動に統一するPRです。
Changes:
CustomEntriesService::getIndex()にpage+limit指定時のページング(Query::page())を追加createIndexConditions()側でpageが誤って検索条件扱いされないよう、unset()対象にpageを追加CustomEntriesServiceTest::test_getIndex()にページングの期待値(2ページ目が取得できること/limitなしならpageを無視すること)を追加
File summaries
| File | Description |
|---|---|
| plugins/bc-custom-content/src/Service/CustomEntriesService.php | limit 指定時に限り page を適用してページングできるようにし、page を条件生成から除外 |
| plugins/bc-custom-content/tests/TestCase/Service/CustomEntriesServiceTest.php | page が効いてページ分割できること、limit なしでは page を無視することをテストで固定 |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
公開 Web API
GET /baser/api/bc-custom-content/custom_entries.jsonにpageクエリパラメータを付けても2ページ目以降が取得できない問題(#4436)を修正しました。原因
CustomEntriesService::getIndex()にpageの処理が実装されておらず、limitのみが適用されていました。そのためpageを変えても常に先頭からlimit件が返っていました。同プラグインの
CustomContentsService::getIndex()にはpage対応があり、ドキュメント にもpageが使える旨の記載があるため、実装漏れと判断しました。変更内容
CustomContentsService::getIndex()と同じ方式に揃えました。unset()にpageを追加している理由createIndexConditions()は、既知のキーを取り除いた残りのキーをカスタムフィールド名として扱う実装になっています。order/direction/limitと同様にpageも除外しておかないと、pageという名前のカスタムフィールドが定義されている環境で意図しない絞り込みが発生します。limitがない場合にpageを無視する理由CakePHP の
Query::page()はlimit未指定時に 25 件を暗黙で適用します。?page=2のみを指定した既存の呼び出しが、これまでの「全件返却」から「25件返却」へ静かに変わってしまうため、CustomContentsServiceと同じくlimit指定時のみpageを適用する挙動としています。この点はテストでも固定しています。テスト
CustomEntriesServiceTest::test_getIndex()に検証を追加しました。修正を戻した状態でこのテストが失敗することを確認しています(2ページ目に1ページ目と同じ2件が返る)。
実行結果
CustomEntriesServiceTestbc-custom-contentの API テストbc-custom-content全体※ Incomplete は既存のスキップです。
🤖 Generated with Claude Code
Generated by Claude Code