Adds points to user when action completed

This commit is contained in:
2023-07-21 23:02:59 +01:00
parent 0bdaac368c
commit 758c87652c

13
main.go
View File

@@ -133,6 +133,19 @@ func completeTask(c *gin.Context) {
c.IndentedJSON(http.StatusNotModified, completedTask) c.IndentedJSON(http.StatusNotModified, completedTask)
return return
} }
// add points to user table
stmt, err = db.Prepare("UPDATE users SET points = points + ? WHERE uid=?")
if err != nil {
c.IndentedJSON(http.StatusNotModified, completedTask)
return
}
_, err = stmt.Exec(completedTask.PointsGained, completedTask.UID)
if err != nil {
c.IndentedJSON(http.StatusNotModified, completedTask)
return
}
c.IndentedJSON(http.StatusOK, completedTask) c.IndentedJSON(http.StatusOK, completedTask)
} }