-
Notifications
You must be signed in to change notification settings - Fork 43
/
routes.go
84 lines (73 loc) · 2.35 KB
/
routes.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"net/http"
"github.com/jritsema/gotoolbox/web"
)
///////////////////////////////////////////////////////////
// UI Interactions
///////////////////////////////////////////////////////////
//
// Add -> GET /company/add/ -> company-add.html
// (target body with row-add.html and row.html)
//
// Save -> POST /company -> add, companies.html
// (target body without row-add.html)
//
// Cancel -> GET /company -> nothing, companies.html
//
// Edit -> GET /company/edit/{id} -> row-edit.html
// Save -> PUT /company/{id} -> update, row.html
// Cancel -> GET /company/{id} -> nothing, row.html
//
// Delete -> DELETE /company/{id} -> delete, companies.html
///////////////////////////////////////////////////////////
func index(r *http.Request) *web.Response {
return web.HTML(http.StatusOK, html, "index.html", data.companies, nil)
}
// GET /company/add
func addCompany(r *http.Request) *web.Response {
return web.HTML(http.StatusOK, html, "company-add.html", data.companies, nil)
}
// POST /company
func saveNewCompany(r *http.Request) *web.Response {
row := Company{}
r.ParseForm()
row.Company = r.Form.Get("company")
row.Contact = r.Form.Get("contact")
row.Country = r.Form.Get("country")
data.add(row)
return web.HTML(http.StatusOK, html, "companies.html", data.companies, nil)
}
// GET /company
func cancelSaveNewCompany(r *http.Request) *web.Response {
return web.HTML(http.StatusOK, html, "companies.html", data.companies, nil)
}
// /GET company/edit/{id}
func editCompany(r *http.Request) *web.Response {
id := r.PathValue("id")
row := data.getByID(id)
return web.HTML(http.StatusOK, html, "row-edit.html", row, nil)
}
// PUT /company/{id}
func saveExistingCompany(r *http.Request) *web.Response {
id := r.PathValue("id")
row := data.getByID(id)
r.ParseForm()
row.Company = r.Form.Get("company")
row.Contact = r.Form.Get("contact")
row.Country = r.Form.Get("country")
data.update(row)
return web.HTML(http.StatusOK, html, "row.html", row, nil)
}
// GET /company/{id}
func cancelSaveExistingCompany(r *http.Request) *web.Response {
id := r.PathValue("id")
row := data.getByID(id)
return web.HTML(http.StatusOK, html, "row.html", row, nil)
}
// DELETE /company/{id}
func deleteCompany(r *http.Request) *web.Response {
id := r.PathValue("id")
data.delete(id)
return web.HTML(http.StatusOK, html, "companies.html", data.companies, nil)
}