qa: Auto-solve OK requests

This commit is contained in:
nemunaire 2022-11-07 02:00:22 +01:00
parent 8758effc99
commit 67f129ce4c
3 changed files with 8 additions and 5 deletions

View file

@ -63,7 +63,7 @@ func importExerciceQA(c *gin.Context) {
return return
} }
if qa, err := exercice.NewQAQuery(uq.Subject, uq.IdTeam, uq.User, uq.State); err != nil { if qa, err := exercice.NewQAQuery(uq.Subject, uq.IdTeam, uq.User, uq.State, nil); err != nil {
log.Println("Unable to importExerciceQA:", err.Error()) log.Println("Unable to importExerciceQA:", err.Error())
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs during query creation."}) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{"errmsg": "An error occurs during query creation."})
return return

View file

@ -93,13 +93,13 @@ func (e *Exercice) GetQAQuery(id int64) (q *QAQuery, err error) {
} }
// NewQAQuery creates and fills a new struct QAQuery and registers it into the database. // NewQAQuery creates and fills a new struct QAQuery and registers it into the database.
func (e *Exercice) NewQAQuery(subject string, teamId *int64, user string, state string) (*QAQuery, error) { func (e *Exercice) NewQAQuery(subject string, teamId *int64, user string, state string, solved *time.Time) (*QAQuery, error) {
if res, err := DBExec("INSERT INTO exercices_qa (id_exercice, id_team, authuser, creation, state, subject) VALUES (?, ?, ?, ?, ?, ?)", e.Id, teamId, user, time.Now(), state, subject); err != nil { if res, err := DBExec("INSERT INTO exercices_qa (id_exercice, id_team, authuser, creation, state, subject, solved) VALUES (?, ?, ?, ?, ?, ?, ?)", e.Id, teamId, user, time.Now(), state, subject, solved); err != nil {
return nil, err return nil, err
} else if qid, err := res.LastInsertId(); err != nil { } else if qid, err := res.LastInsertId(); err != nil {
return nil, err return nil, err
} else { } else {
return &QAQuery{qid, e.Id, teamId, user, time.Now(), state, subject, nil, nil}, nil return &QAQuery{qid, e.Id, teamId, user, time.Now(), state, subject, solved, nil}, nil
} }
} }

View file

@ -5,6 +5,7 @@ import (
"log" "log"
"net/http" "net/http"
"strconv" "strconv"
"time"
"srs.epita.fr/fic-server/libfic" "srs.epita.fr/fic-server/libfic"
@ -105,7 +106,9 @@ func createExerciceQA(c *gin.Context) {
if len(uq.Subject) == 0 { if len(uq.Subject) == 0 {
if uq.State == "ok" { if uq.State == "ok" {
tmp := time.Now()
uq.Subject = "RAS" uq.Subject = "RAS"
uq.Solved = &tmp
} else { } else {
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Subject not filled"}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Subject not filled"})
return return
@ -113,7 +116,7 @@ func createExerciceQA(c *gin.Context) {
} }
exercice := c.MustGet("exercice").(*fic.Exercice) exercice := c.MustGet("exercice").(*fic.Exercice)
qa, err := exercice.NewQAQuery(uq.Subject, &teamid, ficteam, uq.State) qa, err := exercice.NewQAQuery(uq.Subject, &teamid, ficteam, uq.State, uq.Solved)
if err != nil { if err != nil {
log.Println("Unable to NewQAQuery: ", err.Error()) log.Println("Unable to NewQAQuery: ", err.Error())
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Unable to create the new QA query. Please retry."}) c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Unable to create the new QA query. Please retry."})