1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-10 18:10:49 +09:00

GO-2421: add details to BlockLinkCreateWithObject

Signed-off-by: AnastasiaShemyakinskaya <shem98a@mail.ru>
This commit is contained in:
AnastasiaShemyakinskaya 2024-02-15 13:44:12 +03:00
parent 3af984b2af
commit 98d14711fc
No known key found for this signature in database
GPG key ID: CCD60ED83B103281
7 changed files with 998 additions and 929 deletions

View file

@ -4,6 +4,7 @@ import (
"context"
"github.com/globalsign/mgo/bson"
"github.com/gogo/protobuf/types"
"google.golang.org/grpc/metadata"
"github.com/anyproto/anytype-heart/core/block"
@ -43,8 +44,8 @@ func (mw *Middleware) BlockCreate(cctx context.Context, req *pb.RpcBlockCreateRe
func (mw *Middleware) BlockLinkCreateWithObject(cctx context.Context, req *pb.RpcBlockLinkCreateWithObjectRequest) *pb.RpcBlockLinkCreateWithObjectResponse {
ctx := mw.newContext(cctx)
response := func(code pb.RpcBlockLinkCreateWithObjectResponseErrorCode, id, targetId string, err error) *pb.RpcBlockLinkCreateWithObjectResponse {
m := &pb.RpcBlockLinkCreateWithObjectResponse{Error: &pb.RpcBlockLinkCreateWithObjectResponseError{Code: code}, BlockId: id, TargetId: targetId}
response := func(code pb.RpcBlockLinkCreateWithObjectResponseErrorCode, id, targetId string, objectDetails *types.Struct, err error) *pb.RpcBlockLinkCreateWithObjectResponse {
m := &pb.RpcBlockLinkCreateWithObjectResponse{Error: &pb.RpcBlockLinkCreateWithObjectResponseError{Code: code}, BlockId: id, TargetId: targetId, Details: objectDetails}
if err != nil {
m.Error.Description = err.Error()
} else {
@ -52,15 +53,18 @@ func (mw *Middleware) BlockLinkCreateWithObject(cctx context.Context, req *pb.Rp
}
return m
}
var id, targetId string
var (
id, targetId string
objectDetails *types.Struct
)
err := mw.doBlockService(func(bs *block.Service) (err error) {
id, targetId, err = bs.CreateLinkToTheNewObject(cctx, ctx, req)
id, targetId, objectDetails, err = bs.CreateLinkToTheNewObject(cctx, ctx, req)
return
})
if err != nil {
return response(pb.RpcBlockLinkCreateWithObjectResponseError_UNKNOWN_ERROR, "", "", err)
return response(pb.RpcBlockLinkCreateWithObjectResponseError_UNKNOWN_ERROR, "", "", objectDetails, err)
}
return response(pb.RpcBlockLinkCreateWithObjectResponseError_NULL, id, targetId, nil)
return response(pb.RpcBlockLinkCreateWithObjectResponseError_NULL, id, targetId, objectDetails, nil)
}
func (mw *Middleware) ObjectOpen(cctx context.Context, req *pb.RpcObjectOpenRequest) *pb.RpcObjectOpenResponse {

View file

@ -4,6 +4,8 @@ import (
"context"
"fmt"
"github.com/gogo/protobuf/types"
"github.com/anyproto/anytype-heart/core/block/editor/basic"
"github.com/anyproto/anytype-heart/core/block/editor/smartblock"
"github.com/anyproto/anytype-heart/core/block/editor/state"
@ -77,7 +79,7 @@ func (s *Service) CreateLinkToTheNewObject(
ctx context.Context,
sctx session.Context,
req *pb.RpcBlockLinkCreateWithObjectRequest,
) (linkID string, objectID string, err error) {
) (linkID string, objectID string, objectDetails *types.Struct, err error) {
if req.ContextId == req.TemplateId && req.ContextId != "" {
err = fmt.Errorf("unable to create link to template from this template")
return
@ -85,7 +87,7 @@ func (s *Service) CreateLinkToTheNewObject(
objectTypeKey, err := domain.GetTypeKeyFromRawUniqueKey(req.ObjectTypeUniqueKey)
if err != nil {
return "", "", fmt.Errorf("get type key from raw unique key: %w", err)
return "", "", nil, fmt.Errorf("get type key from raw unique key: %w", err)
}
createReq := objectcreator.CreateObjectRequest{
@ -94,7 +96,7 @@ func (s *Service) CreateLinkToTheNewObject(
ObjectTypeKey: objectTypeKey,
TemplateId: req.TemplateId,
}
objectID, _, err = s.objectCreator.CreateObject(ctx, req.SpaceId, createReq)
objectID, objectDetails, err = s.objectCreator.CreateObject(ctx, req.SpaceId, createReq)
if err != nil {
return
}

View file

@ -677,7 +677,7 @@ func (s *Service) MoveBlocksToNewPage(
req pb.RpcBlockListMoveToNewObjectRequest,
) (linkID string, err error) {
// 1. Create new page, link
linkID, objectID, err := s.CreateLinkToTheNewObject(ctx, sctx, &pb.RpcBlockLinkCreateWithObjectRequest{
linkID, objectID, _, err := s.CreateLinkToTheNewObject(ctx, sctx, &pb.RpcBlockLinkCreateWithObjectRequest{
ContextId: req.ContextId,
TargetId: req.DropTargetId,
ObjectTypeUniqueKey: bundle.TypeKeyPage.URL(),

View file

@ -47,7 +47,7 @@ func NewFile(sb smartblock.SmartBlock, blockService BlockService, picker getbloc
}
type BlockService interface {
CreateLinkToTheNewObject(ctx context.Context, sctx session.Context, req *pb.RpcBlockLinkCreateWithObjectRequest) (linkID string, pageID string, err error)
CreateLinkToTheNewObject(ctx context.Context, sctx session.Context, req *pb.RpcBlockLinkCreateWithObjectRequest) (linkID string, pageID string, details *types.Struct, err error)
}
type File interface {
@ -216,7 +216,7 @@ func (sf *sfile) dropFilesCreateStructure(groupId, targetId string, pos model.Bl
return
}
sf.Unlock()
blockId, pageId, err = sf.blockService.CreateLinkToTheNewObject(context.Background(), nil, &pb.RpcBlockLinkCreateWithObjectRequest{
blockId, pageId, _, err = sf.blockService.CreateLinkToTheNewObject(context.Background(), nil, &pb.RpcBlockLinkCreateWithObjectRequest{
SpaceId: sf.SpaceID(),
ContextId: sf.Id(),
ObjectTypeUniqueKey: bundle.TypeKeyPage.URL(),

View file

@ -7207,6 +7207,7 @@ id of the closest simple block |
| blockId | [string](#string) | | |
| targetId | [string](#string) | | |
| event | [ResponseEvent](#anytype-ResponseEvent) | | |
| details | [google.protobuf.Struct](#google-protobuf-Struct) | | |

File diff suppressed because it is too large Load diff

View file

@ -5014,6 +5014,7 @@ message Rpc {
string blockId = 2;
string targetId = 3;
ResponseEvent event = 4;
google.protobuf.Struct details = 5;
message Error {
Code code = 1;