Skip to content

Commit

Permalink
Add ChallengeNoTrack to avoid Entity Not Found when challenges get re…
Browse files Browse the repository at this point in the history
…moved

Signed-off-by: Raphaël Pinson <[email protected]>
  • Loading branch information
raphink committed Nov 1, 2024
1 parent f331e91 commit 9d84dc3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
9 changes: 9 additions & 0 deletions instruqt/challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ type Challenge struct {
} `json:"-"`
}

// ChallengeNoTrack represents the data structure for an Instruqt challenge.
type ChallengeNoTrack struct {
Id string `json:"id"` // The unique identifier for the challenge.
Slug string `json:"slug"` // The slug for the challenge, which is a human-readable identifier.
Title string `json:"title"` // The title of the challenge.
Index int `json:"index"` // The index of the challenge in the track.
Status string `json:"status"` // The status of the challenge (e.g., "unlocked", "completed").
}

// GetChallenge retrieves a challenge from Instruqt using its unique challenge ID.
//
// Parameters:
Expand Down
17 changes: 15 additions & 2 deletions instruqt/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ import (
"context"
"log"
"net/http"
"net/http/httputil"
"os"

"github.com/shurcooL/graphql"

loghttp "github.com/motemen/go-loghttp"

Check failure on line 26 in instruqt/client.go

View workflow job for this annotation

GitHub Actions / test-and-coverage

no required module provides package github.com/motemen/go-loghttp; to add it:
)

// GraphQLClient is an interface that defines the methods for interacting with
Expand Down Expand Up @@ -52,8 +55,18 @@ type Client struct {
func NewClient(token string, teamSlug string) *Client {
httpClient := &http.Client{}
httpClient.Transport = &BearerTokenRoundTripper{
Transport: http.DefaultTransport,
Token: token,
Transport: &loghttp.Transport{
Transport: httpClient.Transport,
LogRequest: func(req *http.Request) {
b, _ := httputil.DumpRequestOut(req, true)
log.Printf("out body: %s", string(b))
},
LogResponse: func(resp *http.Response) {
b, _ := httputil.DumpResponse(resp, true)
log.Printf("in body: %s", string(b))
},
},
Token: token,
}
return &Client{
GraphQLClient: graphql.NewClient("https://play.instruqt.com/graphql", httpClient),
Expand Down
22 changes: 11 additions & 11 deletions instruqt/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ type SandboxTrack struct {
TotalCount int
Nodes []Review
}
Challenges []Challenge // A list of challenges associated with the sandbox track.
Status string // The current status of the sandbox track.
Started time.Time // The timestamp when the sandbox track was started.
Completed time.Time // The timestamp when the sandbox track was completed.
Participant struct { // Information about the participant of the sandbox track.
Challenges []ChallengeNoTrack // A list of challenges associated with the sandbox track.
Status string // The current status of the sandbox track.
Started time.Time // The timestamp when the sandbox track was started.
Completed time.Time // The timestamp when the sandbox track was completed.
Participant struct { // Information about the participant of the sandbox track.
Id string
}
}
Expand All @@ -117,11 +117,11 @@ type SandboxTrackNoReviews struct {
TrackTags []struct { // A list of tags associated with the sandbox track.
Value string
}
Challenges []Challenge // A list of challenges associated with the sandbox track.
Status string // The current status of the sandbox track.
Started time.Time // The timestamp when the sandbox track was started.
Completed time.Time // The timestamp when the sandbox track was completed.
Participant struct { // Information about the participant of the sandbox track.
Challenges []ChallengeNoTrack // A list of challenges associated with the sandbox track.
Status string // The current status of the sandbox track.
Started time.Time // The timestamp when the sandbox track was started.
Completed time.Time // The timestamp when the sandbox track was completed.
Participant struct { // Information about the participant of the sandbox track.
Id string
}
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func (c *Client) GetTrackBySlug(trackSlug string) (t Track, err error) {
// Returns:
// - Challenge: The first unlocked challenge found.
// - error: Any error encountered while retrieving the challenge.
func (c *Client) GetTrackUnlockedChallenge(userId string, trackId string) (challenge Challenge, err error) {
func (c *Client) GetTrackUnlockedChallenge(userId string, trackId string) (challenge ChallengeNoTrack, err error) {
track, err := c.GetUserTrackById(userId, trackId)
if err != nil {
return challenge, fmt.Errorf("[instruqt.GetTrackUnlockedChallenge] failed to get user track: %v", err)
Expand Down

0 comments on commit 9d84dc3

Please sign in to comment.