Updated config on backend
This commit is contained in:
parent
c3fdad6334
commit
1f20d9b45a
1 changed files with 84 additions and 37 deletions
121
backend/main.go
121
backend/main.go
|
|
@ -2,10 +2,12 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"ocbo-esign-backend/connections"
|
||||||
"ocbo-esign-backend/middleware"
|
"ocbo-esign-backend/middleware"
|
||||||
|
|
||||||
"github.com/gin-contrib/cors"
|
"github.com/gin-contrib/cors"
|
||||||
|
|
@ -14,14 +16,6 @@ import (
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DEV
|
|
||||||
// var connection string = "root:superuser@tcp(localhost:3306)/iips"
|
|
||||||
// var connectionPops string = "root:superuser@tcp(localhost:3306)/pops"
|
|
||||||
|
|
||||||
// SERVER
|
|
||||||
var connection string = "iips:iipsuser@tcp(192.168.7.100:3306)/iips"
|
|
||||||
var connectionPops string = "pops:Pops2023!@tcp(192.168.76.10:3306)/pops"
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := godotenv.Load()
|
err := godotenv.Load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -31,10 +25,53 @@ func main() {
|
||||||
connect()
|
connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
func connect() {
|
func getCORSConfig(env string) cors.Config {
|
||||||
db, err := sql.Open("mysql", connection)
|
switch env {
|
||||||
dbpop, err := sql.Open("mysql", connectionPops)
|
case "dev":
|
||||||
|
return cors.Config{
|
||||||
|
AllowOrigins: []string{"http://localhost:5173"},
|
||||||
|
AllowMethods: []string{"GET", "POST"},
|
||||||
|
AllowHeaders: []string{"Origin", "OCBO-Token", "Content-Length", "Content-Type"},
|
||||||
|
ExposeHeaders: []string{"Content-Length"},
|
||||||
|
AllowCredentials: true,
|
||||||
|
}
|
||||||
|
case "prod":
|
||||||
|
return cors.Config{
|
||||||
|
AllowOrigins: []string{"https://ocboapps.davaocity.gov.ph"},
|
||||||
|
AllowMethods: []string{"GET", "POST"},
|
||||||
|
AllowHeaders: []string{"Origin", "OCBO-Token", "Content-Length", "Content-Type"},
|
||||||
|
ExposeHeaders: []string{"Content-Length"},
|
||||||
|
AllowCredentials: true,
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return cors.DefaultConfig()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getConnectionStrings(env string) (string, string, error) {
|
||||||
|
switch env {
|
||||||
|
case "dev":
|
||||||
|
return connections.GetConnectionString(), connections.GetConnectionStringPops(), nil
|
||||||
|
case "prod":
|
||||||
|
return connections.GetConnectionStringServer(), connections.GetConnectionStringPopsServer(), nil
|
||||||
|
default:
|
||||||
|
return "", "", fmt.Errorf("unknown environment: %s", env)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func connect() {
|
||||||
|
env := os.Getenv("ENVIRONMENT")
|
||||||
|
|
||||||
|
conn, connPops, err := getConnectionStrings(env)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
db, err := sql.Open("mysql", conn)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
dbpop, err := sql.Open("mysql", connPops)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
@ -42,34 +79,15 @@ func connect() {
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
defer dbpop.Close()
|
defer dbpop.Close()
|
||||||
|
|
||||||
|
fmt.Println(env)
|
||||||
|
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
router.Use(cors.Default())
|
router.Use(cors.New(getCORSConfig(env)))
|
||||||
|
|
||||||
//DEV
|
|
||||||
// router.Use(cors.New(cors.Config{
|
|
||||||
// AllowOrigins: []string{"http://localhost:5173"},
|
|
||||||
// AllowMethods: []string{"GET", "POST"},
|
|
||||||
// AllowHeaders: []string{"Origin", "OCBO-Token"},
|
|
||||||
// ExposeHeaders: []string{"Content-Length"},
|
|
||||||
// AllowCredentials: true,
|
|
||||||
// }))
|
|
||||||
|
|
||||||
//SERVER
|
|
||||||
// router.Use(cors.New(cors.Config{
|
|
||||||
// //AllowAllOrigins: true,
|
|
||||||
// AllowOrigins: []string{"https://ocboapps.davaocity.gov.ph"},
|
|
||||||
// AllowMethods: []string{"GET", "POST"},
|
|
||||||
// AllowHeaders: []string{"Origin", "OCBO-Token"},
|
|
||||||
// ExposeHeaders: []string{"Content-Length"},
|
|
||||||
// AllowCredentials: true,
|
|
||||||
// }))
|
|
||||||
|
|
||||||
router.StaticFile("/", "static/index.html")
|
router.StaticFile("/", "static/index.html")
|
||||||
router.StaticFile("/esign.webp", "static/esign.webp")
|
router.StaticFile("/esign.webp", "static/esign.webp")
|
||||||
router.StaticFile("/favicon.ico", "static/favicon.ico")
|
router.StaticFile("/favicon.ico", "static/favicon.ico")
|
||||||
|
|
||||||
// shield := "inquiry"
|
|
||||||
|
|
||||||
router.GET("/api/:method", func(c *gin.Context) {
|
router.GET("/api/:method", func(c *gin.Context) {
|
||||||
var result string
|
var result string
|
||||||
method := c.Param("method")
|
method := c.Param("method")
|
||||||
|
|
@ -101,7 +119,7 @@ func connect() {
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{"result": true})
|
c.JSON(http.StatusOK, gin.H{"result": true})
|
||||||
|
|
||||||
case "get-listopapproval-occupancy":
|
case "get-listopapproval-building":
|
||||||
var result2 string
|
var result2 string
|
||||||
|
|
||||||
array := []string{}
|
array := []string{}
|
||||||
|
|
@ -130,6 +148,35 @@ func connect() {
|
||||||
"result2": array2,
|
"result2": array2,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
case "get-listopapproval-occupancy":
|
||||||
|
var result2 string
|
||||||
|
|
||||||
|
array := []string{}
|
||||||
|
array2 := []string{}
|
||||||
|
|
||||||
|
results, err := db.Query(`SELECT IFNULL(o.controlNo, '') AS result, IF(c.firstName IS NULL OR c.firstName = '', c.lastName, CONCAT(c.firstName, ' ', IF(c.middleInitial IS NULL OR c.middleInitial = '', '', CONCAT(c.middleInitial, '. ')), c.lastName) ) AS result2
|
||||||
|
FROM occupancy o JOIN customer c ON o.customerid = c.customerid JOIN occupancydocflowtxn od ON o.occupancyid = od.occupancyreceivingid JOIN (SELECT occupancyreceivingid, MAX(occupancydocflowtxnid) AS latest_occupancydocflowtxnid FROM occupancydocflowtxn GROUP BY occupancyreceivingid) latest_doc ON od.occupancyreceivingid = latest_doc.occupancyreceivingid AND od.occupancydocflowtxnid = latest_doc.latest_occupancydocflowtxnid
|
||||||
|
WHERE (remarks = "FOR OCCUPANCY RECOMMENDING APPROVAL" OR remarks = "FOR ADDITIONAL ORDER OF PAYMENT RECOMMENDING APPROVAL") AND od.is_approve = 0 ORDER BY od.txndate DESC`)
|
||||||
|
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-listopapproval-electrical":
|
case "get-listopapproval-electrical":
|
||||||
var result2 string
|
var result2 string
|
||||||
|
|
||||||
|
|
@ -861,7 +908,7 @@ func connect() {
|
||||||
array := []string{}
|
array := []string{}
|
||||||
array2 := []string{}
|
array2 := []string{}
|
||||||
array3 := []string{}
|
array3 := []string{}
|
||||||
array4 := []string{}
|
array4 := []string{}
|
||||||
|
|
||||||
results, err := db.Query(`SELECT IFNULL(ref.accountdescription, '') AS result, IFNULL(ref.accountcode, '') AS result2, IFNULL(op.amount, '') AS result3, IFNULL(op.numUnits, 0) AS result4
|
results, err := db.Query(`SELECT IFNULL(ref.accountdescription, '') AS result, IFNULL(ref.accountcode, '') AS result2, IFNULL(op.amount, '') AS result3, IFNULL(op.numUnits, 0) AS result4
|
||||||
FROM occupancy o JOIN building_orderofpayment op ON o.occupancyid = op.occupancyid JOIN ref_bldgcomputationsheet ref ON op.ref_bldgcomputationsheetid = ref.ref_bldgcomputationsheetid
|
FROM occupancy o JOIN building_orderofpayment op ON o.occupancyid = op.occupancyid JOIN ref_bldgcomputationsheet ref ON op.ref_bldgcomputationsheetid = ref.ref_bldgcomputationsheetid
|
||||||
|
|
@ -881,13 +928,13 @@ func connect() {
|
||||||
array = append(array, result)
|
array = append(array, result)
|
||||||
array2 = append(array2, result2)
|
array2 = append(array2, result2)
|
||||||
array3 = append(array3, result3)
|
array3 = append(array3, result3)
|
||||||
array4 = append(array4, result4)
|
array4 = append(array4, result4)
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"result": array,
|
"result": array,
|
||||||
"result2": array2,
|
"result2": array2,
|
||||||
"result3": array3,
|
"result3": array3,
|
||||||
"result4": array4,
|
"result4": array4,
|
||||||
})
|
})
|
||||||
|
|
||||||
case "get-printdetailsfees-electrical":
|
case "get-printdetailsfees-electrical":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue