ブックマーク編集・削除機能を追加#4
Conversation
📝 WalkthroughWalkthroughこのPRはブックマークアプリの編集・削除機能を実装します。リポジトリにfindById/update/deleteメソッドを追加し、コントローラで対応するエンドポイントと入力正規化・バリデーションロジックを実装。Thymeleafテンプレートと新規スタイルで編集フォームと操作UIを構築し、MockMvcテストでCRUD操作を包括的に検証します。 Changesブックマーク編集・削除機能実装
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/com/example/bookmark/BookmarkController.java`:
- Around line 92-95: Current code checks existence with
bookmarkRepository.findById(id) before calling update/delete, which can race
with concurrent requests; instead call the update(...) method and use its return
value (or affected-row count) to determine success and set
redirectAttributes.addFlashAttribute("error", ...) when update(...) indicates
failure; remove reliance on the prior existence check (or keep it only for early
fast-fail) but always treat update(...)'s boolean/rows-updated as the final
authority for both the update(...) call(s) and the similar case around the lines
107-108, returning "redirect:/" with an error flash when the update indicates no
rows were changed.
In `@src/test/java/com/example/bookmark/BookmarkControllerTest.java`:
- Line 20: テストで使っている固定パス "/private/tmp/..." を OS 依存にしないため、BookmarkControllerTest
の `@SpringBootTest`(properties = "...") に設定している spring.datasource.url を相対パス(例:
"./build/tmp/bookmark-controller-test.db")か System.getProperty("java.io.tmpdir")
を使った一意のパスに置き換えてください; 具体的には BookmarkControllerTest クラスの `@SpringBootTest`
アノテーション内プロパティ文字列を動的に組み立てるか、テスト用のプロパティプロバイダ(環境変数・@TestPropertySource など)を使って
java.io.tmpdir ベースのパスを設定し、CI や他OSでも同じように動作するようにしてください.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e0c9c868-a936-42bb-90a5-c6019124096f
📒 Files selected for processing (8)
.coderabbit.yaml.gitignoresrc/main/java/com/example/bookmark/BookmarkController.javasrc/main/java/com/example/bookmark/BookmarkRepository.javasrc/main/resources/static/styles.csssrc/main/resources/templates/edit.htmlsrc/main/resources/templates/index.htmlsrc/test/java/com/example/bookmark/BookmarkControllerTest.java
| if (bookmarkRepository.findById(id).isEmpty()) { | ||
| redirectAttributes.addFlashAttribute("error", "ブックマークが見つかりません。"); | ||
| return "redirect:/"; | ||
| } |
There was a problem hiding this comment.
更新結果を最終判定に使ってください。
存在確認後に別リクエストで削除されると、更新失敗でも成功扱いになります。update(...) の戻り値で判定してエラーを返すようにしてください。
💡 修正案
- if (bookmarkRepository.findById(id).isEmpty()) {
- redirectAttributes.addFlashAttribute("error", "ブックマークが見つかりません。");
- return "redirect:/";
- }
-
BookmarkForm form = normalize(title, description, tags);
String validationError = validate(form);
if (validationError != null) {
redirectAttributes.addFlashAttribute("error", validationError);
redirectAttributes.addFlashAttribute("title", title);
redirectAttributes.addFlashAttribute("description", description);
redirectAttributes.addFlashAttribute("tags", tags);
return "redirect:/bookmarks/" + id + "/edit";
}
- bookmarkRepository.update(id, form.title(), form.description(), form.tags());
+ if (!bookmarkRepository.update(id, form.title(), form.description(), form.tags())) {
+ redirectAttributes.addFlashAttribute("error", "ブックマークが見つかりません。");
+ }
return "redirect:/";Also applies to: 107-108
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/main/java/com/example/bookmark/BookmarkController.java` around lines 92 -
95, Current code checks existence with bookmarkRepository.findById(id) before
calling update/delete, which can race with concurrent requests; instead call the
update(...) method and use its return value (or affected-row count) to determine
success and set redirectAttributes.addFlashAttribute("error", ...) when
update(...) indicates failure; remove reliance on the prior existence check (or
keep it only for early fast-fail) but always treat update(...)'s
boolean/rows-updated as the final authority for both the update(...) call(s) and
the similar case around the lines 107-108, returning "redirect:/" with an error
flash when the update indicates no rows were changed.
| import org.springframework.jdbc.core.JdbcTemplate; | ||
| import org.springframework.test.web.servlet.MockMvc; | ||
|
|
||
| @SpringBootTest(properties = "spring.datasource.url=jdbc:sqlite:/private/tmp/bookmark-controller-test.db") |
There was a problem hiding this comment.
テストDBパスをOS非依存にしてください。
/private/tmp 固定は実行環境依存で、CI/他OSで失敗しやすいです。相対パス(例: ./build/...)か java.io.tmpdir ベースに変更してください。
💡 修正案
-@SpringBootTest(properties = "spring.datasource.url=jdbc:sqlite:/private/tmp/bookmark-controller-test.db")
+@SpringBootTest(properties = "spring.datasource.url=jdbc:sqlite:./build/bookmark-controller-test.db")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| @SpringBootTest(properties = "spring.datasource.url=jdbc:sqlite:/private/tmp/bookmark-controller-test.db") | |
| `@SpringBootTest`(properties = "spring.datasource.url=jdbc:sqlite:./build/bookmark-controller-test.db") |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/test/java/com/example/bookmark/BookmarkControllerTest.java` at line 20,
テストで使っている固定パス "/private/tmp/..." を OS 依存にしないため、BookmarkControllerTest の
`@SpringBootTest`(properties = "...") に設定している spring.datasource.url を相対パス(例:
"./build/tmp/bookmark-controller-test.db")か System.getProperty("java.io.tmpdir")
を使った一意のパスに置き換えてください; 具体的には BookmarkControllerTest クラスの `@SpringBootTest`
アノテーション内プロパティ文字列を動的に組み立てるか、テスト用のプロパティプロバイダ(環境変数・@TestPropertySource など)を使って
java.io.tmpdir ベースのパスを設定し、CI や他OSでも同じように動作するようにしてください.
概要
fixes #3
テスト
Summary by CodeRabbit
新機能
スタイル
テスト