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) }
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) }
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) }
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) }