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


##########
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:
   From my perspective, it's not a good approach to return the double nil to 
handle this case later. I recommend you return error here.
   
   As for the next step:
   ```
        if err != nil {
                log.Println("Get unit content error:", err)
                finalizeErrResponse(w, http.StatusInternalServerError, 
INTERNAL_ERROR, "storage error")
                return
        }
        if unit == nil {
                log.Println("Get unit content error:", err)
                finalizeErrResponse(w, http.StatusNotFound, NOT_FOUND, "unit 
not found")
                return
        }
   ```
   Maybe the best way to create custom errors and handle them using switch-case
   
   It' not major because it's related to your code style. I'm sharing to you my 
thoughts about that.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to