hackathon/api/v1/quest.gunk

125 lines
2.9 KiB
Go

package codequest
import (
"github.com/gunk/opt/http"
"github.com/gunk/opt/openapiv2"
"github.com/gunk/opt/proto"
"time"
)
type QuestService interface {
// Questions returns the list of available questions.
// Each question is also listed with whether it has been answered, and
// the points awarded for answering it correctly.
//
// The Text field will not be populated. To get the text, use QuestionByID.
//
// +gunk http.Match{
// Method: "GET",
// Path: "/v1/questions",
// }
Questions(QuestionsRequest) QuestionsResponse
// QuestionByID returns the question with the given ID.
//
// +gunk http.Match{
// Method: "GET",
// Path: "/v1/questions/{ID}",
// }
QuestionByID(QuestionByIDRequest) Question
// QuestionInput returns the question input for the given question.
// The input is the same for part 1 and part 2.
//
// +gunk http.Match{
// Method: "GET",
// Path: "/v1/questions/{ID}/input",
// }
QuestionInput(QuestionInputRequest) QuestionInput
// Submit submits the answer to the given question and part.
//
// +gunk http.Match{
// Method: "POST",
// Path: "/v1/questions/{ID}/{Part}",
// Body: "Body",
// }
Submit(SubmitRequest) SubmitResponse
// Leaderboard returns the global ranking of all participatants.
// The leaderboard is sorted by score, descending.
//
// +gunk http.Match{
// Method: "GET",
// Path: "/v1/questions/leaderboard",
// }
Leaderboard(LeaderboardRequest) LeaderboardResponse
}
type QuestionsRequest struct{}
type Difficulty int
const (
Level1 Difficulty = iota
Level2
)
type PartData struct {
Completed bool `pb:"1" json:"completed"`
PointsWorth int `pb:"2" json:"pointsWorth"`
}
type Question struct {
ID string `pb:"1" json:"id"`
Title string `pb:"2" json:"title"`
Text string `pb:"3" json:"text"`
Difficulty Difficulty `pb:"4" json:"difficulty"`
Part1 PartData `pb:"5" json:"part1"`
Part2 PartData `pb:"6" json:"part2"`
}
type QuestionsResponse struct {
Questions []Question `pb:"1" json:"questions"`
}
type QuestionByIDRequest struct {
ID string `pb:"1" json:"id"`
}
type QuestionInputRequest struct {
ID string `pb:"1" json:"id"`
}
type QuestionInput struct {
ID string `pb:"1" json:"id"`
Input string `pb:"2" json:"input"`
}
type SubmitRequestData struct {
Answer string `pb:"2" json:"answer"`
Code string `pb:"4" json:"code"`
}
type SubmitRequest struct {
ID string `pb:"1" json:"id"`
Part int `pb:"3" json:"part"`
Body SubmitRequestData `pb:"2" json:"Body"`
}
type SubmitResponse struct {
Correct bool `pb:"3" json:"correct"`
Points int `pb:"5" json:"points"`
}
type LeaderboardRequest struct{}
type LeaderboardResponse struct {
Leaderboard []LeaderboardEntry `pb:"1" json:"leaderboard"`
}
type LeaderboardEntry struct {
Username string `pb:"1" json:"username"`
Points int `pb:"2" json:"points"`
}