mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-07 21:37:04 +09:00
GO-5645: Refactor additional filtering in services and handlers
This commit is contained in:
parent
b12c66c712
commit
a81d9a6d95
16 changed files with 53 additions and 173 deletions
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue