mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: reorder memo resource
This commit is contained in:
@ -49,6 +49,27 @@ func (s *Store) FindMemoResourceList(ctx context.Context, find *api.MemoResource
|
|||||||
return list, nil
|
return list, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Store) FindMemoResource(ctx context.Context, find *api.MemoResourceFind) (*api.MemoResource, error) {
|
||||||
|
tx, err := s.db.BeginTx(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, FormatError(err)
|
||||||
|
}
|
||||||
|
defer tx.Rollback()
|
||||||
|
|
||||||
|
list, err := findMemoResourceList(ctx, tx, find)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(list) == 0 {
|
||||||
|
return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("not found")}
|
||||||
|
}
|
||||||
|
|
||||||
|
memoResourceRaw := list[0]
|
||||||
|
|
||||||
|
return memoResourceRaw.toMemoResource(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Store) UpsertMemoResource(ctx context.Context, upsert *api.MemoResourceUpsert) (*api.MemoResource, error) {
|
func (s *Store) UpsertMemoResource(ctx context.Context, upsert *api.MemoResourceUpsert) (*api.MemoResource, error) {
|
||||||
tx, err := s.db.BeginTx(ctx, nil)
|
tx, err := s.db.BeginTx(ctx, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/usememos/memos/api"
|
"github.com/usememos/memos/api"
|
||||||
@ -52,6 +53,27 @@ func (s *Store) ComposeMemoResourceList(ctx context.Context, memo *api.Memo) err
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, resource := range resourceList {
|
||||||
|
memoResource, err := s.FindMemoResource(ctx, &api.MemoResourceFind{
|
||||||
|
MemoID: &memo.ID,
|
||||||
|
ResourceID: &resource.ID,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
resource.CreatedTs = memoResource.CreatedTs
|
||||||
|
resource.UpdatedTs = memoResource.UpdatedTs
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(resourceList, func(i, j int) bool {
|
||||||
|
if resourceList[i].CreatedTs != resourceList[j].CreatedTs {
|
||||||
|
return resourceList[i].CreatedTs < resourceList[j].CreatedTs
|
||||||
|
}
|
||||||
|
|
||||||
|
return resourceList[i].ID < resourceList[j].ID
|
||||||
|
})
|
||||||
|
|
||||||
memo.ResourceList = resourceList
|
memo.ResourceList = resourceList
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Reference in New Issue
Block a user