You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by da...@apache.org on 2022/10/05 12:56:06 UTC

[beam] branch master updated: group_id (#23445)

This is an automated email from the ASF dual-hosted git repository.

damccorm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 48f962e2cc4 group_id (#23445)
48f962e2cc4 is described below

commit 48f962e2cc4d12f1103c64e145ff1550316a2c97
Author: Evgeny Antyshev <ea...@gmail.com>
AuthorDate: Wed Oct 5 15:55:55 2022 +0300

    group_id (#23445)
---
 learning/tour-of-beam/backend/internal/entity.go            |  1 +
 learning/tour-of-beam/backend/internal/fs_content/load.go   |  3 ++-
 .../tour-of-beam/backend/internal/fs_content/load_test.go   |  4 +++-
 learning/tour-of-beam/backend/internal/storage/adapter.go   | 13 ++++++-------
 learning/tour-of-beam/backend/internal/storage/schema.go    |  1 +
 .../tour-of-beam/backend/samples/api/get_content_tree.json  |  1 +
 .../learning-content/python/module 1/group/group-info.yaml  |  2 +-
 7 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/learning/tour-of-beam/backend/internal/entity.go b/learning/tour-of-beam/backend/internal/entity.go
index f5e05bb2ad6..45f5c15bdbb 100644
--- a/learning/tour-of-beam/backend/internal/entity.go
+++ b/learning/tour-of-beam/backend/internal/entity.go
@@ -48,6 +48,7 @@ const (
 )
 
 type Group struct {
+	Id    string `json:"id"`
 	Title string `json:"title"`
 	Nodes []Node `json:"nodes"`
 }
diff --git a/learning/tour-of-beam/backend/internal/fs_content/load.go b/learning/tour-of-beam/backend/internal/fs_content/load.go
index 84caa72d93a..af532a178c1 100644
--- a/learning/tour-of-beam/backend/internal/fs_content/load.go
+++ b/learning/tour-of-beam/backend/internal/fs_content/load.go
@@ -50,6 +50,7 @@ type learningModuleInfo struct {
 }
 
 type learningGroupInfo struct {
+	Id      string   `yaml:"id"`
 	Name    string   `yaml:"name"`
 	Content []string `yaml:"content"`
 }
@@ -99,7 +100,7 @@ func collectUnit(infopath string, ctx *sdkContext) (unit *tob.Unit, err error) {
 func collectGroup(infopath string, ctx *sdkContext) (*tob.Group, error) {
 	info := loadLearningGroupInfo(infopath)
 	log.Printf("Found Group %v metadata at %v\n", info.Name, infopath)
-	group := tob.Group{Title: info.Name}
+	group := tob.Group{Id: info.Id, Title: info.Name}
 	for _, item := range info.Content {
 		node, err := collectNode(filepath.Join(infopath, "..", item), ctx)
 		if err != nil {
diff --git a/learning/tour-of-beam/backend/internal/fs_content/load_test.go b/learning/tour-of-beam/backend/internal/fs_content/load_test.go
index 39a497e3beb..8e50f6360b7 100644
--- a/learning/tour-of-beam/backend/internal/fs_content/load_test.go
+++ b/learning/tour-of-beam/backend/internal/fs_content/load_test.go
@@ -77,7 +77,9 @@ func TestSample(t *testing.T) {
 					getExampleNode("intro-unit", tob.SDK_PYTHON),
 					{
 						Type: tob.NODE_GROUP, Group: &tob.Group{
-							Title: "The Group", Nodes: []tob.Node{
+							Id:    "group1",
+							Title: "The Group",
+							Nodes: []tob.Node{
 								getExampleNode("example1", tob.SDK_PYTHON),
 								getTaskNode("challenge1", tob.SDK_PYTHON),
 							},
diff --git a/learning/tour-of-beam/backend/internal/storage/adapter.go b/learning/tour-of-beam/backend/internal/storage/adapter.go
index 3c2dee6ecb8..28240dcc09a 100644
--- a/learning/tour-of-beam/backend/internal/storage/adapter.go
+++ b/learning/tour-of-beam/backend/internal/storage/adapter.go
@@ -64,9 +64,7 @@ func MakeGroupNode(group *tob.Group, order, level int) *TbLearningNode {
 		return nil
 	}
 	return &TbLearningNode{
-		// ID doesn't make much sense for groups,
-		// but we have to define it to include in queries
-		Id:    group.Title,
+		Id:    group.Id,
 		Title: group.Title,
 
 		Type:  tob.NODE_GROUP,
@@ -96,12 +94,13 @@ func FromDatastoreUnit(tbUnit *TbLearningUnit, id, title string) *tob.Unit {
 }
 
 // Depending on the projection, we either convert TbLearningGroup to a model
-// Or we use common field Title to make it.
-func FromDatastoreGroup(tbGroup *TbLearningGroup, title string) *tob.Group {
+// Or we use common fields Id, Title to make it.
+func FromDatastoreGroup(tbGroup *TbLearningGroup, id, title string) *tob.Group {
 	if tbGroup == nil {
-		return &tob.Group{Title: title}
+		return &tob.Group{Id: id, Title: title}
 	}
 	return &tob.Group{
+		Id:    tbGroup.Id,
 		Title: tbGroup.Title,
 	}
 }
@@ -112,7 +111,7 @@ func FromDatastoreNode(tbNode TbLearningNode) tob.Node {
 	}
 	switch tbNode.Type {
 	case tob.NODE_GROUP:
-		node.Group = FromDatastoreGroup(tbNode.Group, tbNode.Title)
+		node.Group = FromDatastoreGroup(tbNode.Group, tbNode.Id, tbNode.Title)
 	case tob.NODE_UNIT:
 		node.Unit = FromDatastoreUnit(tbNode.Unit, tbNode.Id, tbNode.Title)
 	default:
diff --git a/learning/tour-of-beam/backend/internal/storage/schema.go b/learning/tour-of-beam/backend/internal/storage/schema.go
index e2dea3f2980..5e36c86f490 100644
--- a/learning/tour-of-beam/backend/internal/storage/schema.go
+++ b/learning/tour-of-beam/backend/internal/storage/schema.go
@@ -59,6 +59,7 @@ type TbLearningModule struct {
 
 // tb_learning_node.group.
 type TbLearningGroup struct {
+	Id    string `datastore:"id"`
 	Title string `datastore:"title"`
 }
 
diff --git a/learning/tour-of-beam/backend/samples/api/get_content_tree.json b/learning/tour-of-beam/backend/samples/api/get_content_tree.json
index 4dadd6564f1..15a04ea4eb8 100644
--- a/learning/tour-of-beam/backend/samples/api/get_content_tree.json
+++ b/learning/tour-of-beam/backend/samples/api/get_content_tree.json
@@ -14,6 +14,7 @@
            },
            {
               "group" : {
+                 "id": "group1",
                  "title" : "The Group",
                  "nodes" : [
                     {
diff --git a/learning/tour-of-beam/backend/samples/learning-content/python/module 1/group/group-info.yaml b/learning/tour-of-beam/backend/samples/learning-content/python/module 1/group/group-info.yaml
index 1619bc19fb9..95c810a7b62 100644
--- a/learning/tour-of-beam/backend/samples/learning-content/python/module 1/group/group-info.yaml	
+++ b/learning/tour-of-beam/backend/samples/learning-content/python/module 1/group/group-info.yaml	
@@ -1,4 +1,4 @@
-id: group
+id: group1
 name: The Group
 complexity: BASIC
 content: