Skip to content

Commit

Permalink
Refactor lesson retrieval in MtcApiClient to validate tasks and impro…
Browse files Browse the repository at this point in the history
…ve error handling; update go.mod and go.sum to remove unused dependency on go-pretty.
  • Loading branch information
zenion committed Dec 19, 2024
1 parent ad76e8f commit 50d3491
Show file tree
Hide file tree
Showing 4 changed files with 1,394 additions and 417 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/charmbracelet/lipgloss v0.7.1
github.com/erikgeiser/promptkit v0.9.0
github.com/go-resty/resty/v2 v2.16.2
github.com/jedib0t/go-pretty/v6 v6.6.5
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jedib0t/go-pretty/v6 v6.6.5 h1:9PgMJOVBedpgYLI56jQRJYqngxYAAzfEUua+3NgSqAo=
github.com/jedib0t/go-pretty/v6 v6.6.5/go.mod h1:Uq/HrbhuFty5WSVNfjpQQe47x16RwVGXIveNGEyGtHs=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
Expand Down
9 changes: 8 additions & 1 deletion internal/mtcapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ func (c *MtcApiClient) GetLesson(lessonToken string) (types.Lesson, error) {
if err != nil {
return types.Lesson{}, err
}
return *res.Result().(*types.Lesson), nil

results := *res.Result().(*types.Lesson)

if len(results.Tasks) == 0 {
return types.Lesson{}, fmt.Errorf("token is invalid")
}

return results, nil
}

func (c *MtcApiClient) SubmitLesson(lessonToken string, cliCommandResults []types.CLICommandResult) (types.Lesson, error) {
Expand Down
Loading

0 comments on commit 50d3491

Please sign in to comment.