Skip to content

Commit

Permalink
implement asset list ids
Browse files Browse the repository at this point in the history
  • Loading branch information
nourbalaha committed Oct 23, 2024
1 parent a306552 commit c4af359
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/internal/adapter/publicapi/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (c *Controller) GetAssets(ctx context.Context, pKey string, p ListParam) (L
return ListResult[Asset]{}, err
}

fileMap, err := c.usecases.Asset.FindFilesByIDs(ctx, util.Map(al, func(a *asset.Asset) id.AssetID { return a.ID() }), nil)
fileMap, err := c.usecases.Asset.FindFilesByIDs(ctx, al.IDs(), nil)
if err != nil {
return ListResult[Asset]{}, err
}
Expand Down
8 changes: 8 additions & 0 deletions server/pkg/asset/list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package asset

import (
"github.com/reearth/reearth-cms/server/pkg/id"
"github.com/reearth/reearthx/util"
"github.com/samber/lo"
"golang.org/x/exp/slices"
Expand All @@ -27,3 +28,10 @@ func (l List) Map() Map {
return a.ID(), a
})
}

func (l List) IDs() (ids id.AssetIDList) {
for _, a := range l {
ids = ids.Add(a.ID())
}
return
}
10 changes: 10 additions & 0 deletions server/pkg/asset/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package asset
import (
"testing"

"github.com/reearth/reearth-cms/server/pkg/id"
"github.com/reearth/reearthx/account/accountdomain"
"github.com/stretchr/testify/assert"
)
Expand Down Expand Up @@ -51,3 +52,12 @@ func TestList_Map(t *testing.T) {
}, List{a, nil}.Map())
assert.Equal(t, Map{}, List(nil).Map())
}

func TestList_IDs(t *testing.T) {
pid := NewProjectID()
uid := accountdomain.NewUserID()
a1 := New().NewID().Project(pid).CreatedByUser(uid).Size(1000).Thread(NewThreadID()).NewUUID().MustBuild()
a2 := New().NewID().Project(pid).CreatedByUser(uid).Size(1000).Thread(NewThreadID()).NewUUID().MustBuild()
al := List{a1, a2}
assert.Equal(t, al.IDs(), id.AssetIDList{a1.ID(), a2.ID()})
}

0 comments on commit c4af359

Please sign in to comment.