Esempio n. 1
0
func Index(env Env) (status Status, headers Headers, body Body) {

	viewData := &AdminCategoryViewData{
		CategoryInput: new(duoerlapi.CategoryInput),
		ApiCategories: services.GetCategories(),
	}

	mangotemplate.ForRender(env, "admin/categories", viewData)
	return
}
Esempio n. 2
0
func New(env Env) (status Status, headers Headers, body Body) {
	productInput := services.NewProduct()
	apiBrands, err := services.AllBrands()
	if err != nil {
		panic(err)
	}

	productViewData := &ProductViewData{
		ProductInput:  productInput,
		ApiBrands:     apiBrands,
		ApiCategories: services.GetCategories(),
	}

	mangotemplate.ForRender(env, "products/new", productViewData)
	return
}
Esempio n. 3
0
func Create(env Env) (status Status, headers Headers, body Body) {
	categoryInput := new(duoerlapi.CategoryInput)
	formdata.UnmarshalByNames(env.Request().Request, &categoryInput, categoryFields)

	viewData := &AdminCategoryViewData{
		CategoryInput: categoryInput,
		ApiCategories: services.GetCategories(),
	}

	_, err := services.CreateCategory(categoryInput)
	if validated, ok := err.(*govalidations.Validated); ok {
		viewData.Validated = validated
		mangotemplate.ForRender(env, "admin/categories", viewData)
		return
	}

	if err != nil {
		panic(err)
	}

	return Redirect(http.StatusFound, "/admin/categories")
}
Esempio n. 4
0
func Edit(env Env) (status Status, headers Headers, body Body) {

	productId := env.Request().URL.Query().Get(":id")

	productInput, err := services.EditProduct(productId)
	if err != nil {
		panic(err)
	}

	apiBrands, err := services.AllBrands()
	if err != nil {
		panic(err)
	}

	productViewData := &ProductViewData{
		ProductInput:  productInput,
		ApiBrands:     apiBrands,
		ApiCategories: services.GetCategories(),
	}

	mangotemplate.ForRender(env, "products/edit", productViewData)
	return
}