From 4ea8fe21d47654423bdf719255a5aa053c381458 Mon Sep 17 00:00:00 2001 From: Patrick Alvin Alcala Date: Thu, 25 Sep 2025 12:34:10 +0800 Subject: [PATCH] Added two new apis --- backend/main.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/backend/main.go b/backend/main.go index b643734..4efbebc 100644 --- a/backend/main.go +++ b/backend/main.go @@ -157,6 +157,7 @@ func connect() { "result": array, "result2": array2, }) + } }) @@ -439,8 +440,60 @@ func connect() { c.JSON(http.StatusOK, gin.H{ "result": result, }) + + case "get-employeeid": + err := db.QueryRow("SELECT IFNULL(employeeid, 0) AS result FROM employee WHERE employeename = ?", data).Scan(&result) + if err != nil { + c.AbortWithError(http.StatusBadRequest, err) + c.String(http.StatusBadRequest, err.Error()) + } + c.JSON(http.StatusOK, gin.H{ + "result": result, + }) } }) + router.POST("/api/post-registration", func(c *gin.Context) { + type RegistrationData struct { + Data string `json:"data"` + Data2 string `json:"data2"` + } + var registrationData RegistrationData + if err := c.ShouldBindJSON(®istrationData); err != nil { + c.String(http.StatusBadRequest, "Invalid request body") + return + } + + c.Writer.Header().Set("X-XSS-Protection", "1; mode=block") + c.Writer.Header().Set("X-Content-Type-Options", "nosniff") + c.Writer.Header().Set("X-DNS-Prefetch-Control", "off") + c.Writer.Header().Set("X-Frame-Options", "DENY") + c.Writer.Header().Set("X-Download-Options", "noopen") + c.Writer.Header().Set("Referrer-Policy", "no-referrer") + + dbpost, err := db.Prepare("INSERT INTO esign (esignid, employeeid, signature) VALUES (NULL, ?, ?)") + if err != nil { + panic(err.Error()) + } + defer dbpost.Close() + + exec, err := dbpost.Exec(registrationData.Data, registrationData.Data2) + if err != nil { + panic(err.Error()) + } + + affect, err := exec.RowsAffected() + if err != nil { + panic(err.Error()) + } + + if affect > 0 { + c.String(http.StatusOK, "Success on Registrating e-Sign") + } else { + c.String(http.StatusInternalServerError, "Failed on Registrating e-Sign") + } + + }) + router.Run(":4320") }