Beispiel #1
0
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)
}
Beispiel #2
0
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)
}
Beispiel #3
0
func displayPage(r render.Render, myStore *Store, pageName string) {

	var page *Page

	for _, value := range *myStore.pages {
		if value.Name == pageName {
			page = &value
			break
		}
	}

	if page != nil {
		context := TemplateContext{Page: page, Store: myStore}
		r.HTML(200, page.TemplateName, context)
	}
}
Beispiel #4
0
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)
}
Beispiel #5
0
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)
}
Beispiel #6
0
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)
}
Beispiel #7
0
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)
}
Beispiel #8
0
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)
}
Beispiel #9
0
func getPageHandler(req *http.Request, r render.Render, params martini.Params) {
	pages := getPages(aipOption.Store.Id)
	r.JSON(200, pages)
}
Beispiel #10
0
func getThemesHandler(r render.Render) {
	themes := getThemes(aipOption.Store.Id)
	r.JSON(200, themes)
}