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 getProductHandler(req *http.Request, r render.Render, params martini.Params) { var productId string = params["productId"] link := LinkModel{Url: "http://abc"} var product = Product{} product.All = link if productId == "1" { links := [2]LinkModel{{Url: "Jaosn"}, {Url: "Hello"}} product.All = links } r.JSON(200, product) }
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 getTemplatesHandler(req *http.Request, r render.Render, params martini.Params) { themeName := req.URL.Query().Get("theme") if len(themeName) <= 0 { r.JSON(404, "theme parameter was missing") return } //ensure theme is valid targetTheme := aipOption.Store.getTheme(themeName) if targetTheme == nil { r.JSON(404, "theme was not found") return } templates := []Template{} for _, template := range *aipOption.Store.templates { if targetTheme.Id == template.ThemeId { templates = append(templates, template) } } r.JSON(200, templates) }
func getCollectionHandler(r render.Render, params martini.Params) { collectionId, err := strconv.Atoi(params["collectionId"]) if err != nil { r.JSON(500, "bad request") return } collection, err := GetCollection(aipOption.Store.Id, collectionId) if err != nil { r.JSON(500, "error") return } if collection == nil { r.JSON(404, "collection is not found") return } collection.toJsonForm() r.JSON(200, collection) }
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) }
func getPageHandler(req *http.Request, r render.Render, params martini.Params) { pages := getPages(aipOption.Store.Id) r.JSON(200, pages) }
func getThemesHandler(r render.Render) { themes := getThemes(aipOption.Store.Id) r.JSON(200, themes) }