You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains 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
Why: Logging the error before returning an HTTP error response can aid in diagnosing issues, making this a valuable enhancement for debugging purposes.
Why: Setting a default visibility when visibility is nil can prevent unintended nil values, improving robustness. However, the suggestion assumes the existence of a defaultVisibility, which is not defined in the current context.
7
Maintainability
visibility 変数のスコープを if ブロック内に限定する
visibility 変数のスコープを限定するために、if ブロック内で vis 変数を直接参照するように変更してください。これにより、コードの可読性が向上します。
-switch game.GetVisibility() {+currentVisibility := game.GetVisibility()+switch currentVisibility {
case values.GameVisibilityTypePublic:
apiVisibility = openapi.Public
case values.GameVisibilityTypeLimited:
apiVisibility = openapi.Limited
case values.GameVisibilityTypePrivate:
apiVisibility = openapi.Private
default:
- log.Printf("error: failed to get game visibility: %v\n", game.GetVisibility())+ log.Printf("error: failed to get game visibility: %v\n", currentVisibility)
return echo.NewHTTPError(http.StatusInternalServerError, "failed to get game visibility")
}
Suggestion importance[1-10]: 5
Why: Storing the result of game.GetVisibility() in a temporary variable before comparison can make debugging easier, but it is a minor best practice improvement. The existing code is already functional without this change.
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.
User description
fix: #778
PR Type
enhancement, tests
Description
PATCH /games/{gameID}
エンドポイントで変更できるようになりました。visibility
フィールドのバリデーションを追加し、無効な可視性が指定された場合はエラーメッセージを返すようにしました。Changes walkthrough 📝
game.go
ゲームの可視性を更新する機能を追加
src/handler/v2/game.go
visibility
フィールドの追加と更新処理を実装visibility
のバリデーションを追加GameInfo
にvisibility
を含めるように変更v2_game.go
ゲームの可視性をデータベースで管理する機能を追加
src/repository/gorm2/v2_game.go
getVisibility
メソッドを追加VisibilityTypeID
の設定を追加visibility.go
可視性タイプの変換関数を追加
src/repository/gorm2/visibility.go
convertVisibilityType
関数を追加game.go
ゲームの可視性を更新するサービスロジックを追加
src/service/v2/game.go
visibility
パラメータをUpdateGame
メソッドに追加v2_game.go
ゲーム更新メソッドに可視性パラメータを追加
src/service/v2_game.go
UpdateGame
メソッドのシグネチャを変更game_test.go
ゲームの可視性更新に関するテストを追加
src/handler/v2/game_test.go
visibility
のテストケースを追加visibility
がnilの場合のテストを追加visibility
のアサーションを追加v2_game_test.go
可視性タイプの取得に関するテストを追加
src/repository/gorm2/v2_game_test.go
game_test.go
ゲームの可視性更新に関するサービスのテストを追加
src/service/v2/game_test.go
visibility
のテストケースを追加UpdateGame
メソッドのテストを更新