-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcreate.go
45 lines (40 loc) · 1.02 KB
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package controllers
import (
"encoding/json"
"net/http"
)
type Car struct {
Make string `json:"make"`
Model string `json:"model"`
Colour string `json:"colour"`
Owner string `json:"owner"`
}
func (app *Application) CreateHandler(w http.ResponseWriter, r *http.Request) {
data := &struct {
TransactionId string
Success bool
Response bool
}{
TransactionId: "",
Success: false,
Response: false,
}
if r.FormValue("submitted") == "true" {
/* Form Data */
carData := Car{}
carKey := r.FormValue("carKey")
carData.Make = r.FormValue("carMake")
carData.Model = r.FormValue("carModel")
carData.Colour = r.FormValue("carColor")
carData.Owner = r.FormValue("carOwner")
RequestData, _ := json.Marshal(carData)
txid, err := app.Fabric.CreateCar(carKey, string(RequestData))
if err != nil {
http.Error(w, "Unable to create record in the blockchain", 500)
}
data.TransactionId = txid
data.Success = true
data.Response = true
}
renderTemplate(w, r, "create.html", data)
}