43 lines
969 B
Go
43 lines
969 B
Go
![]() |
package main
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"io/ioutil"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
func newQuery(w http.ResponseWriter, req *http.Request) {
|
||
|
body, err := ioutil.ReadAll(req.Body)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
log.Println(string(body))
|
||
|
var query NewQuery
|
||
|
err = json.Unmarshal(body, &query)
|
||
|
if err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
|
||
|
tx, err := db.Begin()
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
defer tx.Rollback()
|
||
|
stmt, err := tx.Prepare("INSERT INTO queries (startdate, enddate, location, description, contactperson, contactno, email, status, questiondate) VALUES" +
|
||
|
"( $1, $2, $3, $4, $5, $6, $7, $8, $9);")
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
defer stmt.Close() // danger!
|
||
|
for i := 0; i < 1; i++ {
|
||
|
_, err = stmt.Exec(query.Startdate, query.Enddate, query.Location, query.Description, query.Contactperson, query.Contactno, query.Email, query.Status, query.Questiondate)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
}
|
||
|
err = tx.Commit()
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
}
|