wip1
This commit is contained in:
parent
977a75819d
commit
f25068075c
7 changed files with 113 additions and 22 deletions
28
api/tag.go
28
api/tag.go
|
@ -24,7 +24,23 @@ func init() {
|
|||
})))
|
||||
router.PUT("/api/tags/:tid", apiHandler(tagHandler(updateTag)))
|
||||
router.DELETE("/api/tags/:tid", apiHandler(tagHandler(func (tag ckh.Tag, _ []byte) (interface{}, error) {
|
||||
return tag.Delete()
|
||||
if _, err := tag.Delete(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return map[string]int{}, nil
|
||||
}
|
||||
})))
|
||||
|
||||
// Item's tags
|
||||
router.GET("/api/items/:iid/tags", apiHandler(itemHandler(func (item ckh.Item, _ []byte) (interface{}, error) {
|
||||
return item.GetTags()
|
||||
})))
|
||||
router.PUT("/api/items/:iid/tags/:tid", apiHandler(itemTagHandler(func (item ckh.Item, tag ckh.Tag, _ []byte) (interface{}, error) {
|
||||
_, err := tag.AddItem(item)
|
||||
return tag, err
|
||||
})))
|
||||
router.DELETE("/api/items/:iid/tags/:tid", apiHandler(itemTagHandler(func (item ckh.Item, tag ckh.Tag, _ []byte) (interface{}, error) {
|
||||
return tag.DeleteItem(item)
|
||||
})))
|
||||
}
|
||||
|
||||
|
@ -40,6 +56,16 @@ func tagHandler(f func(ckh.Tag, []byte) (interface{}, error)) func(httprouter.Pa
|
|||
}
|
||||
}
|
||||
|
||||
func itemTagHandler(f func(ckh.Item, ckh.Tag, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
|
||||
return func(ps httprouter.Params, body []byte) (interface{}, error) {
|
||||
return itemHandler(func (item ckh.Item, _ []byte) (interface{}, error) {
|
||||
return tagHandler(func (tag ckh.Tag, _ []byte) (interface{}, error) {
|
||||
return f(item, tag, body)
|
||||
})(ps, body)
|
||||
})(ps, body)
|
||||
}
|
||||
}
|
||||
|
||||
func newTag(_ httprouter.Params, body []byte) (interface{}, error) {
|
||||
var ut ckh.Tag
|
||||
if err := json.Unmarshal(body, &ut); err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue