Skip to content

fix: reviews の作成・更新・削除をプレースホルダ化する (#529) - #531

Merged
taminororo merged 1 commit into
developfrom
fix/kanba/529/reviews-placeholder
Sep 17, 2026
Merged

taminororo merged 1 commit into
developfrom
fix/kanba/529/reviews-placeholder

Conversation

@taminororo

@taminororo taminororo commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

Close #529
Ref #363

変更内容

review_repository.go の Create / Update / Delete から文字列連結をなくし、プレースホルダに置き換える。

コメントはユーザーの自由記述がそのままクォート内に連結されていたため、アポストロフィを1つ含むだけで INSERT が壊れ、アプリには「レビューの送信に失敗しました」とだけ出て入力が失われていた。同じ経路で SQL インジェクションも成立しうる。

ファイル: api/lib/internals/repository/review_repository.go
変更前 L80: VALUES (` + userID + ", " + taskID + ", " + staffingRating + ", " + manualRating + ", '" + comment + "')"
変更後 L81: VALUES ($1::int, $2::int, $3::int, $4::int, $5)`

repository の引数は string のまま受けるため、数値カラムへは $1::int と明示的にキャストし、パラメータの型推論に依存しない形にしている。

Crud はもともと可変長引数を受けるので、呼び出し側の変更だけで済んでいる。

ファイル: api/lib/internals/repository/abstract/abstract_repository.go
L48: func (a abstractRepository) UpdateDB(ctx context.Context, query string, args ...interface{}) error {
L49: 	_, err := a.client.DB().ExecContext(ctx, query, args...)

テスト

review_repository_sqlmock_test.go を追加した。コメントがクエリ本文ではなく引数として渡ることを固定するテストで、文字列連結に戻すと失敗する。アポストロフィを含むコメントを使っている。

  • TestReviewRepositoryCreate_PassesCommentAsArgument
  • TestReviewRepositoryUpdate_PassesCommentAsArgumentAndIDLast(WHERE の id が末尾の $6 であることも固定)
  • TestReviewRepositoryDelete_PassesIDAsArgument

スコープ外

#363 に挙がっている他の repository(department / place / bureau / grade / time / shift)は触っていない。#363 は引き続き開いたままにする。

動作確認

  • go build ./... — 成功
  • go vet ./lib/internals/repository/ — 指摘なし
  • go test ./... — repository・usecase ともに ok
  • golangci-lint run ./lib/internals/repository/... — 0 issues

Summary by CodeRabbit

  • セキュリティ改善

    • レビュー情報の作成・更新・削除で、入力値を安全に処理するよう改善しました。
    • アポストロフィなどの特殊文字を含むコメントも、正しく保存・更新できるようになりました。
  • テスト

    • レビュー情報の各操作について、安全な入力処理を検証するテストを追加しました。

@coderabbitai

coderabbitai Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 8ea5cd5f-37b3-4933-9ab8-4f1f0bca0ce9

📥 Commits

Reviewing files that changed from the base of the PR and between 26cf90a and 3505ce8.

📒 Files selected for processing (2)
  • api/lib/internals/repository/review_repository.go
  • api/lib/internals/repository/review_repository_sqlmock_test.go

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

ReviewRepositoryのCreate、Update、Deleteをパラメータ化SQLへ変更しました。SQL文字列への値の連結を削除し、バインド引数を使用します。sqlmockテストで各操作の引数を検証します。

Changes

レビューSQLのパラメータ化

Layer / File(s) Summary
レビュー操作のSQLパラメータ化と検証
api/lib/internals/repository/review_repository.go, api/lib/internals/repository/review_repository_sqlmock_test.go
Create、Update、Deleteが$1形式のプレースホルダーと個別の引数を使用します。数値カラムには::intキャストを指定します。sqlmockテストが、コメントを含む各引数のバインドを検証します。

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 3505c

Review creation, update, and deletion now safely handle quoted comments and do not interpolate operation values into SQL. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed タイトルは、レビューの作成・更新・削除をプレースホルダ化する主要変更を明確に示しています。
Description check ✅ Passed 説明にはIssue情報、変更概要、テスト項目、スコープ外の変更、動作確認結果が記載されています。スクリーンショットは対象外で、テンプレートの要件を十分に満たしています。
Linked Issues check ✅ Passed #529 の要件を満たしています。review_repository.go の Create、Update、Delete は SQL の文字列連結を使用せず、値を UpdateDB の引数として渡しています。数値カラムと id には ::int キャストがあります。追加された sqlmock テストは、コメントを含む各値が SQL 引数として渡されることを確認します。ア…
Out of Scope Changes check ✅ Passed 変更は review_repository.go と対応する sqlmock テストに限定されています。#529 が対象外とする department、place、bureau、grade、time、shift の repository には変更がありません。テスト追加は #529 の実装確認に直接関連します。
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@taminororo
taminororo merged commit 80986fc into develop Sep 17, 2026
3 checks passed
@taminororo
taminororo deleted the fix/kanba/529/reviews-placeholder branch September 17, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

【api】reviews の作成・更新・削除をプレースホルダ化する(#363 の子)

1 participant