-
-
Notifications
You must be signed in to change notification settings - Fork 369
Expand file tree
/
Copy pathstatus_info.go
More file actions
64 lines (50 loc) · 1.42 KB
/
status_info.go
File metadata and controls
64 lines (50 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package api
import (
"fmt"
"log"
"strings"
"time"
)
const dateFormat = "January 2, 2006"
// StatusInfo contains information about a user's status on a particular language track.
type StatusInfo struct {
TrackID string `json:"track_id"`
Recent *Recent
FetchedProblems *Slugs `json:"fetched"`
SkippedProblems *Slugs `json:"skipped"`
}
// Recent contains information about the user's most recently submitted exercise on a particular language track.
type Recent struct {
Problem string `json:"problem"`
SubmittedAt string `json:"submitted_at"`
}
// Slugs is a collection of slugs, all of which are the names of exercises.
type Slugs []string
func (r *Recent) String() string {
submittedAt, err := time.Parse(time.RFC3339Nano, r.SubmittedAt)
if err != nil {
log.Fatal(err)
}
return fmt.Sprintf(" - %s (submitted on %s)", r.Problem, submittedAt.Format(dateFormat))
}
func (s *StatusInfo) String() string {
if len(*s.FetchedProblems) == 0 && s.Recent.Problem == "" {
return fmt.Sprintf("\nYou have yet to begin the %s track!\n", s.TrackID)
}
msg := `
Your status on the %s track:
Most recently submitted exercise:
%s
Exercises fetched but not submitted:
%s
Exercises skipped:
%s
`
return fmt.Sprintf(msg, s.TrackID, s.Recent, s.FetchedProblems, s.SkippedProblems)
}
func (s Slugs) String() string {
for i, problem := range s {
s[i] = fmt.Sprintf(" - %s", problem)
}
return strings.Join(s, "\n")
}