Documentation
¶
Index ¶
- Variables
- func AddBatchDeleteBeforeAndAfterHookPoints(typeString string, ...)
- func AddBatchUpdateBeforeAndAfterHookPoints(typeString string, ...)
- func AddModelRegistry(typeString string, typ reflect.Type)
- type BaseModel
- type BatchHookCargo
- type Client
- type IAfterDelete
- type IAfterInsert
- type IAfterPatch
- type IAfterUpdate
- type IBeforeDelete
- type IBeforeInsert
- type IBeforePatch
- type IBeforeUpdate
- type IModel
- func NewFromTypeString(typeString string) IModel
- func NewSliceFromDB(typeString string, f func(interface{}, ...interface{}) *gorm.DB) ([]IModel, error)
- func NewSliceStructFromTypeString(typeString string) []IModel
- func NewSliceStructFromTypeStringAndJSON(typeString string, jsn []byte) ([]IModel, error)
- type IValidate
- type ModelCargo
- type Reg
- type UserRole
Constants ¶
This section is empty.
Variables ¶
var ModelRegistry = make(map[string]*Reg)
ModelRegistry is model registry
Functions ¶
func AddBatchDeleteBeforeAndAfterHookPoints ¶
func AddBatchDeleteBeforeAndAfterHookPoints(typeString string, before func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *BatchHookCargo) error, after func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *BatchHookCargo) error)
AddBatchDeleteBeforeAndAfterHookPoints adds hookpoints which are called before and after batch delete. Either one can be left as nil
func AddBatchUpdateBeforeAndAfterHookPoints ¶
func AddBatchUpdateBeforeAndAfterHookPoints(typeString string, before func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *BatchHookCargo) error, after func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *BatchHookCargo) error)
AddBatchUpdateBeforeAndAfterHookPoints adds hookpoints which are called before and after batch update. Either one can be left as nil
func AddModelRegistry ¶
AddModelRegistry adds a New function for an IModel
Types ¶
type BaseModel ¶
type BaseModel struct { ID *datatypes.UUID `gorm:"type:binary(16);primary_key;" json:"id"` CreatedAt time.Time `json:"createdAt"` UpdatedAt time.Time DeletedAt *time.Time `sql:"index"` }
BaseModel is the base class domain model which has standard ID
func (*BaseModel) BeforeCreate ¶
BeforeCreate sets a UUID if no ID is set (this is Gorm's hookpoint)
type BatchHookCargo ¶
type BatchHookCargo struct {
Payload interface{}
}
BatchHookCargo is payload between batch update and batch delete hookpoints
type Client ¶
type Client struct { gorm.Model // Includes ID, CreatedAt, UpdatedAt, DeletedAt Name string Secret string `gorm:"not null" json:"-"` RedirectURI string // TODO: RedirectURI can be multiples }
Client is the program that makes request to the API So iOS would be one client, android would be another Any website making API request would have its own client ID This needs to be inserted into db beforehand. So we can validate the app making the request. Any such app has the permission to create the user
type IAfterDelete ¶
type IAfterDelete interface {
AfterDeleteDB(db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *ModelCargo) error
}
IAfterDelete supports method to be called after data is deleted from the database
type IAfterInsert ¶
type IAfterInsert interface {
AfterInsertDB(db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *ModelCargo) error
}
IAfterInsert supports method to be called after data is inserted (created) into the database
type IAfterPatch ¶
type IAfterPatch interface {
AfterPatchDB(db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *ModelCargo) error
}
IAfterPatch supports method to be called before data is patched in the database
type IAfterUpdate ¶
type IAfterUpdate interface {
AfterUpdateDB(db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *ModelCargo) error
}
IAfterUpdate supports method to be called after data is updated in the database
type IBeforeDelete ¶
type IBeforeDelete interface {
BeforeDeleteDB(db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *ModelCargo) error
}
IBeforeDelete supports method to be called before data is deleted from the database
type IBeforeInsert ¶
type IBeforeInsert interface {
BeforeInsertDB(db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *ModelCargo) error
}
IBeforeInsert supports method to be called before data is inserted (created) into the database
type IBeforePatch ¶
type IBeforePatch interface {
BeforePatchDB(db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *ModelCargo) error
}
IBeforePatch supports method to be called before data is patched in the database
type IBeforeUpdate ¶
type IBeforeUpdate interface {
BeforeUpdateDB(db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *ModelCargo) error
}
IBeforeUpdate supports method to be called before data is updated in the database
type IModel ¶
type IModel interface { Permissions(r UserRole) jsontransform.JSONFields // The following two avoids having to use reflection to access ID GetID() *datatypes.UUID SetID(id *datatypes.UUID) }
IModel is the interface for all domain models
func NewFromTypeString ¶
NewFromTypeString instantiate a new IModel object from type registry
func NewSliceFromDB ¶
func NewSliceFromDB(typeString string, f func(interface{}, ...interface{}) *gorm.DB) ([]IModel, error)
NewSliceFromDB queries the database for an array of models
func NewSliceStructFromTypeString ¶
NewSliceStructFromTypeString : return something originally like this obj := make(map[string][]Room) obj["content"] = make([]Room, 0, 0) https://stackoverflow.com/questions/50233285/create-a-map-in-go-using-reflection func NewSliceStructFromTypeString(typeString string) map[string][]IModel {
type IValidate ¶
type IValidate interface {
Validate() error
}
IValidate supports validation with govalidator
type ModelCargo ¶
type ModelCargo struct {
Payload interface{}
}
ModelCargo is payload between hookpoints
type Reg ¶
type Reg struct { Typ reflect.Type BeforeUpdate func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *BatchHookCargo) error AfterUpdate func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *BatchHookCargo) error BeforeDelete func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *BatchHookCargo) error AfterDelete func(ms []IModel, db *gorm.DB, oid *datatypes.UUID, typeString string, cargo *BatchHookCargo) error }
Reg is a registry item