api

package
v0.0.0-...-7bac878 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCountFunc = func(r *http.Request, req *gorm.DB) (int64, map[string]interface{}, error) {
	resp := utils.Message(true, "data returned")
	count := int64(0)

	req.Count(&count)
	return count, resp, nil
}
View Source
var DefaultQueryFilteringFunc = func(r *http.Request, req *gorm.DB, key string, value []string) *gorm.DB {

	switch key {

	default:
		req = req.Where(key+" IN (?)", value)
	}
	return req
}

Add some specific filtering stuff depending on object fields

Functions

func CrudRoutes

func CrudRoutes(models Validation,
	freq func(r *http.Request, req *gorm.DB) *gorm.DB, getallrights utils.RightBits,
	getfunc func(r *http.Request, data interface{}) bool, getrights utils.RightBits,
	crefunc func(r *http.Request, data interface{}) bool, crerights utils.RightBits,
	updfunc func(r *http.Request, data interface{}, data2 interface{}) bool, updrights utils.RightBits,
	delfunc func(r *http.Request, data interface{}) bool, delrights utils.RightBits) utils.Routes

CrudRoutes Generate default CRUD route for object

func CrudRoutesSpecificURL

func CrudRoutesSpecificURL(models Validation,
	freq func(r *http.Request, req *gorm.DB) *gorm.DB, getallrights utils.RightBits,
	getfunc func(r *http.Request, data interface{}) bool, getrights utils.RightBits,
	crefunc func(r *http.Request, data interface{}) bool, crerights utils.RightBits,
	updfunc func(r *http.Request, data interface{}, data2 interface{}) bool, updrights utils.RightBits,
	delfunc func(r *http.Request, data interface{}) bool, delrights utils.RightBits, url string) utils.Routes

CrudRoutesSpecificURL Generate default CRUD route for object with specific url

func DefaultQueryAll

func DefaultQueryAll(r *http.Request, req *gorm.DB) *gorm.DB

DefaultQueryAll default request for GetAll

func DefaultRightAccess

func DefaultRightAccess(r *http.Request, data interface{}) bool

DefaultRightAccess return true right handler

func DefaultRightEdit

func DefaultRightEdit(r *http.Request, data interface{}, data2 interface{}) bool

DefaultRightEdit return true right handler

func DeleteAssociation

func DeleteAssociation(tx *gorm.DB, parent Validation, dataType Validation, associationName string, key string, fieldName string)

DeleteAssociation to remove association and data

func GenericCreate

func GenericCreate(w http.ResponseWriter, r *http.Request, data Validation, f ...func(r *http.Request, data interface{}) bool)

GenericCreate create a new object

func GenericDelete

func GenericDelete(w http.ResponseWriter, r *http.Request, data Validation, f func(r *http.Request, data interface{}) bool)

GenericDelete default deleter for controller

func GenericGet

func GenericGet(w http.ResponseWriter, r *http.Request, data Validation, f func(r *http.Request, data interface{}) bool)

GenericGet default controller for get

func GenericGetQueryAll

func GenericGetQueryAll(w http.ResponseWriter, r *http.Request, data Validation, freq func(r *http.Request, req *gorm.DB) *gorm.DB)

GenericGetQueryAll return all elements with filters

func GenericUpdate

func GenericUpdate(w http.ResponseWriter, r *http.Request, data Validation, f func(r *http.Request, data interface{}, data2 interface{}) bool)

GenericUpdate default updater for controller

func GetAllFromDb

func GetAllFromDb(r *http.Request) (int, int, string)

GetAllFromDb return paginated database : offset, page size, order column

func GetDB

func GetDB() *gorm.DB

GetDB return the actual DB used

func GetFromID

func GetFromID(r *http.Request, data Validation, preloads ...string) error

GetFromID Return object from Id

func GetQuery

func GetQuery(r *http.Request, req *gorm.DB, columns map[string]string) *gorm.DB

GetQuery add url query to gormrequest

func SetDB

func SetDB(initDB *gorm.DB)

SetDB to initialize the DB for the API

Types

type Authed

type Authed interface {
	SetUserEmitter(userID uint)
}

Authed implement an element to set the id

type HistoryAble

type HistoryAble interface {
	GetHistoryFields() map[string]string
	SetHistory([]map[string]interface{})
}

HistoryAble to store history on implementing objects

type Validation

type Validation interface {
	TableName() string
	Validate() (map[string]interface{}, bool)
	OrderColumns() []string
	FilterColumns() map[string]string
	FindFromRequest(r *http.Request) error
	QueryAllFromRequest(r *http.Request, q *gorm.DB) *gorm.DB
}

Validation interface to validate stuff

Jump to

Keyboard shortcuts

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