Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
fix memory
Browse files Browse the repository at this point in the history
  • Loading branch information
rot1024 committed Mar 15, 2022
1 parent bc380be commit 258aad9
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion internal/infrastructure/memory/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package memory

import (
"context"
"sort"
"strings"
"sync"

"github.com/reearth/reearth-backend/internal/usecase"
Expand Down Expand Up @@ -69,11 +71,27 @@ func (r *Asset) FindByTeam(ctx context.Context, id id.TeamID, filter repo.AssetF

result := []*asset.Asset{}
for _, d := range r.data {
if d.Team() == id {
if d.Team() == id && (filter.Keyword == nil || strings.Contains(d.Name(), *filter.Keyword)) {
result = append(result, d)
}
}

if filter.Sort != nil {
s := *filter.Sort
sort.SliceStable(result, func(i, j int) bool {
if s == asset.SortTypeID {
return result[i].ID().ID().Compare(result[j].ID().ID()) < 0
}
if s == asset.SortTypeSize {
return result[i].Size() < result[j].Size()
}
if s == asset.SortTypeName {
return strings.Compare(result[i].Name(), result[j].Name()) < 0
}
return false
})
}

var startCursor, endCursor *usecase.Cursor
if len(result) > 0 {
_startCursor := usecase.Cursor(result[0].ID().String())
Expand Down

0 comments on commit 258aad9

Please sign in to comment.