From c80faad1c79ae75eb2acb95da66f041d713a8fff Mon Sep 17 00:00:00 2001 From: Patrick Alvin Alcala Date: Wed, 28 Jan 2026 10:56:15 +0800 Subject: [PATCH] Updated backend --- backend/main.go | 83 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 23 deletions(-) diff --git a/backend/main.go b/backend/main.go index 2c86178..491f66b 100644 --- a/backend/main.go +++ b/backend/main.go @@ -1333,32 +1333,69 @@ func connect() { "result": result, }) - // case "check-qr": - // var count int - // err := db.QueryRow("SELECT COUNT(esignid) AS result FROM esign WHERE SUBSTR(signature, 36) = ?", data).Scan(&count) - // if err != nil { - // c.AbortWithError(http.StatusBadRequest, err) - // c.String(http.StatusBadRequest, err.Error()) - // return - // } - // if count > 0 { - // err := db.QueryRow("SELECT IFNULL(e.employeename, '') AS result FROM esign es JOIN employee e ON es.employeeid = e.employeeid WHERE SUBSTR(signature, 36) = ?", data).Scan(&result) - // if err != nil { - // c.AbortWithError(http.StatusBadRequest, err) - // c.String(http.StatusBadRequest, err.Error()) - // return - // } + case "check-qr": + var count int + err := db.QueryRow("SELECT COUNT(esignid) AS result FROM esign WHERE SUBSTR(signature, 36) = ?", data).Scan(&count) + if err != nil { + c.AbortWithError(http.StatusBadRequest, err) + c.String(http.StatusBadRequest, err.Error()) + return + } + if count > 0 { + err := db.QueryRow("SELECT IFNULL(e.employeename, '') AS result FROM esign es JOIN employee e ON es.employeeid = e.employeeid WHERE SUBSTR(signature, 36) = ?", data).Scan(&result) + if err != nil { + c.AbortWithError(http.StatusBadRequest, err) + c.String(http.StatusBadRequest, err.Error()) + return + } - // c.JSON(http.StatusOK, gin.H{ - // "result": result, - // }) - // } else { - // c.JSON(http.StatusBadRequest, gin.H{ - // "result": count, - // }) - // } + c.JSON(http.StatusOK, gin.H{ + "result": result, + }) + } else { + c.JSON(http.StatusBadRequest, gin.H{ + "result": count, + }) + } + case "get-transactions": + var result2 string + array := []string{} + array2 := []string{} + + results, err := db.Query(`SELECT IFNULL(referenceNo, '') AS result, IFNULL(date_signed, '') AS result2 FROM esign_transactions WHERE esignid = (SELECT esignid FROM esign WHERE employeeid = (SELECT employeeid FROM employee WHERE employeename = ?))`, data) + if err != nil { + c.AbortWithError(http.StatusBadRequest, err) + c.String(http.StatusBadRequest, err.Error()) + return + } + for results.Next() { + err = results.Scan(&result, &result2) + if err != nil { + c.AbortWithError(http.StatusBadRequest, err) + c.String(http.StatusBadRequest, err.Error()) + return + } + array = append(array, result) + array2 = append(array2, result2) + } + c.JSON(http.StatusOK, gin.H{ + "result": array, + "result2": array2, + }) + + case "get-transactions-count": + err := db.QueryRow(`SELECT COUNT(esign_transactionsid) AS result FROM esign_transactions WHERE esignid = (SELECT esignid FROM esign WHERE employeeid = (SELECT employeeid FROM employee WHERE employeename = ?))`, data).Scan(&result) + if err != nil { + c.AbortWithError(http.StatusBadRequest, err) + c.String(http.StatusBadRequest, err.Error()) + return + } + c.JSON(http.StatusOK, gin.H{ + "result": result, + }) } + }) router.GET("/api/:method/:data/:data2/fetch-data", func(c *gin.Context) {