Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getMeでDBを叩くように変更 #763

Open
wants to merge 9 commits into
base: v2
Choose a base branch
from
Open

Conversation

comavius
Copy link
Contributor

@comavius comavius commented Jun 7, 2024

#725

  • getMeでセッションからユーザーを取ってくる実装からDBからに変更
  • DBにユーザーが存在しない場合にセッションのユーザーをDBに追加

@comavius comavius requested a review from H1rono June 7, 2024 14:10
router/user.go Outdated Show resolved Hide resolved
router/user.go Outdated Show resolved Hide resolved
@H1rono
Copy link
Member

H1rono commented Jun 8, 2024

とりあえずこれ
あとテストの方を直す必要があります

@comavius comavius requested a review from H1rono July 9, 2024 07:04
Copy link
Member

@H1rono H1rono left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

まずは変数名をcamelCaseにしてください

@Hueter57 Hueter57 requested a review from H1rono November 8, 2024 14:47
Copy link
Member

@H1rono H1rono left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if err != nilreturn nil, errとするのは忘れずにお願いします 🙏

router/user.go Outdated Show resolved Hide resolved
@Hueter57 Hueter57 requested a review from H1rono November 8, 2024 16:06
router/user.go Outdated Show resolved Hide resolved
@Hueter57 Hueter57 requested a review from H1rono November 8, 2024 16:29
Copy link
Member

@H1rono H1rono left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テスト頑張ってください

--- FAIL: TestHandlers_GetMe (0.00s)
    --- FAIL: TestHandlers_GetMe/Success (0.00s)
        user.go:95: Unexpected call to *mock_model.MockUserRepository.GetUserByID([context.Background.WithValue(sessions.contextKey, *sessions.Registry) c[76](https://github.com/traPtitech/Jomon/actions/runs/11745765123/job/32723973343?pr=763#step:8:77)069f6-ae57-40ee-be7d-b7674589867a]) at /home/runner/work/Jomon/Jomon/router/user.go:95 because: there are no expected calls of the method "GetUserByID" for that receiver

Copy link

codecov bot commented Nov 14, 2024

Codecov Report

Attention: Patch coverage is 22.22222% with 7 lines in your changes missing coverage. Please review.

Project coverage is 25.23%. Comparing base (6b2f353) to head (c83bbe0).
Report is 10 commits behind head on v2.

Files with missing lines Patch % Lines
router/user.go 22.22% 6 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##               v2     #763   +/-   ##
=======================================
  Coverage   25.23%   25.23%           
=======================================
  Files         148      147    -1     
  Lines       30578    30572    -6     
=======================================
- Hits         7716     7715    -1     
+ Misses      21986    21980    -6     
- Partials      876      877    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Hueter57 Hueter57 requested a review from H1rono November 14, 2024 15:09
Comment on lines -12 to +18
ID uuid.UUID
Name string
DisplayName string
Admin bool
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time
ID uuid.UUID `json:"id"`
Name string `json:"name"`
DisplayName string `json:"display_name"`
Admin bool `json:"admin"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"deleted_at"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この変更は必要なんでしょうか?使ってないように見えるんですが

Copy link
Contributor

@Hueter57 Hueter57 Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この変更がないと予想される返り値のJSONのフィールド名が小文字なのに、実際は大文字が返ってきて違いますよと言われたので変更しました。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

手元で実行したら、こんな感じにエラー出ました

--- FAIL: TestHandlers_GetMe (0.00s)
    --- FAIL: TestHandlers_GetMe/Success (0.01s)
        user_test.go:334: 
                Error Trace:    /home/kohsuke/SysAd/Jomon/router/user_test.go:334
                Error:          Not equal: 
                                expected: "{\"id\":\"7a045fc6-0a22-4b71-b989-93527fef1afc\",\"name\":\"9LcsCLBUWB7xgcntarNB\",\"display_name\":\"aRN8KgouLCcUuD9QtnUY\",\"admin\":true,\"created_at\":\"2024-11-15T00:15:44.088301571+09:00\",\"updated_at\":\"2024-11-15T00:15:44.088301571+09:00\",\"deleted_at\":null}"
                                actual  : "{\"ID\":\"7a045fc6-0a22-4b71-b989-93527fef1afc\",\"Name\":\"9LcsCLBUWB7xgcntarNB\",\"DisplayName\":\"aRN8KgouLCcUuD9QtnUY\",\"Admin\":true,\"CreatedAt\":\"2024-11-15T00:15:44.088301571+09:00\",\"UpdatedAt\":\"2024-11-15T00:15:44.088301571+09:00\",\"DeletedAt\":null}"
                            
                                Diff:
                                --- Expected
                                +++ Actual
                                @@ -1 +1 @@
                                -{"id":"7a045fc6-0a22-4b71-b989-93527fef1afc","name":"9LcsCLBUWB7xgcntarNB","display_name":"aRN8KgouLCcUuD9QtnUY","admin":true,"created_at":"2024-11-15T00:15:44.088301571+09:00","updated_at":"2024-11-15T00:15:44.088301571+09:00","deleted_at":null}
                                +{"ID":"7a045fc6-0a22-4b71-b989-93527fef1afc","Name":"9LcsCLBUWB7xgcntarNB","DisplayName":"aRN8KgouLCcUuD9QtnUY","Admin":true,"CreatedAt":"2024-11-15T00:15:44.088301571+09:00","UpdatedAt":"2024-11-15T00:15:44.088301571+09:00","DeletedAt":null}
                Test:           TestHandlers_GetMe/Success

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

変更前はuserの型がrouter.Userだった(model.Userではなく)ので上手くできてたっぽいですね、ここでもそれに合わせてmodel.User型からrouter.User型への変換を行って欲しいです(適宜↓のようなヘルパー関数を作ってください)

package router

func userFromModelUser(u model.User) User { ... }

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.

4 participants