示例#1
0
文件: api.go 项目: JasonSoft/MyGo
func deleteCollectionHandler(r render.Render, params martini.Params) {
	collectionId, _ := strconv.Atoi(params["collectionId"])
	collection := Collection{Id: collectionId, StoreId: aipOption.Store.Id}
	err := collection.delete()
	if err != nil {
		logError(err.Error())
		r.JSON(500, "error")
		return
	}
	r.Status(200)
}
示例#2
0
文件: api.go 项目: JasonSoft/MyGo
func updateCollectionHandler(r render.Render, collection Collection, params martini.Params) {
	collection.StoreId = aipOption.Store.Id
	err := collection.update()

	if err != nil {
		if appErr, ok := err.(*appError); ok {
			r.JSON(500, appErr.Error())
			return
		} else {
			logError(err.Error())
			r.JSON(500, "error")
			return
		}
	}
	r.Status(200)
}
示例#3
0
文件: api.go 项目: JasonSoft/MyGo
func createCollectionHandler(r render.Render, collection Collection) {
	collection.StoreId = aipOption.Store.Id

	err := collection.create()
	if err != nil {
		if appErr, ok := err.(*appError); ok {
			r.JSON(500, appErr.Error())
			return
		} else {
			logError(err.Error())
			r.JSON(500, "error")
			return
		}
	}

	location := fmt.Sprintf("/api/v1/collections/%d", collection.Id)
	r.Header().Add("location", location)
	r.Status(201)
}
示例#4
0
文件: api.go 项目: JasonSoft/MyGo
func getCollectionsHandler(r render.Render) {
	collections, err := GetCollections(aipOption.Store.Id)
	if err != nil {
		if appErr, ok := err.(*appError); ok {
			r.JSON(500, appErr.Error())
			return
		} else {
			r.JSON(500, "error")
			return
		}
	}
	if collections == nil {
		r.Status(200)
		return
	}
	for i := range collections {
		collection := &collections[i]
		collection.toJsonForm()
	}
	r.JSON(200, collections)
}