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

feat: asset filtering #81

Merged
merged 31 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
9885686
wip: asset filtering
KaWaite Nov 22, 2021
8d510b1
Merge remote-tracking branch 'origin/main' into feat/asset-filtering
KaWaite Nov 22, 2021
dbb176f
asset filtering
KaWaite Nov 25, 2021
a776b49
refactoring
KaWaite Nov 26, 2021
e136f57
fix naming
KaWaite Nov 26, 2021
896fe92
Merge remote-tracking branch 'origin/main' into feat/asset-filtering
KaWaite Nov 26, 2021
6ee6b99
Merge remote-tracking branch 'origin/main' into feat/asset-filtering
KaWaite Dec 20, 2021
3adc203
Merge remote-tracking branch 'origin/main' into feat/asset-filtering
KaWaite Jan 13, 2022
a6a58d2
Merge remote-tracking branch 'origin/main' into feat/asset-filtering
KaWaite Jan 14, 2022
5f7b138
Update branch from main
yk-eukarya Jan 20, 2022
b9bc7f6
add ability to search by key word
yk-eukarya Jan 21, 2022
f0d4780
update from main
yk-eukarya Jan 21, 2022
9a3750a
make the pagination cursor optional
yk-eukarya Jan 24, 2022
6823d3c
Merge remote-tracking branch 'oss/main' into feat/asset-filtering
yk-eukarya Jan 27, 2022
e37942c
Merge remote-tracking branch 'oss/main' into feat/asset-filtering
yk-eukarya Feb 3, 2022
e47ce12
code restructuring
yk-eukarya Feb 7, 2022
6311e9c
fix sort default value
yk-eukarya Feb 24, 2022
be55570
fix sort default value
yk-eukarya Feb 25, 2022
afb4535
fix sort
yk-eukarya Feb 25, 2022
ffb3b05
pagination refactoring
yk-eukarya Mar 3, 2022
6b02bf7
Merge remote-tracking branch 'oss/main' into feat/asset-filtering
yk-eukarya Mar 3, 2022
d8c5c3c
support sort with pagination
yk-eukarya Mar 3, 2022
c732419
- remove unused code
yk-eukarya Mar 7, 2022
7b8176b
- refactor pagination code
yk-eukarya Mar 9, 2022
d3bf277
- fix paginationFilter return type
yk-eukarya Mar 10, 2022
f9abc62
- code refactoring
yk-eukarya Mar 10, 2022
b60c5fa
- fix pagination when it contains reverse order
yk-eukarya Mar 14, 2022
5dc60e0
Merge remote-tracking branch 'oss/main' into feat/asset-filtering
yk-eukarya Mar 14, 2022
bc380be
Merge branch 'main' into feat/asset-filtering
rot1024 Mar 15, 2022
258aad9
fix memory
rot1024 Mar 15, 2022
58df58e
Merge remote-tracking branch 'origin/main' into feat/asset-filtering
KaWaite Mar 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 106 additions & 32 deletions internal/adapter/gql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions internal/adapter/gql/gqlmodel/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,15 @@ func FromListOperation(op ListOperation) interfaces.ListOperation {
}
return interfaces.ListOperation("")
}

func ToPagination(pagination *Pagination) *usecase.Pagination {
if pagination == nil {
return nil
}
return &usecase.Pagination{
Before: pagination.Before,
After: pagination.After,
First: pagination.First,
Last: pagination.Last,
}
}
15 changes: 15 additions & 0 deletions internal/adapter/gql/gqlmodel/convert_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,18 @@ func ToAsset(a *asset.Asset) *Asset {
ContentType: a.ContentType(),
}
}

