mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 09:35:00 +09:00
GO-4459: Return object layout and unify GetObject usage
This commit is contained in:
parent
f869fbf7b7
commit
47acefc704
9 changed files with 35 additions and 70 deletions
|
@ -55,23 +55,24 @@ func main() {
|
|||
// {"POST", "/auth/displayCode", nil, nil},
|
||||
// {"GET", "/auth/token?challengeId={challengeId}&code={code}", map[string]interface{}{"challengeId": "6738dfc5cda913aad90e8c2a", "code": "2931"}, nil},
|
||||
|
||||
// export
|
||||
// {"GET", "/spaces/{space_id}/objects/{object_id}/export/{format}", map[string]interface{}{"space_id": testSpaceId, "object_id": testObjectId, "format": "markdown"}, nil},
|
||||
|
||||
// spaces
|
||||
// {"POST", "/spaces", nil, map[string]interface{}{"name": "New Space"}},
|
||||
// {"GET", "/spaces?limit={limit}&offset={offset}", map[string]interface{}{"limit": 100, "offset": 0}, nil},
|
||||
// {"GET", "/spaces/{space_id}/members?limit={limit}&offset={offset}", map[string]interface{}{"space_id": testSpaceId, "limit": 100, "offset": 0}, nil},
|
||||
|
||||
// space_objects
|
||||
// objects
|
||||
// {"GET", "/spaces/{space_id}/objects?limit={limit}&offset={offset}", map[string]interface{}{"space_id": testSpaceId, "limit": 100, "offset": 0}, nil},
|
||||
// {"GET", "/spaces/{space_id}/objects/{object_id}", map[string]interface{}{"space_id": testSpaceId, "object_id": testObjectId}, nil},
|
||||
// {"POST", "/spaces/{space_id}/objects", map[string]interface{}{"space_id": testSpaceId}, map[string]interface{}{"name": "New Object from demo", "icon_emoji": "💥", "template_id": "", "object_type_unique_key": "ot-page", "with_chat": false}},
|
||||
// {"POST", "/spaces/{space_id}/objects", map[string]interface{}{"space_id": testSpaceId}, map[string]interface{}{"name": "New Object from demo", "icon": "💥", "template_id": "", "object_type_unique_key": "ot-page", "with_chat": false}},
|
||||
// {"PUT", "/spaces/{space_id}/objects/{object_id}", map[string]interface{}{"space_id": testSpaceId, "object_id": testObjectId}, map[string]interface{}{"name": "Updated Object"}},
|
||||
|
||||
// types_and_templates
|
||||
// {"GET", "/spaces/{space_id}/objectTypes?limit={limit}&offset={offset}", map[string]interface{}{"space_id": testSpaceId, "limit": 100, "offset": 0}, nil},
|
||||
// {"GET", "/spaces/{space_id}/objectTypes/{type_id}/templates?limit={limit}&offset={offset}", map[string]interface{}{"space_id": testSpaceId, "type_id": testTypeId, "limit": 100, "offset": 0}, nil},
|
||||
// {"GET", "/spaces/{space_id}/object_types?limit={limit}&offset={offset}", map[string]interface{}{"space_id": testSpaceId, "limit": 100, "offset": 0}, nil},
|
||||
// {"GET", "/spaces/{space_id}/object_types/{type_id}/templates?limit={limit}&offset={offset}", map[string]interface{}{"space_id": testSpaceId, "type_id": testTypeId, "limit": 100, "offset": 0}, nil},
|
||||
|
||||
// search
|
||||
// {"GET", "/search?query={query}&object_type={object_type}&limit={limit}&offset={offset}", map[string]interface{}{"query": "Tag", "object_type": testTypeId, "limit": 100, "offset": 0}, nil},
|
||||
// {"GET", "/search?query={query}&object_types={object_types}&limit={limit}&offset={offset}", map[string]interface{}{"query": "new", "object_types": "", "limit": 100, "offset": 0}, nil},
|
||||
}
|
||||
|
||||
for _, ep := range endpoints {
|
||||
|
|
|
@ -942,6 +942,10 @@ const docTemplate = `{
|
|||
"type": "string",
|
||||
"example": "bafyreie6n5l5nkbjal37su54cha4coy7qzuhrnajluzv5qd5jvtsrxkequ"
|
||||
},
|
||||
"layout": {
|
||||
"type": "string",
|
||||
"example": "basic"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"example": "Object Name"
|
||||
|
|
|
@ -936,6 +936,10 @@
|
|||
"type": "string",
|
||||
"example": "bafyreie6n5l5nkbjal37su54cha4coy7qzuhrnajluzv5qd5jvtsrxkequ"
|
||||
},
|
||||
"layout": {
|
||||
"type": "string",
|
||||
"example": "basic"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"example": "Object Name"
|
||||
|
|
|
@ -89,6 +89,9 @@ definitions:
|
|||
id:
|
||||
example: bafyreie6n5l5nkbjal37su54cha4coy7qzuhrnajluzv5qd5jvtsrxkequ
|
||||
type: string
|
||||
layout:
|
||||
example: basic
|
||||
type: string
|
||||
name:
|
||||
example: Object Name
|
||||
type: string
|
||||
|
|
|
@ -29,6 +29,7 @@ type Object struct {
|
|||
Id string `json:"id" example:"bafyreie6n5l5nkbjal37su54cha4coy7qzuhrnajluzv5qd5jvtsrxkequ"`
|
||||
Name string `json:"name" example:"Object Name"`
|
||||
Icon string `json:"icon" example:"📄"`
|
||||
Layout string `json:"layout" example:"basic"`
|
||||
ObjectType string `json:"object_type" example:"Page"`
|
||||
SpaceId string `json:"space_id" example:"bafyreigyfkt6rbv24sbv5aq2hko3bhmv5xxlf22b4bypdu6j7hnphm3psq.23me69r569oi1"`
|
||||
RootId string `json:"root_id"`
|
||||
|
|
|
@ -82,7 +82,7 @@ func (s *ObjectService) ListObjects(ctx context.Context, spaceId string, offset
|
|||
Offset: 0,
|
||||
Limit: 0,
|
||||
ObjectTypeFilter: []string{},
|
||||
Keys: []string{"id", "name", "type", "layout", "iconEmoji", "iconImage"},
|
||||
Keys: []string{"id", "name"},
|
||||
})
|
||||
|
||||
if resp.Error.Code != pb.RpcObjectSearchResponseError_NULL {
|
||||
|
@ -103,9 +103,6 @@ func (s *ObjectService) ListObjects(ctx context.Context, spaceId string, offset
|
|||
return nil, 0, false, err
|
||||
}
|
||||
|
||||
// TODO: layout is not correctly returned in ObjectShow; therefore we need to resolve it here
|
||||
object.Type = model.ObjectTypeLayout_name[int32(record.Fields["layout"].GetNumberValue())]
|
||||
|
||||
objects = append(objects, object)
|
||||
}
|
||||
return objects, total, hasMore, nil
|
||||
|
@ -137,6 +134,7 @@ func (s *ObjectService) GetObject(ctx context.Context, spaceId string, objectId
|
|||
Id: resp.ObjectView.Details[0].Details.Fields["id"].GetStringValue(),
|
||||
Name: resp.ObjectView.Details[0].Details.Fields["name"].GetStringValue(),
|
||||
Icon: icon,
|
||||
Layout: model.ObjectTypeLayout_name[int32(resp.ObjectView.Details[0].Details.Fields["layout"].GetNumberValue())],
|
||||
ObjectType: objectTypeName,
|
||||
SpaceId: resp.ObjectView.Details[0].Details.Fields["spaceId"].GetStringValue(),
|
||||
RootId: resp.ObjectView.RootId,
|
||||
|
@ -166,34 +164,7 @@ func (s *ObjectService) CreateObject(ctx context.Context, spaceId string, reques
|
|||
return Object{}, ErrFailedCreateObject
|
||||
}
|
||||
|
||||
objShowResp := s.mw.ObjectShow(ctx, &pb.RpcObjectShowRequest{
|
||||
SpaceId: spaceId,
|
||||
ObjectId: resp.ObjectId,
|
||||
})
|
||||
|
||||
if objShowResp.Error.Code != pb.RpcObjectShowResponseError_NULL {
|
||||
return Object{}, ErrFailedRetrieveObject
|
||||
}
|
||||
|
||||
icon2 := util.GetIconFromEmojiOrImage(s.AccountInfo, objShowResp.ObjectView.Details[0].Details.Fields["iconEmoji"].GetStringValue(), objShowResp.ObjectView.Details[0].Details.Fields["iconImage"].GetStringValue())
|
||||
objectTypeName, err := util.ResolveTypeToName(s.mw, spaceId, objShowResp.ObjectView.Details[0].Details.Fields["type"].GetStringValue())
|
||||
if err != nil {
|
||||
return Object{}, err
|
||||
}
|
||||
|
||||
object := Object{
|
||||
Type: "object",
|
||||
Id: resp.ObjectId,
|
||||
Name: objShowResp.ObjectView.Details[0].Details.Fields["name"].GetStringValue(),
|
||||
Icon: icon2,
|
||||
ObjectType: objectTypeName,
|
||||
SpaceId: objShowResp.ObjectView.Details[0].Details.Fields["spaceId"].GetStringValue(),
|
||||
RootId: objShowResp.ObjectView.RootId,
|
||||
Blocks: s.GetBlocks(objShowResp),
|
||||
Details: s.GetDetails(objShowResp),
|
||||
}
|
||||
|
||||
return object, nil
|
||||
return s.GetObject(ctx, spaceId, resp.ObjectId)
|
||||
}
|
||||
|
||||
// UpdateObject updates an existing object in a specific space.
|
||||
|
|
|
@ -79,7 +79,7 @@ func TestObjectService_ListObjects(t *testing.T) {
|
|||
Offset: 0,
|
||||
Limit: 0,
|
||||
ObjectTypeFilter: []string{},
|
||||
Keys: []string{"id", "name", "type", "layout", "iconEmoji", "iconImage"},
|
||||
Keys: []string{"id", "name"},
|
||||
}).Return(&pb.RpcObjectSearchResponse{
|
||||
Records: []*types.Struct{
|
||||
{
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/anyproto/anytype-heart/cmd/api/object"
|
||||
"github.com/anyproto/anytype-heart/cmd/api/pagination"
|
||||
"github.com/anyproto/anytype-heart/cmd/api/space"
|
||||
"github.com/anyproto/anytype-heart/cmd/api/util"
|
||||
"github.com/anyproto/anytype-heart/pb"
|
||||
"github.com/anyproto/anytype-heart/pb/service"
|
||||
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
|
||||
|
@ -62,7 +61,7 @@ func (s *SearchService) Search(ctx context.Context, searchQuery string, objectTy
|
|||
IncludeTime: true,
|
||||
EmptyPlacement: model.BlockContentDataviewSort_NotSpecified,
|
||||
}},
|
||||
Keys: []string{"id", "name", "type", "snippet", "layout", "iconEmoji", "iconImage"},
|
||||
Keys: []string{"id", "name"},
|
||||
// TODO split limit between spaces
|
||||
// Limit: paginationLimitPerSpace,
|
||||
// FullText: searchTerm,
|
||||
|
@ -77,29 +76,11 @@ func (s *SearchService) Search(ctx context.Context, searchQuery string, objectTy
|
|||
}
|
||||
|
||||
for _, record := range objResp.Records {
|
||||
icon := util.GetIconFromEmojiOrImage(s.AccountInfo, record.Fields["iconEmoji"].GetStringValue(), record.Fields["iconImage"].GetStringValue())
|
||||
objectTypeName, err := util.ResolveTypeToName(s.mw, spaceId, record.Fields["type"].GetStringValue())
|
||||
object, err := s.objectService.GetObject(ctx, spaceId, record.Fields["id"].GetStringValue())
|
||||
if err != nil {
|
||||
return nil, 0, false, err
|
||||
}
|
||||
|
||||
showResp := s.mw.ObjectShow(ctx, &pb.RpcObjectShowRequest{
|
||||
SpaceId: spaceId,
|
||||
ObjectId: record.Fields["id"].GetStringValue(),
|
||||
})
|
||||
|
||||
// TODO: return snippet for notes?
|
||||
results = append(results, object.Object{
|
||||
Type: model.ObjectTypeLayout_name[int32(record.Fields["layout"].GetNumberValue())],
|
||||
Id: record.Fields["id"].GetStringValue(),
|
||||
Name: record.Fields["name"].GetStringValue(),
|
||||
Icon: icon,
|
||||
ObjectType: objectTypeName,
|
||||
SpaceId: spaceId,
|
||||
RootId: showResp.ObjectView.RootId,
|
||||
Blocks: s.objectService.GetBlocks(showResp),
|
||||
Details: s.objectService.GetDetails(showResp),
|
||||
})
|
||||
results = append(results, object)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -110,12 +110,8 @@ func TestSearchService_Search(t *testing.T) {
|
|||
Records: []*types.Struct{
|
||||
{
|
||||
Fields: map[string]*types.Value{
|
||||
"id": pbtypes.String("obj-global-1"),
|
||||
"name": pbtypes.String("Global Object"),
|
||||
"type": pbtypes.String("global-type-id"),
|
||||
"layout": pbtypes.Float64(float64(model.ObjectType_basic)),
|
||||
"iconEmoji": pbtypes.String("🌐"),
|
||||
"lastModifiedDate": pbtypes.Float64(999999),
|
||||
"id": pbtypes.String("obj-global-1"),
|
||||
"name": pbtypes.String("Global Object"),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -167,10 +163,13 @@ func TestSearchService_Search(t *testing.T) {
|
|||
Id: "root-123",
|
||||
Details: &types.Struct{
|
||||
Fields: map[string]*types.Value{
|
||||
"id": pbtypes.String("obj-global-1"),
|
||||
"name": pbtypes.String("Global Object"),
|
||||
"layout": pbtypes.Int64(int64(model.ObjectType_basic)),
|
||||
"iconEmoji": pbtypes.String("🌐"),
|
||||
"lastModifiedDate": pbtypes.Float64(999999),
|
||||
"createdDate": pbtypes.Float64(888888),
|
||||
"spaceId": pbtypes.String("space-1"),
|
||||
"tag": pbtypes.StringList([]string{"tag-1", "tag-2"}),
|
||||
},
|
||||
},
|
||||
|
@ -199,16 +198,17 @@ func TestSearchService_Search(t *testing.T) {
|
|||
}, nil).Once()
|
||||
|
||||
// when
|
||||
objects, total, hasMore, err := fx.Search(ctx, "search-term", "", offset, limit)
|
||||
objects, total, hasMore, err := fx.Search(ctx, "search-term", []string{}, offset, limit)
|
||||
|
||||
// then
|
||||
require.NoError(t, err)
|
||||
require.Len(t, objects, 1)
|
||||
require.Equal(t, "object", objects[0].Type)
|
||||
require.Equal(t, "space-1", objects[0].SpaceId)
|
||||
require.Equal(t, "Global Object", objects[0].Name)
|
||||
require.Equal(t, "obj-global-1", objects[0].Id)
|
||||
require.Equal(t, "basic", objects[0].Layout)
|
||||
require.Equal(t, "🌐", objects[0].Icon)
|
||||
require.Equal(t, "basic", objects[0].Type)
|
||||
require.Equal(t, "This is a sample text block", objects[0].Blocks[2].Text.Text)
|
||||
|
||||
// check details
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue