|
|
|
@ -234,47 +234,49 @@ func main() {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) {
|
|
|
|
ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) {
|
|
|
|
return []byte("TODO"), nil
|
|
|
|
return []byte("TODO"), nil
|
|
|
|
}})
|
|
|
|
}})
|
|
|
|
|
|
|
|
var jHdlr = jwt.Handler // make an alias so routes will be more readable
|
|
|
|
// Create or update schemas …
|
|
|
|
|
|
|
|
db.AutoMigrate(&User{})
|
|
|
|
// Create or update schemas …
|
|
|
|
db.AutoMigrate(&List{})
|
|
|
|
db.AutoMigrate(&User{})
|
|
|
|
db.AutoMigrate(&Item{})
|
|
|
|
db.AutoMigrate(&List{})
|
|
|
|
db.AutoMigrate(&Unit{})
|
|
|
|
db.AutoMigrate(&Item{})
|
|
|
|
db.Model(&User{}).Related(&List{})
|
|
|
|
db.AutoMigrate(&Unit{})
|
|
|
|
db.Model(&List{}).Related(&Item{})
|
|
|
|
db.Model(&User{}).Related(&List{})
|
|
|
|
db.Model(&Item{}).Related(&Unit{})
|
|
|
|
db.Model(&List{}).Related(&Item{})
|
|
|
|
defer db.Close()
|
|
|
|
db.Model(&Item{}).Related(&Unit{})
|
|
|
|
|
|
|
|
defer db.Close()
|
|
|
|
// define URL handlers
|
|
|
|
|
|
|
|
r := mux.NewRouter()
|
|
|
|
|
|
|
|
|
|
|
|
// define URL handlers
|
|
|
|
// User Management
|
|
|
|
r := mux.NewRouter()
|
|
|
|
r.Handle("/users", ehttp.HandlerFunc(register)).Methods("POST") // Make new user
|
|
|
|
|
|
|
|
r.Handle("/users", ehttp.HandlerFunc(getToken)).Methods("GET") // Get user „info“(=token)
|
|
|
|
// User Management
|
|
|
|
// TODO: delete, modify
|
|
|
|
r.Handle("/users", ehttp.HandlerFunc(register)).Methods("POST") // Make new user
|
|
|
|
|
|
|
|
r.Handle("/users", ehttp.HandlerFunc(getToken)).Methods("GET") // Get user „info“(=token)
|
|
|
|
// List Management
|
|
|
|
// TODO: delete, modify
|
|
|
|
r.Handle("/lists", jwt.Handler(ehttp.HandlerFunc(createList))).Methods("POST") // Make a new list
|
|
|
|
|
|
|
|
r.Handle("/lists", jwt.Handler(ehttp.HandlerFunc(nil))).Methods("GET") // Get list of lists
|
|
|
|
// List Management
|
|
|
|
r.Handle("/lists/{name}", jwt.Handler(ehttp.HandlerFunc(nil))).Methods("PUT") // Update list (name, icon, …)
|
|
|
|
r.Handle("/lists", jHdlr(ehttp.HandlerFunc(createList))).Methods("POST") // Make a new list
|
|
|
|
r.Handle("/lists/{name}", jwt.Handler(ehttp.HandlerFunc(nil))).Methods("DELETE") // Delete a list
|
|
|
|
r.Handle("/lists", jHdlr(ehttp.HandlerFunc(nil))).Methods("GET") // Get list of lists
|
|
|
|
r.Handle("/lists/{name}", jwt.Handler(ehttp.HandlerFunc(nil))).Methods("GET") // Get list content (i.e., items)
|
|
|
|
r.Handle("/lists/{name}", jHdlr(ehttp.HandlerFunc(nil))).Methods("PUT") // Update list (name, icon, …)
|
|
|
|
// List sharing
|
|
|
|
r.Handle("/lists/{name}", jHdlr(ehttp.HandlerFunc(nil))).Methods("DELETE") // Delete a list
|
|
|
|
r.Handle("/lists/{name}/sharers", jwt.Handler(ehttp.HandlerFunc(nil))).Methods("POST") // Add new sharer
|
|
|
|
r.Handle("/lists/{name}", jHdlr(ehttp.HandlerFunc(nil))).Methods("GET") // Get list content (i.e., items)
|
|
|
|
r.Handle("/lists/{name}/sharers", jwt.Handler(ehttp.HandlerFunc(nil))).Methods("GET") // Get list of sharers
|
|
|
|
// List sharing
|
|
|
|
r.Handle("/lists/{name}/sharers/{user}", jwt.Handler(ehttp.HandlerFunc(nil))).Methods("DELETE") // Remove sharer
|
|
|
|
r.Handle("/lists/{name}/sharers", jHdlr(ehttp.HandlerFunc(nil))).Methods("POST") // Add new sharer
|
|
|
|
|
|
|
|
r.Handle("/lists/{name}/sharers", jHdlr(ehttp.HandlerFunc(nil))).Methods("GET") // Get list of sharers
|
|
|
|
r.Handle("/lists/{name}/items", jwt.Handler(ehttp.HandlerFunc(nil))).Methods("PUT") // Add new item
|
|
|
|
r.Handle("/lists/{name}/sharers/{user}", jHdlr(ehttp.HandlerFunc(nil))).Methods("DELETE") // Remove sharer
|
|
|
|
r.Handle("/lists/{name}/items/{item}", jwt.Handler(ehttp.HandlerFunc(nil))).Methods("DELETE") // Delete item
|
|
|
|
|
|
|
|
r.Handle("/lists/{name}/items/{item}", jwt.Handler(ehttp.HandlerFunc(nil))).Methods("POST") // Update item
|
|
|
|
r.Handle("/lists/{name}/items", jHdlr(ehttp.HandlerFunc(nil))).Methods("PUT") // Add new item
|
|
|
|
|
|
|
|
r.Handle("/lists/{name}/items/{item}", jHdlr(ehttp.HandlerFunc(nil))).Methods("DELETE") // Delete item
|
|
|
|
// Unit-history (unit is a ever-growing list only used for auto-completion)
|
|
|
|
r.Handle("/lists/{name}/items/{item}", jHdlr(ehttp.HandlerFunc(nil))).Methods("POST") // Update item
|
|
|
|
r.Handle("/units", jwt.Handler(ehttp.HandlerFunc(nil))).Methods("POST") // Make a new unit
|
|
|
|
|
|
|
|
r.Handle("/units", jwt.Handler(ehttp.HandlerFunc(nil))).Methods("GET") // Get list of units
|
|
|
|
// Unit-history (unit is a ever-growing list only used for auto-completion)
|
|
|
|
|
|
|
|
r.Handle("/units", jHdlr(ehttp.HandlerFunc(nil))).Methods("POST") // Make a new unit
|
|
|
|
loggedRouter := handlers.LoggingHandler(os.Stdout, r)
|
|
|
|
r.Handle("/units", jHdlr(ehttp.HandlerFunc(nil))).Methods("GET") // Get list of units
|
|
|
|
http.Handle("/", loggedRouter)
|
|
|
|
|
|
|
|
http.ListenAndServe(":8000", nil)
|
|
|
|
loggedRouter := handlers.LoggingHandler(os.Stdout, r)
|
|
|
|
}
|
|
|
|
http.Handle("/", loggedRouter)
|
|
|
|
|
|
|
|
http.ListenAndServe(":8000", nil)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|