category

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ApiDelete = Router.
	GET("/api/delete/%s").
	WithArgs(PathArgs.ID).
	Do(func(m *model, req *wc.Request) (wc.Content, error) {
		var id int
		err := req.Scan(&id)

		if err != nil {
			return nil, err
		}

		m.DeleteCategory(id)
		return nil, wc.Redirect(HtmlList.URL())
	})
View Source
var ApiList = Router.
	GET("/api/list/").
	WithArgs(QueryArgs.OrderBy, HeaderArgs.MyTest, CookieArgs.ATest).
	Do(func(m *model, req *wc.Request) (wc.Content, error) {
		var (
			orderby      string
			mytestheader string
			cookietest   string
		)
		err := req.Scan(&orderby, &mytestheader, &cookietest)

		if err != nil {
			fmt.Printf("error: %s\n", err)
			return nil, err
		}

		fmt.Printf("got my testheader: %q\n", mytestheader)
		fmt.Printf("got my cookie: %q\n", cookietest)

		var count, limit, page int
		err = req.GetPaginationHeader(&count, &limit, &page)

		if err == nil {
			fmt.Printf("got pagination header: count: %v limit: %v page: %v\n", count, limit, page)
		}

		return wc.NewJSON(m.Categories), nil
	})
View Source
var ApiPatch = Router.
	PATCH("/api/patch/%s").
	WithArgs(PathArgs.ID).
	Do(func(m *model, req *wc.Request) (wc.Content, error) {

		var id int

		err := req.Scan(&id)
		if err != nil {
			return nil, err
		}

		if m.FindCategory(id) == nil {
			return nil, wc.ErrNotFound
		}

		var cat Category

		err = req.BodyAsJSON(&cat)
		if err != nil {
			return nil, err
		}

		cat.ID = id

		m.DeleteCategory(id)
		m.AddCategory(cat)

		return nil, wc.StatusOK
	})
View Source
var ApiPut = Router.
	PUT("/api/put/").
	Do(func(m *model, req *wc.Request) (wc.Content, error) {
		var cat Category

		err := req.BodyAsJSON(&cat)
		if err != nil {
			return nil, err
		}

		m.AddCategory(cat)

		return nil, wc.StatusOK
	})
View Source
var CookieArgs = struct {
	ATest wc.CookieArg
}{
	wc.NewCookieArg("atest"),
}
View Source
var HeaderArgs = struct {
	MyTest wc.HeaderArg
}{
	wc.NewHeaderArg("X-Mytest"),
}
View Source
var HtmlEdit = Router.
	GET("/html/edit/%s").
	WithArgs(PathArgs.ID, QueryArgs.Limit, QueryArgs.OrderBy, QueryArgs.Page).
	Do(func(m *model, req *wc.Request) (wc.Content, error) {
		var id int
		var (
			limit   int
			orderby string
			page    int
		)

		err := req.Scan(&id, &limit, &orderby, &page)

		if err != nil {
			return nil, err
		}

		var catNew Category
		catNew.Name = fmt.Sprintf("neu per put %v", rand.Int())

		var json = &wc.JSON{catNew}
		var bf bytes.Buffer
		err = json.WriteTo(&bf)

		if err != nil {
			return nil, err
		}

		_, err = ApiPut.Call(json)

		if err != nil {
			fmt.Printf("could call new: %s\n", err.Error())
			return nil, err
		}

		cat := m.FindCategory(id)

		if cat == nil {
			return nil, fmt.Errorf("not found")
		}

		args := fmt.Sprintf("limit: %v, orderby: %q, page: %v", limit, orderby, page)

		return DIV(
			DIV(args),
			TABLE(TR(TD(fmt.Sprintf("%v", cat.ID)), TD(cat.Name))),
			AHref(
				HtmlList.URL(QueryArgs.Limit.Value(12)),
				"zur Liste",
			),
		).Html(), nil
	})
View Source
var HtmlList = Router.
	GET("/html/list/").
	WithArgs(QueryArgs.Limit, QueryArgs.OrderBy, QueryArgs.Page)
View Source
var PathArgs = struct {
	ID wc.PathArg
}{
	wc.NewPathArg("id"),
}
View Source
var QueryArgs = struct {
	Limit   wc.QueryArgOpt
	OrderBy wc.QueryArgOpt
	Page    wc.QueryArgOpt
}{
	wc.NewQueryArgOpt("limit").Int(),
	wc.NewQueryArgOpt("orderby").String(),
	wc.NewQueryArgOpt("page").Int(),
}
View Source
var Router = wc.New("Category", startModel, stopModel)

Functions

This section is empty.

Types

type Category

type Category struct {
	ID   int
	Name string
}

type Store added in v0.4.0

type Store struct {
	Categories []Category
	sync.RWMutex
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL