Added delete method
This commit is contained in:
parent
72abd22fee
commit
c21f6ac308
1 changed files with 232 additions and 5 deletions
233
backend/main.go
233
backend/main.go
|
|
@ -31,7 +31,7 @@ func getCORSConfig(env string) cors.Config {
|
||||||
case "dev":
|
case "dev":
|
||||||
return cors.Config{
|
return cors.Config{
|
||||||
AllowOrigins: []string{"http://localhost:5173"},
|
AllowOrigins: []string{"http://localhost:5173"},
|
||||||
AllowMethods: []string{"GET", "POST", "OPTIONS"},
|
AllowMethods: []string{"GET", "POST", "OPTIONS", "DELETE"},
|
||||||
AllowHeaders: []string{"Origin", "OCBO-Token", "Content-Length", "Content-Type", "X-Server"},
|
AllowHeaders: []string{"Origin", "OCBO-Token", "Content-Length", "Content-Type", "X-Server"},
|
||||||
ExposeHeaders: []string{"Content-Length"},
|
ExposeHeaders: []string{"Content-Length"},
|
||||||
AllowCredentials: true,
|
AllowCredentials: true,
|
||||||
|
|
@ -39,7 +39,7 @@ func getCORSConfig(env string) cors.Config {
|
||||||
case "prod":
|
case "prod":
|
||||||
return cors.Config{
|
return cors.Config{
|
||||||
AllowOrigins: []string{"https://ocboapps.davaocity.gov.ph", "https://esign.patalcala.com"},
|
AllowOrigins: []string{"https://ocboapps.davaocity.gov.ph", "https://esign.patalcala.com"},
|
||||||
AllowMethods: []string{"GET", "POST", "OPTIONS"},
|
AllowMethods: []string{"GET", "POST", "OPTIONS", "DELETE"},
|
||||||
// AllowHeaders: []string{"Origin", "OCBO-Token", "Content-Length", "Content-Type", "X-Server", "Authorization"},
|
// AllowHeaders: []string{"Origin", "OCBO-Token", "Content-Length", "Content-Type", "X-Server", "Authorization"},
|
||||||
AllowHeaders: []string{"*"},
|
AllowHeaders: []string{"*"},
|
||||||
ExposeHeaders: []string{"Content-Length"},
|
ExposeHeaders: []string{"Content-Length"},
|
||||||
|
|
@ -1431,7 +1431,18 @@ func connect() {
|
||||||
})
|
})
|
||||||
|
|
||||||
case "check-popsrecord":
|
case "check-popsrecord":
|
||||||
err := dbpop.QueryRow("SELECT COUNT(OrderPayId) AS result FROM orderpaydetail WHERE oprefid = ?" , data).Scan(&result)
|
err := dbpop.QueryRow("SELECT COUNT(OrderPayId) AS result FROM orderpaydetail WHERE oprefid = ?", 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,
|
||||||
|
})
|
||||||
|
|
||||||
|
case "get-opdata-electrical":
|
||||||
|
err := db.QueryRow(`SELECT IFNULL(CONCAT(electricalid, '-', assessedbyid, '-', reviewedbyid, '-', SUM(ref_bldgcomputationsheetid), '-', SUM(amount)),'') AS result FROM electrical_orderofpayment_new WHERE electricalid = (SELECT electricalid FROM electrical WHERE electricalNo = ?)`, data).Scan(&result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusBadRequest, err)
|
c.AbortWithError(http.StatusBadRequest, err)
|
||||||
c.String(http.StatusBadRequest, err.Error())
|
c.String(http.StatusBadRequest, err.Error())
|
||||||
|
|
@ -2265,5 +2276,221 @@ func connect() {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.POST("/api/save-lockdata", middleware.TokenChecker(), func(c *gin.Context) {
|
||||||
|
type saveLockData struct {
|
||||||
|
Data string `json:"data"` //referenceNo
|
||||||
|
Data2 string `json:"data2"` //lock_data
|
||||||
|
}
|
||||||
|
var savelockData saveLockData
|
||||||
|
if err := c.ShouldBindJSON(&savelockData); 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")
|
||||||
|
c.Writer.Header().Set("Content-Security-Policy", "default-src 'self'; img-src 'self';")
|
||||||
|
c.Writer.Header().Set("X-Server", "OCBO Server")
|
||||||
|
|
||||||
|
dbpost, err := db.Prepare("INSERT INTO esign_lock (esign_lockid, ?, ?)")
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
c.String(http.StatusInternalServerError, "Internal Server Error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer dbpost.Close()
|
||||||
|
|
||||||
|
exec, err := dbpost.Exec(savelockData.Data, savelockData.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 Saving Lock Data")
|
||||||
|
} else {
|
||||||
|
c.String(http.StatusInternalServerError, "Failed on Saving Lock Data")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
router.DELETE("/api/delete-orderofpayment-electrical", middleware.TokenChecker(), func(c *gin.Context) {
|
||||||
|
type DeleteOP struct {
|
||||||
|
Data int `json:"data"`
|
||||||
|
}
|
||||||
|
var deleteOp DeleteOP
|
||||||
|
if err := c.ShouldBindJSON(&deleteOp); 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")
|
||||||
|
c.Writer.Header().Set("Content-Security-Policy", "default-src 'self'; img-src 'self';")
|
||||||
|
c.Writer.Header().Set("X-Server", "OCBO Server")
|
||||||
|
|
||||||
|
var isPaid int
|
||||||
|
checkErr := db.QueryRow("SELECT is_paid FROM electrical_orderofpayment_new WHERE electricalid = ?", deleteOp.Data).Scan(&isPaid)
|
||||||
|
if checkErr != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, checkErr)
|
||||||
|
c.String(http.StatusInternalServerError, "Internal Server Error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if isPaid == 1 {
|
||||||
|
c.String(http.StatusBadRequest, "Order of Payment has Already been Paid")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dbpost, err := db.Prepare("DELETE FROM electrical_orderofpayment_new WHERE electricalid = ? AND is_paid = 0")
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
c.String(http.StatusInternalServerError, "Internal Server Error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer dbpost.Close()
|
||||||
|
|
||||||
|
exec, err := dbpost.Exec(deleteOp.Data)
|
||||||
|
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 Deleting Order of Payment")
|
||||||
|
} else {
|
||||||
|
c.String(http.StatusInternalServerError, "Failed on Deleting Order of Payment")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
router.DELETE("/api/delete-orderofpayment-occupancy", middleware.TokenChecker(), func(c *gin.Context) {
|
||||||
|
type DeleteOP struct {
|
||||||
|
Data int `json:"data"`
|
||||||
|
}
|
||||||
|
var deleteOp DeleteOP
|
||||||
|
if err := c.ShouldBindJSON(&deleteOp); 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")
|
||||||
|
c.Writer.Header().Set("Content-Security-Policy", "default-src 'self'; img-src 'self';")
|
||||||
|
c.Writer.Header().Set("X-Server", "OCBO Server")
|
||||||
|
|
||||||
|
var isPaid int
|
||||||
|
checkErr := db.QueryRow("SELECT is_paid FROM occupancy_orderofpayment WHERE occupancyid = ?", deleteOp.Data).Scan(&isPaid)
|
||||||
|
if checkErr != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, checkErr)
|
||||||
|
c.String(http.StatusInternalServerError, "Internal Server Error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if isPaid == 1 {
|
||||||
|
c.String(http.StatusBadRequest, "Order of Payment has Already been Paid")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dbpost, err := db.Prepare("DELETE FROM occupancy_orderofpayment WHERE occupancyid = ? AND is_paid = 0")
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
c.String(http.StatusInternalServerError, "Internal Server Error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer dbpost.Close()
|
||||||
|
|
||||||
|
exec, err := dbpost.Exec(deleteOp.Data)
|
||||||
|
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 Deleting Order of Payment")
|
||||||
|
} else {
|
||||||
|
c.String(http.StatusInternalServerError, "Failed on Deleting Order of Payment")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
router.DELETE("/api/void-op-local", middleware.TokenChecker(), func(c *gin.Context) {
|
||||||
|
type DeleteOPLocal struct {
|
||||||
|
Data int `json:"data"`
|
||||||
|
}
|
||||||
|
var deleteOpLocal DeleteOPLocal
|
||||||
|
if err := c.ShouldBindJSON(&deleteOpLocal); 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")
|
||||||
|
c.Writer.Header().Set("Content-Security-Policy", "default-src 'self'; img-src 'self';")
|
||||||
|
c.Writer.Header().Set("X-Server", "OCBO Server")
|
||||||
|
|
||||||
|
var isPaid int
|
||||||
|
checkErr := db.QueryRow("SELECT COUNT(AFNum) FROM orderpaydetails WHERE OPRefId = ?", deleteOpLocal.Data).Scan(&isPaid)
|
||||||
|
if checkErr != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, checkErr)
|
||||||
|
c.String(http.StatusInternalServerError, "Internal Server Error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if isPaid == 1 {
|
||||||
|
c.String(http.StatusBadRequest, "Error! Payment already exist.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
dbpost, err := db.Prepare("DELETE FROM orderpaydetails WHERE OPRefId = ?")
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
|
c.String(http.StatusInternalServerError, "Internal Server Error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer dbpost.Close()
|
||||||
|
|
||||||
|
exec, err := dbpost.Exec(deleteOpLocal.Data)
|
||||||
|
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 Deleting POPS Local")
|
||||||
|
} else {
|
||||||
|
c.String(http.StatusInternalServerError, "Failed on Deleting POPS Local")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
router.Run(":4320")
|
router.Run(":4320")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue