New route to delete grades
This commit is contained in:
parent
6f9b83ef24
commit
706e786190
5 changed files with 107 additions and 5 deletions
16
grades.go
16
grades.go
|
@ -3,6 +3,7 @@ package main
|
|||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
@ -65,6 +66,21 @@ func declareAPIAuthGradesRoutes(router *gin.RouterGroup) {
|
|||
})
|
||||
}
|
||||
|
||||
func gradeHandler(c *gin.Context) {
|
||||
work := c.MustGet("work").(*Work)
|
||||
|
||||
if gid, err := strconv.Atoi(string(c.Param("gid"))); err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{"errmsg": "Bad grade identifier."})
|
||||
return
|
||||
} else if grade, err := work.GetGrade(int64(gid)); err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusNotFound, gin.H{"errmsg": "Grade not found."})
|
||||
return
|
||||
} else {
|
||||
c.Set("grade", grade)
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func GetAllGrades() (scores map[int64]map[int64]*float64, err error) {
|
||||
if rows, errr := DBQuery("SELECT id_user, id_survey, SUM(score)/COUNT(*) FROM student_scores GROUP BY id_user, id_survey"); errr != nil {
|
||||
return nil, errr
|
||||
|
|
Reference in a new issue