chore: update user setting names

This commit is contained in:
Steven 2023-12-16 12:18:53 +08:00
parent e8ca2ea5a0
commit 1c7fb77e05
6 changed files with 19 additions and 19 deletions

View file

@ -359,7 +359,7 @@ func (s *APIV1Service) UpsertAccessTokenToStore(ctx context.Context, user *store
Description: "Account sign in", Description: "Account sign in",
} }
userAccessTokens = append(userAccessTokens, &userAccessToken) userAccessTokens = append(userAccessTokens, &userAccessToken)
if _, err := s.Store.UpsertUserSettingV1(ctx, &storepb.UserSetting{ if _, err := s.Store.UpsertUserSetting(ctx, &storepb.UserSetting{
UserId: user.ID, UserId: user.ID,
Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS, Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS,
Value: &storepb.UserSetting_AccessTokens{ Value: &storepb.UserSetting_AccessTokens{

View file

@ -265,7 +265,7 @@ func (s *APIV1Service) CreateMemo(c echo.Context) error {
} }
if createMemoRequest.Visibility == "" { if createMemoRequest.Visibility == "" {
userMemoVisibilitySetting, err := s.Store.GetUserSettingV1(ctx, &store.FindUserSetting{ userMemoVisibilitySetting, err := s.Store.GetUserSetting(ctx, &store.FindUserSetting{
UserID: &userID, UserID: &userID,
Key: storepb.UserSettingKey_USER_SETTING_MEMO_VISIBILITY, 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. // Send notification to telegram if memo is not private.
if memoResponse.Visibility != Private { if memoResponse.Visibility != Private {
// fetch all telegram UserID // 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 { if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to ListUserSettings").SetInternal(err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to ListUserSettings").SetInternal(err)
} }

View file

@ -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) 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, UserID: &user.ID,
}) })
if err != nil { if err != nil {
@ -236,7 +236,7 @@ func (s *APIV2Service) UpdateUserSetting(ctx context.Context, request *apiv2pb.U
for _, field := range request.UpdateMask.Paths { for _, field := range request.UpdateMask.Paths {
if field == "locale" { if field == "locale" {
if _, err := s.Store.UpsertUserSettingV1(ctx, &storepb.UserSetting{ if _, err := s.Store.UpsertUserSetting(ctx, &storepb.UserSetting{
UserId: user.ID, UserId: user.ID,
Key: storepb.UserSettingKey_USER_SETTING_LOCALE, Key: storepb.UserSettingKey_USER_SETTING_LOCALE,
Value: &storepb.UserSetting_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) return nil, status.Errorf(codes.Internal, "failed to upsert user setting: %v", err)
} }
} else if field == "appearance" { } else if field == "appearance" {
if _, err := s.Store.UpsertUserSettingV1(ctx, &storepb.UserSetting{ if _, err := s.Store.UpsertUserSetting(ctx, &storepb.UserSetting{
UserId: user.ID, UserId: user.ID,
Key: storepb.UserSettingKey_USER_SETTING_APPEARANCE, Key: storepb.UserSettingKey_USER_SETTING_APPEARANCE,
Value: &storepb.UserSetting_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) return nil, status.Errorf(codes.Internal, "failed to upsert user setting: %v", err)
} }
} else if field == "memo_visibility" { } else if field == "memo_visibility" {
if _, err := s.Store.UpsertUserSettingV1(ctx, &storepb.UserSetting{ if _, err := s.Store.UpsertUserSetting(ctx, &storepb.UserSetting{
UserId: user.ID, UserId: user.ID,
Key: storepb.UserSettingKey_USER_SETTING_MEMO_VISIBILITY, Key: storepb.UserSettingKey_USER_SETTING_MEMO_VISIBILITY,
Value: &storepb.UserSetting_MemoVisibility{ 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) return nil, status.Errorf(codes.Internal, "failed to upsert user setting: %v", err)
} }
} else if field == "telegram_user_id" { } 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, UserId: user.ID,
Key: storepb.UserSettingKey_USER_SETTING_TELEGRAM_USER_ID, Key: storepb.UserSettingKey_USER_SETTING_TELEGRAM_USER_ID,
Value: &storepb.UserSetting_TelegramUserId{ Value: &storepb.UserSetting_TelegramUserId{
@ -431,7 +431,7 @@ func (s *APIV2Service) DeleteUserAccessToken(ctx context.Context, request *apiv2
} }
updatedUserAccessTokens = append(updatedUserAccessTokens, userAccessToken) updatedUserAccessTokens = append(updatedUserAccessTokens, userAccessToken)
} }
if _, err := s.Store.UpsertUserSettingV1(ctx, &storepb.UserSetting{ if _, err := s.Store.UpsertUserSetting(ctx, &storepb.UserSetting{
UserId: user.ID, UserId: user.ID,
Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS, Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS,
Value: &storepb.UserSetting_AccessTokens{ Value: &storepb.UserSetting_AccessTokens{
@ -456,7 +456,7 @@ func (s *APIV2Service) UpsertAccessTokenToStore(ctx context.Context, user *store
Description: description, Description: description,
} }
userAccessTokens = append(userAccessTokens, &userAccessToken) userAccessTokens = append(userAccessTokens, &userAccessToken)
if _, err := s.Store.UpsertUserSettingV1(ctx, &storepb.UserSetting{ if _, err := s.Store.UpsertUserSetting(ctx, &storepb.UserSetting{
UserId: user.ID, UserId: user.ID,
Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS, Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS,
Value: &storepb.UserSetting_AccessTokens{ Value: &storepb.UserSetting_AccessTokens{

View file

@ -39,7 +39,7 @@ func (t *TelegramHandler) MessageHandle(ctx context.Context, bot *telegram.Bot,
} }
var creatorID int32 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, Key: storepb.UserSettingKey_USER_SETTING_TELEGRAM_USER_ID,
}) })
if err != nil { if err != nil {

View file

@ -11,7 +11,7 @@ type FindUserSetting struct {
Key storepb.UserSettingKey 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) userSettingMessage, err := s.driver.UpsertUserSetting(ctx, upsert)
if err != nil { if err != nil {
return nil, err return nil, err
@ -21,7 +21,7 @@ func (s *Store) UpsertUserSettingV1(ctx context.Context, upsert *storepb.UserSet
return userSettingMessage, nil 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) userSettingList, err := s.driver.ListUserSettings(ctx, find)
if err != nil { if err != nil {
return nil, err return nil, err
@ -33,14 +33,14 @@ func (s *Store) ListUserSettingsV1(ctx context.Context, find *FindUserSetting) (
return userSettingList, nil 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 find.UserID != nil {
if cache, ok := s.userSettingCache.Load(getUserSettingV1CacheKey(*find.UserID, find.Key.String())); ok { if cache, ok := s.userSettingCache.Load(getUserSettingV1CacheKey(*find.UserID, find.Key.String())); ok {
return cache.(*storepb.UserSetting), nil return cache.(*storepb.UserSetting), nil
} }
} }
list, err := s.ListUserSettingsV1(ctx, find) list, err := s.ListUserSettings(ctx, find)
if err != nil { if err != nil {
return nil, err 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. // GetUserAccessTokens returns the access tokens of the user.
func (s *Store) GetUserAccessTokens(ctx context.Context, userID int32) ([]*storepb.AccessTokensUserSetting_AccessToken, error) { 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, UserID: &userID,
Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS, 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, UserId: userID,
Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS, Key: storepb.UserSettingKey_USER_SETTING_ACCESS_TOKENS,
Value: &storepb.UserSetting_AccessTokens{ Value: &storepb.UserSetting_AccessTokens{

View file

@ -15,13 +15,13 @@ func TestUserSettingStore(t *testing.T) {
ts := NewTestingStore(ctx, t) ts := NewTestingStore(ctx, t)
user, err := createTestingHostUser(ctx, ts) user, err := createTestingHostUser(ctx, ts)
require.NoError(t, err) require.NoError(t, err)
_, err = ts.UpsertUserSettingV1(ctx, &storepb.UserSetting{ _, err = ts.UpsertUserSetting(ctx, &storepb.UserSetting{
UserId: user.ID, UserId: user.ID,
Key: storepb.UserSettingKey_USER_SETTING_LOCALE, Key: storepb.UserSettingKey_USER_SETTING_LOCALE,
Value: &storepb.UserSetting_Locale{Locale: "en"}, Value: &storepb.UserSetting_Locale{Locale: "en"},
}) })
require.NoError(t, err) require.NoError(t, err)
list, err := ts.ListUserSettingsV1(ctx, &store.FindUserSetting{}) list, err := ts.ListUserSettings(ctx, &store.FindUserSetting{})
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, 1, len(list)) require.Equal(t, 1, len(list))
} }