2021-12-21 10:18:12 +07:00
|
|
|
package codequest
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gunk/opt/http"
|
|
|
|
"github.com/gunk/opt/openapiv2"
|
|
|
|
"github.com/gunk/opt/proto"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type QuestService interface {
|
2022-04-28 23:31:09 +07:00
|
|
|
// 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.
|
|
|
|
//
|
2021-12-21 10:18:12 +07:00
|
|
|
// +gunk http.Match{
|
|
|
|
// Method: "GET",
|
|
|
|
// Path: "/v1/questions",
|
|
|
|
// }
|
2022-04-28 23:31:09 +07:00
|
|
|
Questions(QuestionsRequest) QuestionsResponse
|
2021-12-21 10:18:12 +07:00
|
|
|
|
2022-04-28 23:31:09 +07:00
|
|
|
// QuestionByID returns the question with the given ID.
|
|
|
|
//
|
2021-12-21 10:18:12 +07:00
|
|
|
// +gunk http.Match{
|
|
|
|
// Method: "GET",
|
|
|
|
// Path: "/v1/questions/{ID}",
|
|
|
|
// }
|
|
|
|
QuestionByID(QuestionByIDRequest) Question
|
|
|
|
|
2022-04-28 23:31:09 +07:00
|
|
|
// QuestionInput returns the question input for the given question.
|
|
|
|
// The input is the same for part 1 and part 2.
|
|
|
|
//
|
2021-12-21 10:18:12 +07:00
|
|
|
// +gunk http.Match{
|
|
|
|
// Method: "GET",
|
|
|
|
// Path: "/v1/questions/{ID}/input",
|
|
|
|
// }
|
|
|
|
QuestionInput(QuestionInputRequest) QuestionInput
|
|
|
|
|
2022-04-28 23:31:09 +07:00
|
|
|
// Submit submits the answer to the given question and part.
|
|
|
|
//
|
2021-12-21 10:18:12 +07:00
|
|
|
// +gunk http.Match{
|
|
|
|
// Method: "POST",
|
2022-04-28 23:31:09 +07:00
|
|
|
// Path: "/v1/questions/{ID}/{Part}",
|
2021-12-23 03:09:24 +07:00
|
|
|
// Body: "Body",
|
2021-12-21 10:18:12 +07:00
|
|
|
// }
|
|
|
|
Submit(SubmitRequest) SubmitResponse
|
2022-04-28 23:31:09 +07:00
|
|
|
|
|
|
|
// 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
|
2021-12-21 10:18:12 +07:00
|
|
|
}
|
|
|
|
|
2022-04-28 23:31:09 +07:00
|
|
|
type QuestionsRequest struct{}
|
|
|
|
|
|
|
|
type Difficulty int
|
|
|
|
|
|
|
|
const (
|
|
|
|
Level1 Difficulty = iota
|
|
|
|
Level2
|
|
|
|
)
|
|
|
|
|
2021-12-21 10:18:12 +07:00
|
|
|
type PartData struct {
|
2022-04-28 23:31:09 +07:00
|
|
|
Completed bool `pb:"1" json:"completed"`
|
|
|
|
PointsWorth int `pb:"2" json:"pointsWorth"`
|
2021-12-21 10:18:12 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
type Question struct {
|
2022-04-28 23:31:09 +07:00
|
|
|
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"`
|
2021-12-21 10:18:12 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2021-12-23 03:09:24 +07:00
|
|
|
type SubmitRequestData struct {
|
|
|
|
Answer string `pb:"2" json:"answer"`
|
2021-12-21 10:18:12 +07:00
|
|
|
Code string `pb:"4" json:"code"`
|
|
|
|
}
|
|
|
|
|
2021-12-23 03:09:24 +07:00
|
|
|
type SubmitRequest struct {
|
|
|
|
ID string `pb:"1" json:"id"`
|
2022-04-28 23:31:09 +07:00
|
|
|
Part int `pb:"3" json:"part"`
|
|
|
|
Body SubmitRequestData `pb:"2" json:"Body"`
|
2021-12-23 03:09:24 +07:00
|
|
|
}
|
|
|
|
|
2021-12-21 10:18:12 +07:00
|
|
|
type SubmitResponse struct {
|
2021-12-23 03:09:24 +07:00
|
|
|
Correct bool `pb:"3" json:"correct"`
|
|
|
|
Points int `pb:"5" json:"points"`
|
2021-12-21 10:18:12 +07:00
|
|
|
}
|
2022-04-28 23:31:09 +07:00
|
|
|
|
|
|
|
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"`
|
|
|
|
}
|