feat: update memo sort option setting (#326)

feat: add memo display ts
This commit is contained in:
boojack
2022-10-21 19:57:57 +08:00
committed by GitHub
parent 0b34b142c8
commit b68d6e2693
12 changed files with 58 additions and 39 deletions

View File

@@ -3,6 +3,7 @@ package store
import (
"context"
"database/sql"
"encoding/json"
"fmt"
"strings"
@@ -41,6 +42,7 @@ func (raw *memoRaw) toMemo() *api.Memo {
// Domain specific fields
Content: raw.Content,
Visibility: raw.Visibility,
DisplayTs: raw.CreatedTs,
}
}
@@ -62,6 +64,25 @@ func (s *Store) ComposeMemo(ctx context.Context, memo *api.Memo) (*api.Memo, err
return nil, err
}
memoSortOptionKey := api.UserSettingMemoSortOptionKey
memoSortOption, err := s.FindUserSetting(ctx, &api.UserSettingFind{
UserID: memo.CreatorID,
Key: &memoSortOptionKey,
})
if err != nil {
return nil, err
}
memoSortOptionValue := "created_ts"
if memoSortOption != nil {
err = json.Unmarshal([]byte(memoSortOption.Value), &memoSortOptionValue)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal user setting memo sort option value")
}
}
if memoSortOptionValue == "updated_ts" {
memo.DisplayTs = memo.UpdatedTs
}
return memo, nil
}
@@ -244,6 +265,9 @@ func patchMemoRaw(ctx context.Context, tx *sql.Tx, patch *api.MemoPatch) (*memoR
if v := patch.CreatedTs; v != nil {
set, args = append(set, "created_ts = ?"), append(args, *v)
}
if v := patch.UpdatedTs; v != nil {
set, args = append(set, "updated_ts = ?"), append(args, *v)
}
if v := patch.RowStatus; v != nil {
set, args = append(set, "row_status = ?"), append(args, *v)
}