feat: PUT /sponsorship_activities/{id}/status の実装#1065
Conversation
- OpenAPI に UpdateSponsorshipActivityStatusRequest スキーマを追加 - Repository: UpdateStatus に goqu による SQL 実装を追加 - UseCase: UpdateSponsorshipActivityStatus のシグネチャを generated 型に統一し、更新後に全体を返すよう実装 - Handler: mock を本実装に置き換え Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Deploying finansu with
|
| Latest commit: |
f061304
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://9fc5befc.finansu.pages.dev |
| Branch Preview URL: | https://feat-kubosaka-update-sponsor-rh9a.finansu.pages.dev |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! このプルリクエストは、協賛活動のステータスを個別に更新するための新しいAPIエンドポイントを導入します。これにより、活動の進捗や可否、デザインの状況、備考を効率的に管理できるようになり、システム全体の柔軟性と機能性が向上します。 Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
このプルリクエストは、協賛活動のステータスを更新するための PUT /sponsorship_activities/{id}/status エンドポイントを実装するものです。OpenAPI定義の更新、ハンドラ、ユースケース、リポジトリ層の実装が含まれています。全体的に、プルリクエストの目的に沿った良い実装です。エラーハンドリングと堅牢性をさらに向上させるための提案をいくつかコメントしました。また、多くのフロントエンドファイルにフォーマットの変更が加えられていますが、これらは問題ないようです。
| _, err = r.client.DB().ExecContext(ctx, query, args...) | ||
| return err |
There was a problem hiding this comment.
UPDATEクエリ実行後、実際にレコードが更新されたかを確認することをお勧めします。ExecContextは対象のレコードが存在しない場合でもエラーを返しません。result.RowsAffected()をチェックし、更新された行が0の場合はsql.ErrNoRowsのようなエラーを返すことで、呼び出し元が存在しないIDに対する更新を検知できるようになります。これにより、APIはより堅牢になり、クライアントに404 Not Foundのような適切なステータスコードを返すことが可能になります。
result, err := r.client.DB().ExecContext(ctx, query, args...)
if err != nil {
return err
}
rowsAffected, err := result.RowsAffected()
if err != nil {
return err
}
if rowsAffected == 0 {
return sql.ErrNoRows
}
return nil| if err := c.Bind(&req); err != nil { | ||
| return c.String(http.StatusBadRequest, "Bad Request") | ||
| } | ||
|
|
||
| updated, err := h.sponsorshipActivityUseCase.UpdateSponsorshipActivityStatus(c.Request().Context(), id, req) | ||
| if err != nil { | ||
| return c.String(http.StatusInternalServerError, "failed to update status") | ||
| } |
There was a problem hiding this comment.
エラーハンドリングを改善し、他のハンドラとの一貫性を保つことをお勧めします。c.String()で固定の文字列を返す代わりに、echoのデフォルトエラーハンドラに処理を委譲するために、単にreturn errとするのが一般的です。これにより、API全体で一貫したエラーレスポンス形式を維持しやすくなります。
| if err := c.Bind(&req); err != nil { | |
| return c.String(http.StatusBadRequest, "Bad Request") | |
| } | |
| updated, err := h.sponsorshipActivityUseCase.UpdateSponsorshipActivityStatus(c.Request().Context(), id, req) | |
| if err != nil { | |
| return c.String(http.StatusInternalServerError, "failed to update status") | |
| } | |
| if err := c.Bind(&req); err != nil { | |
| return err | |
| } | |
| updated, err := h.sponsorshipActivityUseCase.UpdateSponsorshipActivityStatus(c.Request().Context(), id, req) | |
| if err != nil { | |
| return err | |
| } |
対応Issue
resolve #0
概要
協賛活動のステータスのみを更新する API (
PUT /sponsorship_activities/{id}/status) を実装。UpdateSponsorshipActivityStatusRequestスキーマを追加し、requestBody を$refに変更UpdateStatus()に goqu による UPDATE SQL を実装UpdateSponsorshipActivityStatus()のシグネチャをgenerated型に統一し、更新後に全データを返すよう実装更新対象フィールド:
activityStatus/feasibilityStatus/designProgress/remarksテスト項目
PUT /sponsorship_activities/{id}/statusで各ステータスフィールドが更新されることSponsorshipActivity全体が返ることremarksを省略した場合も正常に動作すること備考
なし