diff --git a/core/api/handler/list.go b/core/api/handler/list.go index 50b811df8..fdb4ffbbc 100644 --- a/core/api/handler/list.go +++ b/core/api/handler/list.go @@ -9,9 +9,7 @@ import ( "github.com/anyproto/anytype-heart/core/api/pagination" "github.com/anyproto/anytype-heart/core/api/service" "github.com/anyproto/anytype-heart/core/api/util" - "github.com/anyproto/anytype-heart/pkg/lib/bundle" "github.com/anyproto/anytype-heart/pkg/lib/pb/model" - "github.com/anyproto/anytype-heart/util/pbtypes" ) // GetListViewsHandler @@ -82,15 +80,8 @@ func GetObjectsInListHandler(s *service.Service) gin.HandlerFunc { offset := c.GetInt("offset") limit := c.GetInt("limit") - nameParam := c.Query("name") - var filters []service.Filter - if nameParam != "" { - filters = append(filters, service.Filter{ - RelationKey: bundle.RelationKeyName.String(), - Condition: model.BlockContentDataviewFilter_Like, - Value: pbtypes.String(nameParam), - }) - } + filtersAny, _ := c.Get("filters") + filters := filtersAny.([]*model.BlockContentDataviewFilter) objects, total, hasMore, err := s.GetObjectsInList(c, spaceId, listId, viewId, filters, offset, limit) code := util.MapErrorCode(err, diff --git a/core/api/handler/member.go b/core/api/handler/member.go index b1ee4d5a0..78c819685 100644 --- a/core/api/handler/member.go +++ b/core/api/handler/member.go @@ -9,9 +9,7 @@ import ( "github.com/anyproto/anytype-heart/core/api/pagination" "github.com/anyproto/anytype-heart/core/api/service" "github.com/anyproto/anytype-heart/core/api/util" - "github.com/anyproto/anytype-heart/pkg/lib/bundle" "github.com/anyproto/anytype-heart/pkg/lib/pb/model" - "github.com/anyproto/anytype-heart/util/pbtypes" ) // ListMembersHandler retrieves a list of members in a space @@ -36,15 +34,8 @@ func ListMembersHandler(s *service.Service) gin.HandlerFunc { offset := c.GetInt("offset") limit := c.GetInt("limit") - nameParam := c.Query("name") - var filters []service.Filter - if nameParam != "" { - filters = append(filters, service.Filter{ - RelationKey: bundle.RelationKeyName.String(), - Condition: model.BlockContentDataviewFilter_Like, - Value: pbtypes.String(nameParam), - }) - } + filtersAny, _ := c.Get("filters") + filters := filtersAny.([]*model.BlockContentDataviewFilter) members, total, hasMore, err := s.ListMembers(c.Request.Context(), spaceId, filters, offset, limit) code := util.MapErrorCode(err, diff --git a/core/api/handler/object.go b/core/api/handler/object.go index d7466b41d..bf92de1e2 100644 --- a/core/api/handler/object.go +++ b/core/api/handler/object.go @@ -9,9 +9,7 @@ import ( "github.com/anyproto/anytype-heart/core/api/pagination" "github.com/anyproto/anytype-heart/core/api/service" "github.com/anyproto/anytype-heart/core/api/util" - "github.com/anyproto/anytype-heart/pkg/lib/bundle" "github.com/anyproto/anytype-heart/pkg/lib/pb/model" - "github.com/anyproto/anytype-heart/util/pbtypes" ) // ListObjectsHandler retrieves a list of objects in a space @@ -36,15 +34,8 @@ func ListObjectsHandler(s *service.Service) gin.HandlerFunc { offset := c.GetInt("offset") limit := c.GetInt("limit") - nameParam := c.Query("name") - var filters []service.Filter - if nameParam != "" { - filters = append(filters, service.Filter{ - RelationKey: bundle.RelationKeyName.String(), - Condition: model.BlockContentDataviewFilter_Like, - Value: pbtypes.String(nameParam), - }) - } + filtersAny, _ := c.Get("filters") + filters := filtersAny.([]*model.BlockContentDataviewFilter) objects, total, hasMore, err := s.ListObjects(c.Request.Context(), spaceId, filters, offset, limit) code := util.MapErrorCode(err, diff --git a/core/api/handler/property.go b/core/api/handler/property.go index f3f6beef2..038edd38c 100644 --- a/core/api/handler/property.go +++ b/core/api/handler/property.go @@ -9,9 +9,7 @@ import ( "github.com/anyproto/anytype-heart/core/api/pagination" "github.com/anyproto/anytype-heart/core/api/service" "github.com/anyproto/anytype-heart/core/api/util" - "github.com/anyproto/anytype-heart/pkg/lib/bundle" "github.com/anyproto/anytype-heart/pkg/lib/pb/model" - "github.com/anyproto/anytype-heart/util/pbtypes" ) // ListPropertiesHandler retrieves a list of properties in a space @@ -36,15 +34,8 @@ func ListPropertiesHandler(s *service.Service) gin.HandlerFunc { offset := c.GetInt("offset") limit := c.GetInt("limit") - nameParam := c.Query("name") - var filters []service.Filter - if nameParam != "" { - filters = append(filters, service.Filter{ - RelationKey: bundle.RelationKeyName.String(), - Condition: model.BlockContentDataviewFilter_Like, - Value: pbtypes.String(nameParam), - }) - } + filtersAny, _ := c.Get("filters") + filters := filtersAny.([]*model.BlockContentDataviewFilter) properties, total, hasMore, err := s.ListProperties(c.Request.Context(), spaceId, filters, offset, limit) code := util.MapErrorCode(err, diff --git a/core/api/handler/space.go b/core/api/handler/space.go index 5b50a14ce..7a5202ec4 100644 --- a/core/api/handler/space.go +++ b/core/api/handler/space.go @@ -9,9 +9,7 @@ import ( "github.com/anyproto/anytype-heart/core/api/pagination" "github.com/anyproto/anytype-heart/core/api/service" "github.com/anyproto/anytype-heart/core/api/util" - "github.com/anyproto/anytype-heart/pkg/lib/bundle" "github.com/anyproto/anytype-heart/pkg/lib/pb/model" - "github.com/anyproto/anytype-heart/util/pbtypes" ) // ListSpacesHandler retrieves a list of spaces @@ -34,15 +32,8 @@ func ListSpacesHandler(s *service.Service) gin.HandlerFunc { offset := c.GetInt("offset") limit := c.GetInt("limit") - nameParam := c.Query("name") - var filters []service.Filter - if nameParam != "" { - filters = append(filters, service.Filter{ - RelationKey: bundle.RelationKeyName.String(), - Condition: model.BlockContentDataviewFilter_Like, - Value: pbtypes.String(nameParam), - }) - } + filtersAny, _ := c.Get("filters") + filters := filtersAny.([]*model.BlockContentDataviewFilter) spaces, total, hasMore, err := s.ListSpaces(c.Request.Context(), filters, offset, limit) code := util.MapErrorCode(err, diff --git a/core/api/handler/tag.go b/core/api/handler/tag.go index 538c74333..0c0d83a41 100644 --- a/core/api/handler/tag.go +++ b/core/api/handler/tag.go @@ -9,9 +9,7 @@ import ( "github.com/anyproto/anytype-heart/core/api/pagination" "github.com/anyproto/anytype-heart/core/api/service" "github.com/anyproto/anytype-heart/core/api/util" - "github.com/anyproto/anytype-heart/pkg/lib/bundle" "github.com/anyproto/anytype-heart/pkg/lib/pb/model" - "github.com/anyproto/anytype-heart/util/pbtypes" ) // ListTagsHandler lists all tags for a given property id in a space @@ -37,15 +35,8 @@ func ListTagsHandler(s *service.Service) gin.HandlerFunc { offset := c.GetInt("offset") limit := c.GetInt("limit") - nameParam := c.Query("name") - var filters []service.Filter - if nameParam != "" { - filters = append(filters, service.Filter{ - RelationKey: bundle.RelationKeyName.String(), - Condition: model.BlockContentDataviewFilter_Like, - Value: pbtypes.String(nameParam), - }) - } + filtersAny, _ := c.Get("filters") + filters := filtersAny.([]*model.BlockContentDataviewFilter) tags, total, hasMore, err := s.ListTags(c.Request.Context(), spaceId, propertyId, filters, offset, limit) code := util.MapErrorCode(err, diff --git a/core/api/handler/template.go b/core/api/handler/template.go index a4d85f77c..df222068b 100644 --- a/core/api/handler/template.go +++ b/core/api/handler/template.go @@ -9,9 +9,7 @@ import ( "github.com/anyproto/anytype-heart/core/api/pagination" "github.com/anyproto/anytype-heart/core/api/service" "github.com/anyproto/anytype-heart/core/api/util" - "github.com/anyproto/anytype-heart/pkg/lib/bundle" "github.com/anyproto/anytype-heart/pkg/lib/pb/model" - "github.com/anyproto/anytype-heart/util/pbtypes" ) // ListTemplatesHandler retrieves a list of templates for a type in a space @@ -38,15 +36,8 @@ func ListTemplatesHandler(s *service.Service) gin.HandlerFunc { offset := c.GetInt("offset") limit := c.GetInt("limit") - nameParam := c.Query("name") - var filters []service.Filter - if nameParam != "" { - filters = append(filters, service.Filter{ - RelationKey: bundle.RelationKeyName.String(), - Condition: model.BlockContentDataviewFilter_Like, - Value: pbtypes.String(nameParam), - }) - } + filtersAny, _ := c.Get("filters") + filters := filtersAny.([]*model.BlockContentDataviewFilter) templates, total, hasMore, err := s.ListTemplates(c.Request.Context(), spaceId, typeId, filters, offset, limit) code := util.MapErrorCode(err, diff --git a/core/api/handler/type.go b/core/api/handler/type.go index e10a5ffc0..e562863bc 100644 --- a/core/api/handler/type.go +++ b/core/api/handler/type.go @@ -9,9 +9,7 @@ import ( "github.com/anyproto/anytype-heart/core/api/pagination" "github.com/anyproto/anytype-heart/core/api/service" "github.com/anyproto/anytype-heart/core/api/util" - "github.com/anyproto/anytype-heart/pkg/lib/bundle" "github.com/anyproto/anytype-heart/pkg/lib/pb/model" - "github.com/anyproto/anytype-heart/util/pbtypes" ) // ListTypesHandler retrieves a list of types in a space @@ -36,15 +34,8 @@ func ListTypesHandler(s *service.Service) gin.HandlerFunc { offset := c.GetInt("offset") limit := c.GetInt("limit") - nameParam := c.Query("name") - var filters []service.Filter - if nameParam != "" { - filters = append(filters, service.Filter{ - RelationKey: bundle.RelationKeyName.String(), - Condition: model.BlockContentDataviewFilter_Like, - Value: pbtypes.String(nameParam), - }) - } + filtersAny, _ := c.Get("filters") + filters := filtersAny.([]*model.BlockContentDataviewFilter) types, total, hasMore, err := s.ListTypes(c.Request.Context(), spaceId, filters, offset, limit) code := util.MapErrorCode(err, diff --git a/core/api/service/list.go b/core/api/service/list.go index 6e6c0e321..c6c5869da 100644 --- a/core/api/service/list.go +++ b/core/api/service/list.go @@ -95,7 +95,7 @@ func (s *Service) GetListViews(ctx context.Context, spaceId string, listId strin } // GetObjectsInList retrieves objects in a list -func (s *Service) GetObjectsInList(ctx context.Context, spaceId string, listId string, viewId string, extraFilters []Filter, offset, limit int) ([]apimodel.Object, int, bool, error) { +func (s *Service) GetObjectsInList(ctx context.Context, spaceId string, listId string, viewId string, additionalFilters []*model.BlockContentDataviewFilter, offset, limit int) ([]apimodel.Object, int, bool, error) { resp := s.mw.ObjectShow(ctx, &pb.RpcObjectShowRequest{ SpaceId: spaceId, ObjectId: listId, @@ -141,13 +141,7 @@ func (s *Service) GetObjectsInList(ctx context.Context, spaceId string, listId s return nil, 0, false, ErrFailedGetListDataview } - for _, f := range extraFilters { - filters = append(filters, &model.BlockContentDataviewFilter{ - RelationKey: f.RelationKey, - Condition: f.Condition, - Value: f.Value, - }) - } + filters = append(filters, additionalFilters...) var typeDetail *types.Struct for _, detail := range resp.ObjectView.Details { diff --git a/core/api/service/member.go b/core/api/service/member.go index e288a828d..2b0c938aa 100644 --- a/core/api/service/member.go +++ b/core/api/service/member.go @@ -16,8 +16,8 @@ import ( ) // ListMembers returns a paginated list of members in the space with the given ID. -func (s *Service) ListMembers(ctx context.Context, spaceId string, filters []Filter, offset int, limit int) (members []apimodel.Member, total int, hasMore bool, err error) { - baseFilters := []*model.BlockContentDataviewFilter{ +func (s *Service) ListMembers(ctx context.Context, spaceId string, additionalFilters []*model.BlockContentDataviewFilter, offset int, limit int) (members []apimodel.Member, total int, hasMore bool, err error) { + filters := append([]*model.BlockContentDataviewFilter{ { RelationKey: bundle.RelationKeyResolvedLayout.String(), Condition: model.BlockContentDataviewFilter_Equal, @@ -28,17 +28,11 @@ func (s *Service) ListMembers(ctx context.Context, spaceId string, filters []Fil Condition: model.BlockContentDataviewFilter_Equal, Value: pbtypes.Int64(int64(model.ParticipantStatus_Active)), }, - } - for _, f := range filters { - baseFilters = append(baseFilters, &model.BlockContentDataviewFilter{ - RelationKey: f.RelationKey, - Condition: f.Condition, - Value: f.Value, - }) - } + }, additionalFilters...) + activeResp := s.mw.ObjectSearch(ctx, &pb.RpcObjectSearchRequest{ SpaceId: spaceId, - Filters: baseFilters, + Filters: filters, Sorts: []*model.BlockContentDataviewSort{ { RelationKey: bundle.RelationKeyName.String(), diff --git a/core/api/service/object.go b/core/api/service/object.go index e3d37d3c7..ee71eb616 100644 --- a/core/api/service/object.go +++ b/core/api/service/object.go @@ -33,8 +33,8 @@ var ( ) // ListObjects retrieves a paginated list of objects in a specific space. -func (s *Service) ListObjects(ctx context.Context, spaceId string, filters []Filter, offset int, limit int) (objects []apimodel.Object, total int, hasMore bool, err error) { - baseFilters := []*model.BlockContentDataviewFilter{ +func (s *Service) ListObjects(ctx context.Context, spaceId string, additionalFilters []*model.BlockContentDataviewFilter, offset int, limit int) (objects []apimodel.Object, total int, hasMore bool, err error) { + filters := append([]*model.BlockContentDataviewFilter{ { RelationKey: bundle.RelationKeyResolvedLayout.String(), Condition: model.BlockContentDataviewFilter_In, @@ -50,17 +50,11 @@ func (s *Service) ListObjects(ctx context.Context, spaceId string, filters []Fil Condition: model.BlockContentDataviewFilter_NotEqual, Value: pbtypes.Bool(true), }, - } - for _, f := range filters { - baseFilters = append(baseFilters, &model.BlockContentDataviewFilter{ - RelationKey: f.RelationKey, - Condition: f.Condition, - Value: f.Value, - }) - } + }, additionalFilters...) + resp := s.mw.ObjectSearch(ctx, &pb.RpcObjectSearchRequest{ SpaceId: spaceId, - Filters: baseFilters, + Filters: filters, Sorts: []*model.BlockContentDataviewSort{{ RelationKey: bundle.RelationKeyLastModifiedDate.String(), Type: model.BlockContentDataviewSort_Desc, diff --git a/core/api/service/property.go b/core/api/service/property.go index f06fba75f..6c6cb1765 100644 --- a/core/api/service/property.go +++ b/core/api/service/property.go @@ -106,8 +106,8 @@ var RelationFormatToPropertyFormat = map[model.RelationFormat]apimodel.PropertyF } // ListProperties returns a list of properties for a specific space. -func (s *Service) ListProperties(ctx context.Context, spaceId string, filters []Filter, offset int, limit int) (properties []apimodel.Property, total int, hasMore bool, err error) { - baseFilters := []*model.BlockContentDataviewFilter{ +func (s *Service) ListProperties(ctx context.Context, spaceId string, additionalFilters []*model.BlockContentDataviewFilter, offset int, limit int) (properties []apimodel.Property, total int, hasMore bool, err error) { + filters := append([]*model.BlockContentDataviewFilter{ { RelationKey: bundle.RelationKeyResolvedLayout.String(), Condition: model.BlockContentDataviewFilter_Equal, @@ -118,17 +118,11 @@ func (s *Service) ListProperties(ctx context.Context, spaceId string, filters [] Condition: model.BlockContentDataviewFilter_NotEqual, Value: pbtypes.Bool(true), }, - } - for _, f := range filters { - baseFilters = append(baseFilters, &model.BlockContentDataviewFilter{ - RelationKey: f.RelationKey, - Condition: f.Condition, - Value: f.Value, - }) - } + }, additionalFilters...) + resp := s.mw.ObjectSearch(ctx, &pb.RpcObjectSearchRequest{ SpaceId: spaceId, - Filters: baseFilters, + Filters: filters, Sorts: []*model.BlockContentDataviewSort{ { RelationKey: bundle.RelationKeyName.String(), diff --git a/core/api/service/space.go b/core/api/service/space.go index b5c602c94..99a4385cb 100644 --- a/core/api/service/space.go +++ b/core/api/service/space.go @@ -33,8 +33,8 @@ var ( ) // ListSpaces returns a paginated list of spaces for the account. -func (s *Service) ListSpaces(ctx context.Context, filters []Filter, offset int, limit int) (spaces []apimodel.Space, total int, hasMore bool, err error) { - baseFilters := []*model.BlockContentDataviewFilter{ +func (s *Service) ListSpaces(ctx context.Context, additionalFilters []*model.BlockContentDataviewFilter, offset int, limit int) (spaces []apimodel.Space, total int, hasMore bool, err error) { + filters := append([]*model.BlockContentDataviewFilter{ { RelationKey: bundle.RelationKeyResolvedLayout.String(), Condition: model.BlockContentDataviewFilter_Equal, @@ -50,17 +50,11 @@ func (s *Service) ListSpaces(ctx context.Context, filters []Filter, offset int, Condition: model.BlockContentDataviewFilter_In, Value: pbtypes.IntList(int(model.SpaceStatus_Unknown), int(model.SpaceStatus_SpaceActive)), }, - } - for _, f := range filters { - baseFilters = append(baseFilters, &model.BlockContentDataviewFilter{ - RelationKey: f.RelationKey, - Condition: f.Condition, - Value: f.Value, - }) - } + }, additionalFilters...) + resp := s.mw.ObjectSearch(ctx, &pb.RpcObjectSearchRequest{ SpaceId: s.techSpaceId, - Filters: baseFilters, + Filters: filters, Sorts: []*model.BlockContentDataviewSort{ { RelationKey: bundle.RelationKeySpaceOrder.String(), diff --git a/core/api/service/tag.go b/core/api/service/tag.go index a08938c62..0085a7c61 100644 --- a/core/api/service/tag.go +++ b/core/api/service/tag.go @@ -27,13 +27,13 @@ var ( ) // ListTags returns all tags for a given property id in a space. -func (s *Service) ListTags(ctx context.Context, spaceId string, propertyId string, filters []Filter, offset int, limit int) (tags []apimodel.Tag, total int, hasMore bool, err error) { +func (s *Service) ListTags(ctx context.Context, spaceId string, propertyId string, additionalFilters []*model.BlockContentDataviewFilter, offset int, limit int) (tags []apimodel.Tag, total int, hasMore bool, err error) { _, rk, err := util.ResolveIdtoUniqueKeyAndRelationKey(s.mw, spaceId, propertyId) if err != nil { return nil, 0, false, ErrInvalidPropertyId } - baseFilters := []*model.BlockContentDataviewFilter{ + filters := append([]*model.BlockContentDataviewFilter{ { RelationKey: bundle.RelationKeyResolvedLayout.String(), Condition: model.BlockContentDataviewFilter_In, @@ -44,17 +44,11 @@ func (s *Service) ListTags(ctx context.Context, spaceId string, propertyId strin Condition: model.BlockContentDataviewFilter_Equal, Value: pbtypes.String(rk), }, - } - for _, f := range filters { - baseFilters = append(baseFilters, &model.BlockContentDataviewFilter{ - RelationKey: f.RelationKey, - Condition: f.Condition, - Value: f.Value, - }) - } + }, additionalFilters...) + resp := s.mw.ObjectSearch(ctx, &pb.RpcObjectSearchRequest{ SpaceId: spaceId, - Filters: baseFilters, + Filters: filters, Keys: []string{ bundle.RelationKeyId.String(), bundle.RelationKeyUniqueKey.String(), diff --git a/core/api/service/template.go b/core/api/service/template.go index afd916fb8..78fde5c60 100644 --- a/core/api/service/template.go +++ b/core/api/service/template.go @@ -20,7 +20,7 @@ var ( ) // ListTemplates returns a paginated list of templates in a specific space. -func (s *Service) ListTemplates(ctx context.Context, spaceId string, typeId string, filters []Filter, offset int, limit int) (templates []apimodel.Object, total int, hasMore bool, err error) { +func (s *Service) ListTemplates(ctx context.Context, spaceId string, typeId string, additionalFilters []*model.BlockContentDataviewFilter, offset int, limit int) (templates []apimodel.Object, total int, hasMore bool, err error) { // First, determine the type ID of "ot-template" in the space templateTypeIdResp := s.mw.ObjectSearch(ctx, &pb.RpcObjectSearchRequest{ SpaceId: spaceId, @@ -44,7 +44,7 @@ func (s *Service) ListTemplates(ctx context.Context, spaceId string, typeId stri // Then, search all objects of the template type and filter by the target type templateTypeId := templateTypeIdResp.Records[0].Fields[bundle.RelationKeyId.String()].GetStringValue() - baseFilters := []*model.BlockContentDataviewFilter{ + filters := append([]*model.BlockContentDataviewFilter{ { RelationKey: bundle.RelationKeyType.String(), Condition: model.BlockContentDataviewFilter_Equal, @@ -55,17 +55,11 @@ func (s *Service) ListTemplates(ctx context.Context, spaceId string, typeId stri Condition: model.BlockContentDataviewFilter_Equal, Value: pbtypes.String(typeId), }, - } - for _, f := range filters { - baseFilters = append(baseFilters, &model.BlockContentDataviewFilter{ - RelationKey: f.RelationKey, - Condition: f.Condition, - Value: f.Value, - }) - } + }, additionalFilters...) + templateObjectsResp := s.mw.ObjectSearch(ctx, &pb.RpcObjectSearchRequest{ SpaceId: spaceId, - Filters: baseFilters, + Filters: filters, }) if templateObjectsResp.Error.Code != pb.RpcObjectSearchResponseError_NULL { diff --git a/core/api/service/type.go b/core/api/service/type.go index c49a88a58..f68584012 100644 --- a/core/api/service/type.go +++ b/core/api/service/type.go @@ -31,8 +31,8 @@ var ( ) // ListTypes returns a paginated list of types in a specific space. -func (s *Service) ListTypes(ctx context.Context, spaceId string, filters []Filter, offset int, limit int) (types []apimodel.Type, total int, hasMore bool, err error) { - baseFilters := []*model.BlockContentDataviewFilter{ +func (s *Service) ListTypes(ctx context.Context, spaceId string, additionalFilters []*model.BlockContentDataviewFilter, offset int, limit int) (types []apimodel.Type, total int, hasMore bool, err error) { + filters := append([]*model.BlockContentDataviewFilter{ { RelationKey: bundle.RelationKeyResolvedLayout.String(), Condition: model.BlockContentDataviewFilter_Equal, @@ -43,17 +43,11 @@ func (s *Service) ListTypes(ctx context.Context, spaceId string, filters []Filte Condition: model.BlockContentDataviewFilter_NotEqual, Value: pbtypes.Bool(true), }, - } - for _, f := range filters { - baseFilters = append(baseFilters, &model.BlockContentDataviewFilter{ - RelationKey: f.RelationKey, - Condition: f.Condition, - Value: f.Value, - }) - } + }, additionalFilters...) + resp := s.mw.ObjectSearch(ctx, &pb.RpcObjectSearchRequest{ SpaceId: spaceId, - Filters: baseFilters, + Filters: filters, Sorts: []*model.BlockContentDataviewSort{ { RelationKey: bundle.RelationKeyName.String(),