diff --git a/server/router/api/v1/memo_service.go b/server/router/api/v1/memo_service.go index e40e4bad..fd895762 100644 --- a/server/router/api/v1/memo_service.go +++ b/server/router/api/v1/memo_service.go @@ -352,6 +352,11 @@ func (s *APIV1Service) DeleteMemo(ctx context.Context, request *v1pb.DeleteMemoR return nil, status.Errorf(codes.Internal, "failed to delete memo") } + // Delete memo relation + if err := s.Store.DeleteMemoRelation(ctx, &store.DeleteMemoRelation{MemoID: &id}); err != nil { + return nil, status.Errorf(codes.Internal, "failed to delete memo relations") + } + // Delete related resources. resources, err := s.Store.ListResources(ctx, &store.FindResource{MemoID: &id}) if err != nil { @@ -363,6 +368,24 @@ func (s *APIV1Service) DeleteMemo(ctx context.Context, request *v1pb.DeleteMemoR } } + // Delete memo comments + commentType := store.MemoRelationComment + relations, err := s.Store.ListMemoRelations(ctx, &store.FindMemoRelation{RelatedMemoID: &id, Type: &commentType}) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to list memo comments") + } + for _, relation := range relations { + if _, err := s.DeleteMemo(ctx, &v1pb.DeleteMemoRequest{Name: fmt.Sprintf("%s%d", MemoNamePrefix, relation.MemoID)}); err != nil { + return nil, status.Errorf(codes.Internal, "failed to delete memo comment") + } + } + + // Delete memo references + referenceType := store.MemoRelationReference + if err := s.Store.DeleteMemoRelation(ctx, &store.DeleteMemoRelation{RelatedMemoID: &id, Type: &referenceType}); err != nil { + return nil, status.Errorf(codes.Internal, "failed to delete memo references") + } + return &emptypb.Empty{}, nil }