Compare commits
No commits in common. "1f20d9b45a8e7b6adc0cc7fae896391f0cd0d555" and "5e22d780822d322453698c3c339a2e5e87e785f4" have entirely different histories.
1f20d9b45a
...
5e22d78082
3 changed files with 37 additions and 107 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
FROM golang:1.25.4 AS build
|
FROM golang:1.25.3 AS build
|
||||||
ENV GIN_MODE=release
|
ENV GIN_MODE=release
|
||||||
ENV PORT=4320
|
ENV PORT=4320
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
package connections
|
|
||||||
|
|
||||||
var connectionString string = "root:superuser@tcp(localhost:3306)/iips"
|
|
||||||
var connectionStringPops string = "root:superuser@tcp(localhost:3306)/pops"
|
|
||||||
|
|
||||||
var connectionStringServer string = "iips:iipsuser@tcp(192.168.7.100:3306)/iips"
|
|
||||||
var connectionStringPopsServer string = "pops:Pops2023!@tcp(192.168.76.10:3306)/pops"
|
|
||||||
|
|
||||||
func GetConnectionString() string {
|
|
||||||
return connectionString
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetConnectionStringPops() string {
|
|
||||||
return connectionStringPops
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetConnectionStringServer() string {
|
|
||||||
return connectionStringServer
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetConnectionStringPopsServer() string {
|
|
||||||
return connectionStringPopsServer
|
|
||||||
}
|
|
||||||
119
backend/main.go
119
backend/main.go
|
|
@ -2,12 +2,10 @@ 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"
|
||||||
|
|
@ -16,6 +14,14 @@ 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 {
|
||||||
|
|
@ -25,53 +31,10 @@ func main() {
|
||||||
connect()
|
connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCORSConfig(env string) cors.Config {
|
|
||||||
switch env {
|
|
||||||
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() {
|
func connect() {
|
||||||
env := os.Getenv("ENVIRONMENT")
|
db, err := sql.Open("mysql", connection)
|
||||||
|
dbpop, err := sql.Open("mysql", connectionPops)
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|
@ -79,15 +42,34 @@ 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.New(getCORSConfig(env)))
|
router.Use(cors.Default())
|
||||||
|
|
||||||
|
//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")
|
||||||
|
|
@ -119,35 +101,6 @@ func connect() {
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{"result": true})
|
c.JSON(http.StatusOK, gin.H{"result": true})
|
||||||
|
|
||||||
case "get-listopapproval-building":
|
|
||||||
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 ref_occupancy_type ot ON o.ref_occupancy_typeid = ot.ref_occupancy_typeid JOIN ref_occupancy ro ON ot.ref_occupancyid = ro.ref_occupancyid 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-occupancy":
|
case "get-listopapproval-occupancy":
|
||||||
var result2 string
|
var result2 string
|
||||||
|
|
||||||
|
|
@ -155,7 +108,7 @@ func connect() {
|
||||||
array2 := []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
|
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
|
FROM occupancy o JOIN customer c ON o.customerid = c.customerid JOIN ref_occupancy_type ot ON o.ref_occupancy_typeid = ot.ref_occupancy_typeid JOIN ref_occupancy ro ON ot.ref_occupancyid = ro.ref_occupancyid 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`)
|
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 {
|
if err != nil {
|
||||||
c.AbortWithError(http.StatusBadRequest, err)
|
c.AbortWithError(http.StatusBadRequest, err)
|
||||||
|
|
@ -908,7 +861,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
|
||||||
|
|
@ -928,13 +881,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