You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/09/01 14:42:44 UTC

[GitHub] [beam] eantyshev commented on a diff in pull request #22967: [Tour Of Beam][backend] get unit content

eantyshev commented on code in PR #22967:
URL: https://github.com/apache/beam/pull/22967#discussion_r960743410


##########
learning/tour-of-beam/backend/internal/storage/datastore.go:
##########
@@ -227,5 +227,34 @@ func (d *DatastoreDb) SaveContentTrees(ctx context.Context, trees []tob.ContentT
 	return nil
 }
 
+// Get learning unit content by unitId
+func (d *DatastoreDb) GetUnitContent(ctx context.Context, sdk tob.Sdk, unitId string) (unit *tob.Unit, err error) {
+	var tbNodes []TbLearningNode
+	rootKey := pgNameKey(TbLearningPathKind, sdkToKey(sdk), nil)
+
+	query := datastore.NewQuery(TbLearningNodeKind).
+		Namespace(PgNamespace).
+		Ancestor(rootKey).
+		FilterField("id", "=", unitId)
+
+	_, err = d.Client.GetAll(ctx, query, &tbNodes)
+	if err != nil {
+		return nil, fmt.Errorf("query unit failed: %w", err)
+	}
+
+	switch {
+	case len(tbNodes) == 0:
+		return nil, nil

Review Comment:
   I thought on it and decided to introduce an error in a service layer, where it belongs
   (non-existing unit is OK in the database context)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org