Rename types so they make sense

This commit is contained in:
2023-07-21 22:40:16 +01:00
parent 2aaa448331
commit fb9e3130e0

14
main.go
View File

@@ -108,7 +108,7 @@ func getTasks(c *gin.Context) {
func completeTask(c *gin.Context) {
// get the task data from the request
var completedTask historyReqData
var completedTask newHistoryData
if err := c.BindJSON(&completedTask); err != nil {
c.IndentedJSON(http.StatusBadRequest, completedTask)
return
@@ -129,12 +129,12 @@ func completeTask(c *gin.Context) {
func getHistory(c *gin.Context) {
// get the log of past points gained
var history []historyReqData
// get array of all historyReqData
var history []newHistoryData
// get array of all history Data
rows, err := db.Query("SELECT * FROM history")
checkErr(err)
for rows.Next() {
var tempHistoryData historyReqData
var tempHistoryData newHistoryData
err = rows.Scan(&tempHistoryData.UID, &tempHistoryData.TID, &tempHistoryData.Time, &tempHistoryData.PointsGained)
if err != nil {
c.IndentedJSON(http.StatusNotFound, history)
@@ -144,12 +144,12 @@ func getHistory(c *gin.Context) {
}
rows.Close()
var historyRes []historyResData
var historyRes []historyData
// make the data human-readable
for i := 0; i < len(history); i++ {
var tempHistory historyResData
var tempHistory historyData
// get the username
var tempUser loginOutput
var tempUser userData
stmt, err := db.Prepare("SELECT * FROM users WHERE uid=?")
checkErr(err)
err = stmt.QueryRow(history[i].UID).Scan(&tempUser.UID, &tempUser.Name, &tempUser.Password, &tempUser.Role)