listeps

package
v0.0.0-...-07f0968 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Eps = []*app.Endpoint{
		{
			Description:  "Create a new list",
			Path:         (&list.Create{}).Path(),
			Timeout:      500,
			MaxBodyBytes: app.KB,
			IsPrivate:    false,
			GetDefaultArgs: func() interface{} {
				return &list.Create{}
			},
			GetExampleArgs: func() interface{} {
				return &list.Create{
					Name: "My List",
				}
			},
			GetExampleResponse: func() interface{} {
				return exampleList
			},
			Handler: func(tlbx app.Tlbx, a interface{}) interface{} {
				args := a.(*list.Create)
				validate.Str("name", args.Name, nameMinLen, nameMaxLen)
				me := me.AuthedGet(tlbx)
				srv := service.Get(tlbx)
				res := &list.List{
					ID:                 tlbx.NewID(),
					CreatedOn:          NowMilli(),
					Name:               args.Name,
					TodoItemCount:      0,
					CompletedItemCount: 0,
				}
				srv.Data().MustExec(qryListInsert(),
					me, res.ID, res.CreatedOn, res.Name, res.TodoItemCount, res.CompletedItemCount)
				return res
			},
		},
		{
			Description:  "Get a list set",
			Path:         (&list.Get{}).Path(),
			Timeout:      500,
			MaxBodyBytes: app.KB,
			IsPrivate:    false,
			GetDefaultArgs: func() interface{} {
				return &list.Get{
					Base: FilterDefs(),
				}
			},
			GetExampleArgs: func() interface{} {
				return &list.Get{
					NamePrefix:            ptr.String("My L"),
					CreatedOnMin:          ptr.Time(app.ExampleTime()),
					CreatedOnMax:          ptr.Time(app.ExampleTime()),
					TodoItemCountMin:      ptr.Int(2),
					TodoItemCountMax:      ptr.Int(5),
					CompletedItemCountMin: ptr.Int(3),
					CompletedItemCountMax: ptr.Int(4),
					Base: filter.Base{
						After: ptr.ID(app.ExampleID()),
						Sort:  list.SortName,
						Asc:   ptr.Bool(true),
						Limit: 50,
					},
				}
			},
			GetExampleResponse: func() interface{} {
				return &list.GetRes{
					Set: []*list.List{
						exampleList,
					},
					More: true,
				}
			},
			Handler: func(tlbx app.Tlbx, a interface{}) interface{} {
				return getSet(tlbx, a.(*list.Get))
			},
		},
		{
			Description:  "Update a list",
			Path:         (&list.Update{}).Path(),
			Timeout:      500,
			MaxBodyBytes: app.KB,
			IsPrivate:    false,
			GetDefaultArgs: func() interface{} {
				return &list.Update{}
			},
			GetExampleArgs: func() interface{} {
				return &list.Update{
					ID:   app.ExampleID(),
					Name: field.String{V: "New List Name"},
				}
			},
			GetExampleResponse: func() interface{} {
				return exampleList
			},
			Handler: func(tlbx app.Tlbx, a interface{}) interface{} {
				args := a.(*list.Update)
				validate.Str("name", args.Name.V, nameMinLen, nameMaxLen)
				getSetRes := getSet(tlbx, &list.Get{
					Base: filter.Base{
						IDs: IDs{args.ID},
					},
				})
				app.ReturnIf(len(getSetRes.Set) == 0, http.StatusNotFound, "no list with that id")
				list := getSetRes.Set[0]
				list.Name = args.Name.V
				srv := service.Get(tlbx)
				srv.Data().MustExec(qryListUpdate(), list.Name, me.AuthedGet(tlbx), list.ID)
				return list
			},
		},
		{
			Description:  "Delete lists",
			Path:         (&list.Delete{}).Path(),
			Timeout:      500,
			MaxBodyBytes: app.KB,
			IsPrivate:    false,
			GetDefaultArgs: func() interface{} {
				return &list.Delete{}
			},
			GetExampleArgs: func() interface{} {
				return &list.Delete{
					IDs: []ID{app.ExampleID()},
				}
			},
			GetExampleResponse: func() interface{} {
				return nil
			},
			Handler: func(tlbx app.Tlbx, a interface{}) interface{} {
				args := a.(*list.Delete)
				idsLen := len(args.IDs)
				if idsLen == 0 {
					return nil
				}
				validate.MaxIDs("ids", args.IDs, 100)
				me := me.AuthedGet(tlbx)
				srv := service.Get(tlbx)
				queryArgs := make([]interface{}, 0, idsLen+1)
				queryArgs = append(queryArgs, me)
				queryArgs = append(queryArgs, args.IDs.ToIs()...)
				tx := srv.Data().BeginWrite()
				defer tx.Rollback()

				tx.MustExec(qryListsDelete(idsLen), queryArgs...)
				tx.Commit()
				return nil
			},
		},
	}
)

Functions

func FilterDefs

func FilterDefs() filter.Base

func OnDelete

func OnDelete(tlbx app.Tlbx, me ID)

Types

This section is empty.

Jump to

Keyboard shortcuts

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