damccorm commented on code in PR #23782:
URL: https://github.com/apache/beam/pull/23782#discussion_r1006916820
##########
learning/tour-of-beam/backend/internal/service/content.go:
##########
@@ -23,30 +23,48 @@ import (
"beam.apache.org/learning/tour-of-beam/backend/internal/storage"
)
-var ErrNoUnit = errors.New("unit not found")
-
type IContent interface {
- GetContentTree(ctx context.Context, sdk tob.Sdk, userId *string)
(tob.ContentTree, error)
- GetUnitContent(ctx context.Context, sdk tob.Sdk, unitId string, userId
*string) (tob.Unit, error)
+ GetContentTree(ctx context.Context, sdk tob.Sdk) (tob.ContentTree,
error)
+ GetUnitContent(ctx context.Context, sdk tob.Sdk, unitId string)
(tob.Unit, error)
+ GetUserProgress(ctx context.Context, sdk tob.Sdk, userId string)
(tob.SdkProgress, error)
+ SetUnitComplete(ctx context.Context, sdk tob.Sdk, unitId, uid string)
error
}
type Svc struct {
Repo storage.Iface
}
-func (s *Svc) GetContentTree(ctx context.Context, sdk tob.Sdk, userId *string)
(ct tob.ContentTree, err error) {
- // TODO enrich tree with user-specific state (isCompleted)
+func (s *Svc) GetContentTree(ctx context.Context, sdk tob.Sdk) (ct
tob.ContentTree, err error) {
return s.Repo.GetContentTree(ctx, sdk)
}
-func (s *Svc) GetUnitContent(ctx context.Context, sdk tob.Sdk, unitId string,
userId *string) (tob.Unit, error) {
- // TODO enrich unit with user-specific state: isCompleted, userSnippetId
+func (s *Svc) GetUnitContent(ctx context.Context, sdk tob.Sdk, unitId string)
(tob.Unit, error) {
unit, err := s.Repo.GetUnitContent(ctx, sdk, unitId)
if err != nil {
return tob.Unit{}, err
}
if unit == nil {
- return tob.Unit{}, ErrNoUnit
+ return tob.Unit{}, tob.ErrNoUnit
}
return *unit, nil
}
+
+func (s *Svc) GetUserProgress(ctx context.Context, sdk tob.Sdk, userId string)
(tob.SdkProgress, error) {
+ progress, err := s.Repo.GetUserProgress(ctx, sdk, userId)
+ if errors.Is(err, tob.ErrNoUser) {
+ // make an empty list a default response
+ return tob.SdkProgress{Units: make([]tob.UnitProgress, 0)}, nil
+ }
+ if err != nil {
+ return tob.SdkProgress{}, err
+ }
+ if progress == nil {
+ panic("progress is nil, no err")
Review Comment:
I guess that's fair - this would represent a pretty complete failure. I'm ok
with it
--
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]