frontend: add players possibility to report problems with exercices
This commit is contained in:
parent
32dc9c1a8c
commit
9186bbc229
13 changed files with 206 additions and 0 deletions
57
backend/issue.go
Normal file
57
backend/issue.go
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/binary"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
type IssueUpload struct {
|
||||
IdExercice int64 `json:"id_exercice"`
|
||||
Subject string `json:"subject"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
func treatIssue(pathname string, team fic.Team) {
|
||||
// Generate a unique identifier to follow the request in logs
|
||||
bid := make([]byte, 5)
|
||||
binary.LittleEndian.PutUint32(bid, rand.Uint32())
|
||||
id := "[" + base64.StdEncoding.EncodeToString(bid) + "]"
|
||||
log.Println(id, "New issue receive", pathname)
|
||||
|
||||
var issue IssueUpload
|
||||
|
||||
if cnt_raw, err := ioutil.ReadFile(pathname); err != nil {
|
||||
log.Printf("%s [ERR] %s\n", id, err)
|
||||
} else if err := json.Unmarshal(cnt_raw, &issue); err != nil {
|
||||
log.Printf("%s [ERR] %s\n", id, err)
|
||||
} else if len(issue.Subject) == 0 && len(issue.Description) == 0 {
|
||||
log.Printf("%s Empty issue: not treated.\n", id)
|
||||
} else if len(issue.Subject) == 0 {
|
||||
log.Printf("%s Issue with no subject: not treated.\n", id)
|
||||
} else {
|
||||
var exercice *fic.Exercice = nil
|
||||
if e, err := fic.GetExercice(issue.IdExercice); err == nil {
|
||||
exercice = &e
|
||||
}
|
||||
|
||||
if claim, err := fic.NewClaim(issue.Subject, &team, exercice, nil, "medium"); err != nil {
|
||||
log.Printf("%s [ERR] Unable to create new issue: %s\n", id, err)
|
||||
} else if len(issue.Description) > 0 {
|
||||
if _, err := claim.AddDescription(issue.Description, fic.ClaimAssignee{Id: 0}); err != nil {
|
||||
log.Printf("%s [WRN] Unable to add description to issue: %s\n", id, err)
|
||||
} else {
|
||||
log.Printf("%s [OOK] New issue created: id=%d\n", id, claim.Id)
|
||||
if err = os.Remove(pathname); err != nil {
|
||||
log.Printf("%s [ERR] %s\n", id, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -186,6 +186,8 @@ func treat(raw_path string) {
|
|||
switch spath[2] {
|
||||
case "name":
|
||||
treatRename(raw_path, team)
|
||||
case "issue":
|
||||
treatIssue(raw_path, team)
|
||||
case "hint":
|
||||
treatOpeningHint(raw_path, team)
|
||||
case "choices":
|
||||
|
|
|
|||
Reference in a new issue