From 1c7fb77e0501f75478797838be51e2cca130b23f Mon Sep 17 00:00:00 2001 From: Steven Date: Sat, 16 Dec 2023 12:18:53 +0800 Subject: [PATCH] chore: update user setting names --- api/v1/auth.go | 2 +- api/v1/memo.go | 4 ++-- api/v2/user_service.go | 14 +++++++------- server/integration/telegram.go | 2 +- store/user_setting.go | 12 ++++++------ test/store/user_setting_test.go | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/api/v1/auth.go b/api/v1/auth.go index 625873ea..24cbdcd8 100644 --- a/api/v1/auth.go +++ b/api/v1/auth.go @@ -359,7 +359,7 @@ func (s *APIV1Service) UpsertAccessTokenToStore(ctx context.Context, user *store Description: "Account sign in", } userAccessTokens = append(userAccessTokens, &userAccessToken) - if _, err := s.Store.UpsertUserSettingV1(ctx, &storepb.UserSetting{ + if _, err := s.Store.UpsertUserSetting(ctx, &storepb.UserSetting{ UserId: user.ID, Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS, Value: &storepb.UserSetting_AccessTokens{ diff --git a/api/v1/memo.go b/api/v1/memo.go index 96c3ed07..f107924d 100644 --- a/api/v1/memo.go +++ b/api/v1/memo.go @@ -265,7 +265,7 @@ func (s *APIV1Service) CreateMemo(c echo.Context) error { } if createMemoRequest.Visibility == "" { - userMemoVisibilitySetting, err := s.Store.GetUserSettingV1(ctx, &store.FindUserSetting{ + userMemoVisibilitySetting, err := s.Store.GetUserSetting(ctx, &store.FindUserSetting{ UserID: &userID, Key: storepb.UserSettingKey_USER_SETTING_MEMO_VISIBILITY, }) @@ -389,7 +389,7 @@ func (s *APIV1Service) CreateMemo(c echo.Context) error { // Send notification to telegram if memo is not private. if memoResponse.Visibility != Private { // fetch all telegram UserID - userSettings, err := s.Store.ListUserSettingsV1(ctx, &store.FindUserSetting{Key: storepb.UserSettingKey_USER_SETTING_TELEGRAM_USER_ID}) + userSettings, err := s.Store.ListUserSettings(ctx, &store.FindUserSetting{Key: storepb.UserSettingKey_USER_SETTING_TELEGRAM_USER_ID}) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to ListUserSettings").SetInternal(err) } diff --git a/api/v2/user_service.go b/api/v2/user_service.go index 250c1c13..bc625125 100644 --- a/api/v2/user_service.go +++ b/api/v2/user_service.go @@ -201,7 +201,7 @@ func (s *APIV2Service) GetUserSetting(ctx context.Context, _ *apiv2pb.GetUserSet return nil, status.Errorf(codes.Internal, "failed to get current user: %v", err) } - userSettings, err := s.Store.ListUserSettingsV1(ctx, &store.FindUserSetting{ + userSettings, err := s.Store.ListUserSettings(ctx, &store.FindUserSetting{ UserID: &user.ID, }) if err != nil { @@ -236,7 +236,7 @@ func (s *APIV2Service) UpdateUserSetting(ctx context.Context, request *apiv2pb.U for _, field := range request.UpdateMask.Paths { if field == "locale" { - if _, err := s.Store.UpsertUserSettingV1(ctx, &storepb.UserSetting{ + if _, err := s.Store.UpsertUserSetting(ctx, &storepb.UserSetting{ UserId: user.ID, Key: storepb.UserSettingKey_USER_SETTING_LOCALE, Value: &storepb.UserSetting_Locale{ @@ -246,7 +246,7 @@ func (s *APIV2Service) UpdateUserSetting(ctx context.Context, request *apiv2pb.U return nil, status.Errorf(codes.Internal, "failed to upsert user setting: %v", err) } } else if field == "appearance" { - if _, err := s.Store.UpsertUserSettingV1(ctx, &storepb.UserSetting{ + if _, err := s.Store.UpsertUserSetting(ctx, &storepb.UserSetting{ UserId: user.ID, Key: storepb.UserSettingKey_USER_SETTING_APPEARANCE, Value: &storepb.UserSetting_Appearance{ @@ -256,7 +256,7 @@ func (s *APIV2Service) UpdateUserSetting(ctx context.Context, request *apiv2pb.U return nil, status.Errorf(codes.Internal, "failed to upsert user setting: %v", err) } } else if field == "memo_visibility" { - if _, err := s.Store.UpsertUserSettingV1(ctx, &storepb.UserSetting{ + if _, err := s.Store.UpsertUserSetting(ctx, &storepb.UserSetting{ UserId: user.ID, Key: storepb.UserSettingKey_USER_SETTING_MEMO_VISIBILITY, Value: &storepb.UserSetting_MemoVisibility{ @@ -266,7 +266,7 @@ func (s *APIV2Service) UpdateUserSetting(ctx context.Context, request *apiv2pb.U return nil, status.Errorf(codes.Internal, "failed to upsert user setting: %v", err) } } else if field == "telegram_user_id" { - if _, err := s.Store.UpsertUserSettingV1(ctx, &storepb.UserSetting{ + if _, err := s.Store.UpsertUserSetting(ctx, &storepb.UserSetting{ UserId: user.ID, Key: storepb.UserSettingKey_USER_SETTING_TELEGRAM_USER_ID, Value: &storepb.UserSetting_TelegramUserId{ @@ -431,7 +431,7 @@ func (s *APIV2Service) DeleteUserAccessToken(ctx context.Context, request *apiv2 } updatedUserAccessTokens = append(updatedUserAccessTokens, userAccessToken) } - if _, err := s.Store.UpsertUserSettingV1(ctx, &storepb.UserSetting{ + if _, err := s.Store.UpsertUserSetting(ctx, &storepb.UserSetting{ UserId: user.ID, Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS, Value: &storepb.UserSetting_AccessTokens{ @@ -456,7 +456,7 @@ func (s *APIV2Service) UpsertAccessTokenToStore(ctx context.Context, user *store Description: description, } userAccessTokens = append(userAccessTokens, &userAccessToken) - if _, err := s.Store.UpsertUserSettingV1(ctx, &storepb.UserSetting{ + if _, err := s.Store.UpsertUserSetting(ctx, &storepb.UserSetting{ UserId: user.ID, Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS, Value: &storepb.UserSetting_AccessTokens{ diff --git a/server/integration/telegram.go b/server/integration/telegram.go index 4f036ccf..142df964 100644 --- a/server/integration/telegram.go +++ b/server/integration/telegram.go @@ -39,7 +39,7 @@ func (t *TelegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot, } var creatorID int32 - userSettingList, err := t.store.ListUserSettingsV1(ctx, &store.FindUserSetting{ + userSettingList, err := t.store.ListUserSettings(ctx, &store.FindUserSetting{ Key: storepb.UserSettingKey_USER_SETTING_TELEGRAM_USER_ID, }) if err != nil { diff --git a/store/user_setting.go b/store/user_setting.go index 530f8500..d8e85bf5 100644 --- a/store/user_setting.go +++ b/store/user_setting.go @@ -11,7 +11,7 @@ type FindUserSetting struct { Key storepb.UserSettingKey } -func (s *Store) UpsertUserSettingV1(ctx context.Context, upsert *storepb.UserSetting) (*storepb.UserSetting, error) { +func (s *Store) UpsertUserSetting(ctx context.Context, upsert *storepb.UserSetting) (*storepb.UserSetting, error) { userSettingMessage, err := s.driver.UpsertUserSetting(ctx, upsert) if err != nil { return nil, err @@ -21,7 +21,7 @@ func (s *Store) UpsertUserSettingV1(ctx context.Context, upsert *storepb.UserSet return userSettingMessage, nil } -func (s *Store) ListUserSettingsV1(ctx context.Context, find *FindUserSetting) ([]*storepb.UserSetting, error) { +func (s *Store) ListUserSettings(ctx context.Context, find *FindUserSetting) ([]*storepb.UserSetting, error) { userSettingList, err := s.driver.ListUserSettings(ctx, find) if err != nil { return nil, err @@ -33,14 +33,14 @@ func (s *Store) ListUserSettingsV1(ctx context.Context, find *FindUserSetting) ( return userSettingList, nil } -func (s *Store) GetUserSettingV1(ctx context.Context, find *FindUserSetting) (*storepb.UserSetting, error) { +func (s *Store) GetUserSetting(ctx context.Context, find *FindUserSetting) (*storepb.UserSetting, error) { if find.UserID != nil { if cache, ok := s.userSettingCache.Load(getUserSettingV1CacheKey(*find.UserID, find.Key.String())); ok { return cache.(*storepb.UserSetting), nil } } - list, err := s.ListUserSettingsV1(ctx, find) + list, err := s.ListUserSettings(ctx, find) if err != nil { return nil, err } @@ -56,7 +56,7 @@ func (s *Store) GetUserSettingV1(ctx context.Context, find *FindUserSetting) (*s // GetUserAccessTokens returns the access tokens of the user. func (s *Store) GetUserAccessTokens(ctx context.Context, userID int32) ([]*storepb.AccessTokensUserSetting_AccessToken, error) { - userSetting, err := s.GetUserSettingV1(ctx, &FindUserSetting{ + userSetting, err := s.GetUserSetting(ctx, &FindUserSetting{ UserID: &userID, Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS, }) @@ -85,7 +85,7 @@ func (s *Store) RemoveUserAccessToken(ctx context.Context, userID int32, token s } } - _, err = s.UpsertUserSettingV1(ctx, &storepb.UserSetting{ + _, err = s.UpsertUserSetting(ctx, &storepb.UserSetting{ UserId: userID, Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS, Value: &storepb.UserSetting_AccessTokens{ diff --git a/test/store/user_setting_test.go b/test/store/user_setting_test.go index b06dc3fb..31fd68e7 100644 --- a/test/store/user_setting_test.go +++ b/test/store/user_setting_test.go @@ -15,13 +15,13 @@ func TestUserSettingStore(t *testing.T) { ts := NewTestingStore(ctx, t) user, err := createTestingHostUser(ctx, ts) require.NoError(t, err) - _, err = ts.UpsertUserSettingV1(ctx, &storepb.UserSetting{ + _, err = ts.UpsertUserSetting(ctx, &storepb.UserSetting{ UserId: user.ID, Key: storepb.UserSettingKey_USER_SETTING_LOCALE, Value: &storepb.UserSetting_Locale{Locale: "en"}, }) require.NoError(t, err) - list, err := ts.ListUserSettingsV1(ctx, &store.FindUserSetting{}) + list, err := ts.ListUserSettings(ctx, &store.FindUserSetting{}) require.NoError(t, err) require.Equal(t, 1, len(list)) }