Compare commits

...

3 Commits

2 changed files with 6 additions and 12 deletions

BIN
main

Binary file not shown.

18
main.go
View File

@@ -63,8 +63,7 @@ func login(c *gin.Context) {
// check for user using given credentials
stmt, err := db.Prepare("SELECT * FROM users WHERE name=?")
checkErr(err)
err = stmt.Close()
checkErr(err)
defer stmt.Close()
var user loginOutput
err = stmt.QueryRow(userData.Name).Scan(&user.UID, &user.Name, &user.Password, &user.Role)
if err != nil {
@@ -100,8 +99,7 @@ func getTasks(c *gin.Context) {
}
tasks = append(tasks, tempTask)
}
err = rows.Close()
checkErr(err)
rows.Close()
var jsonTasks taskArray
jsonTasks.Tasks = tasks
c.IndentedJSON(http.StatusOK, jsonTasks)
@@ -143,8 +141,7 @@ func getHistory(c *gin.Context) {
}
history = append(history, tempHistoryData)
}
err = rows.Close()
checkErr(err)
rows.Close()
var historyRes []historyResData
// make the data human-readable
@@ -154,22 +151,20 @@ func getHistory(c *gin.Context) {
var tempUser loginOutput
stmt, err := db.Prepare("SELECT * FROM users WHERE uid=?")
checkErr(err)
err = stmt.Close()
checkErr(err)
err = stmt.QueryRow(history[i].UID).Scan(&tempUser.UID, &tempUser.Name, &tempUser.Password, &tempUser.Role)
checkErr(err)
tempHistory.User = tempUser.Name
stmt.Close()
// get the task name and points
var tempTask task
stmt, err = db.Prepare("SELECT * FROM activities WHERE taskId=?")
checkErr(err)
err = stmt.Close()
checkErr(err)
err = stmt.QueryRow(history[i].TID).Scan(&tempTask.TID, &tempTask.Name, &tempTask.Points)
checkErr(err)
tempHistory.Task = tempTask.Name
tempHistory.PointsGained = tempTask.Points
stmt.Close()
tempHistory.Time = history[i].Time
@@ -221,8 +216,7 @@ func main() {
})
router.Static("/frontend", "./frontend")
err := router.Run("localhost:8080")
checkErr(err)
router.Run("localhost:8080")
}
func checkErr(err error) {