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