示例#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 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)
}
示例#3
0
文件: page.go 项目: JasonSoft/MyGo
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)
	}
}
示例#4
0
文件: api.go 项目: JasonSoft/MyGo
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)
}
示例#5
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)
}
示例#6
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)
}
示例#7
0
文件: api.go 项目: JasonSoft/MyGo
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)
}
示例#8
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)
}
示例#9
0
文件: api.go 项目: JasonSoft/MyGo
func getPageHandler(req *http.Request, r render.Render, params martini.Params) {
	pages := getPages(aipOption.Store.Id)
	r.JSON(200, pages)
}
示例#10
0
文件: api.go 项目: JasonSoft/MyGo
func getThemesHandler(r render.Render) {
	themes := getThemes(aipOption.Store.Id)
	r.JSON(200, themes)
}