func AssetSortTypeFrom(ast *AssetSortType) *asset.SortType {
if ast == nil {
return nil
}
switch *ast {
case AssetSortTypeDate:
return &asset.SortTypeID
case AssetSortTypeName:
return &asset.SortTypeName
case AssetSortTypeSize:
return &asset.SortTypeSize
}
return &asset.SortTypeID
}
50 changes: 50 additions & 0 deletions internal/adapter/gql/gqlmodel/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions internal/adapter/gql/loader_asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/reearth/reearth-backend/internal/adapter/gql/gqlmodel"
"github.com/reearth/reearth-backend/internal/usecase"
"github.com/reearth/reearth-backend/internal/usecase/interfaces"
"github.com/reearth/reearth-backend/pkg/asset"
"github.com/reearth/reearth-backend/pkg/id"
)

Expand All @@ -32,9 +33,10 @@ func (c *AssetLoader) Fetch(ctx context.Context, ids []id.AssetID) ([]*gqlmodel.
return assets, nil
}

func (c *AssetLoader) FindByTeam(ctx context.Context, teamID id.ID, first *int, last *int, before *usecase.Cursor, after *usecase.Cursor) (*gqlmodel.AssetConnection, error) {
p := usecase.NewPagination(first, last, before, after)
assets, pi, err := c.usecase.FindByTeam(ctx, id.TeamID(teamID), p, getOperator(ctx))
func (c *AssetLoader) FindByTeam(ctx context.Context, teamID id.ID, keyword *string, sort *asset.SortType, pagination *gqlmodel.Pagination) (*gqlmodel.AssetConnection, error) {
p := gqlmodel.ToPagination(pagination)

assets, pi, err := c.usecase.FindByTeam(ctx, id.TeamID(teamID), keyword, sort, p, getOperator(ctx))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/adapter/gql/resolver_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func (r *Resolver) Query() QueryResolver {

type queryResolver struct{ *Resolver }

func (r *queryResolver) Assets(ctx context.Context, teamID id.ID, first *int, last *int, after *usecase.Cursor, before *usecase.Cursor) (*gqlmodel.AssetConnection, error) {
return loaders(ctx).Asset.FindByTeam(ctx, teamID, first, last, before, after)
func (r *queryResolver) Assets(ctx context.Context, teamID id.ID, keyword *string, sortType *gqlmodel.AssetSortType, pagination *gqlmodel.Pagination) (*gqlmodel.AssetConnection, error) {
return loaders(ctx).Asset.FindByTeam(ctx, teamID, keyword, gqlmodel.AssetSortTypeFrom(sortType), pagination)
}

func (r *queryResolver) Me(ctx context.Context) (*gqlmodel.User, error) {
Expand Down
7 changes: 6 additions & 1 deletion internal/adapter/gql/resolver_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ func (r *Resolver) TeamMember() TeamMemberResolver {
type teamResolver struct{ *Resolver }

func (r *teamResolver) Assets(ctx context.Context, obj *gqlmodel.Team, first *int, last *int, after *usecase.Cursor, before *usecase.Cursor) (*gqlmodel.AssetConnection, error) {
return loaders(ctx).Asset.FindByTeam(ctx, obj.ID, first, last, before, after)
return loaders(ctx).Asset.FindByTeam(ctx, obj.ID, nil, nil, &gqlmodel.Pagination{
First: first,
Last: last,
After: after,
Before: before,
})
}

func (r *teamResolver) Projects(ctx context.Context, obj *gqlmodel.Team, includeArchived *bool, first *int, last *int, after *usecase.Cursor, before *usecase.Cursor) (*gqlmodel.ProjectConnection, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/infrastructure/memory/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (r *Asset) Remove(ctx context.Context, id id.AssetID) error {
return nil
}

func (r *Asset) FindByTeam(ctx context.Context, id id.TeamID, pagination *usecase.Pagination) ([]*asset.Asset, *usecase.PageInfo, error) {
func (r *Asset) FindByTeam(ctx context.Context, id id.TeamID, filter repo.AssetFilter) ([]*asset.Asset, *usecase.PageInfo, error) {
r.lock.Lock()
defer r.lock.Unlock()

Expand Down
Loading