mdlutil

package
v0.10.5 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFieldNameFromModelByTagKey

func GetFieldNameFromModelByTagKey(modelObj interface{}, valueKey string) *string

GetFieldNameFromModelByTagKey get's the name of the tagged field If it's a slice, it returns the element type It's an interface{} because it's not necessarily IModel

func GetFieldTypeFromModelByTagKeyBetterRestAndValueKey

func GetFieldTypeFromModelByTagKeyBetterRestAndValueKey(modelObj mdl.IModel, valueKey string, recurseIntoEmbedded bool) reflect.Type

GetFieldTypeFromModelByTagKeyBetterRestAndValueKey fetches the datatype of the variable tagged in tag

func GetFieldValueFromModelByTagKeyBetterRestAndValueKey

func GetFieldValueFromModelByTagKeyBetterRestAndValueKey(modelObj mdl.IModel, valueKey string) interface{}

GetFieldValueFromModelByTagKeyBetterRestAndValueKey fetches value of the variable tagged in tag

func GetTagValueFromModelByTagKeyBetterRestAndValueKey

func GetTagValueFromModelByTagKeyBetterRestAndValueKey(modelObj interface{}, valueKey string) *string

Types

type HTTP

type HTTP struct {
	Endpoint string
	Op       rest.Op
}

HTTP stores HTTP request information

type IDoRealDelete

type IDoRealDelete interface {
	DoRealDelete() bool
}

IDoRealDelete is an interface to customize specification for real db delete

type IHasPermissions

type IHasPermissions interface {
	Permissions(role userrole.UserRole, who UserIDFetchable) (jsontrans.Permission, jsontrans.JSONFields)
}

IHasPermissions is for IModel with a custom permission field to cherry pick json fields default is to return all but the dates

type IOwnership

type IOwnership interface {
	GetRole() userrole.UserRole
	SetRole(userrole.UserRole)

	GetUserID() *datatype.UUID
	SetUserID(*datatype.UUID)

	GetModelID() *datatype.UUID
	SetModelID(*datatype.UUID)

	GetID() *datatype.UUID
	SetID(*datatype.UUID)
}

IOwnership is what OwnershipModelBase tables should satisfy. Except OwnershipType, that's for struct which embed OwnershipModelBase

type IValidate

type IValidate interface {
	Validate(who UserIDFetchable, http HTTP) error
}

IValidate supports validation with govalidator

type JSONIDPatch

type JSONIDPatch struct {
	ID    *datatype.UUID  `json:"id"`
	Patch json.RawMessage `json:"patch"` // json.RawMessage is actually just typedefed to []byte
}

JSONIDPatch is the stuff inside "content" for PatchMany operation

type OwnershipModelBase

type OwnershipModelBase struct {
	ID *datatype.UUID `gorm:"type:uuid;primary_key;" json:"id"`

	CreatedAt time.Time  `json:"createdAt"`
	UpdatedAt time.Time  `json:"updatedAt"`
	DeletedAt *time.Time `sql:"index" json:"deletedAt"`

	Role userrole.UserRole `json:"role"` // an int
}

OwnershipModelBase has a role. Intended to be embedded by table serving as link from resource to user

func (*OwnershipModelBase) BeforeCreate

func (o *OwnershipModelBase) BeforeCreate(scope *gorm.Scope) error

BeforeCreate sets a UUID if no ID is set (this is Gorm's hookpoint)

func (*OwnershipModelBase) GetID

func (o *OwnershipModelBase) GetID() *datatype.UUID

GetID Get the ID field of the model (useful when using interface)

func (*OwnershipModelBase) GetRole

func (o *OwnershipModelBase) GetRole() userrole.UserRole

GetRole gets the role field of the model, comforms to IOwnership

func (*OwnershipModelBase) SetID

func (o *OwnershipModelBase) SetID(id *datatype.UUID)

SetID Set the ID field of the model (useful when using interface)

func (*OwnershipModelBase) SetRole

func (o *OwnershipModelBase) SetRole(r userrole.UserRole)

SetRole sets the role field of the model, comforms to IOwnership

type OwnershipModelWithIDBase

type OwnershipModelWithIDBase struct {
	OwnershipModelBase

	UserID  *datatype.UUID `gorm:"index" json:"userID"` // I guess the user's table has to be named "User" then.
	ModelID *datatype.UUID `gorm:"index" json:"modelID"`
}

OwnershipModelWithIDBase is one with ID, if you don't need unique index for userID and modelID (if you don't expose the link table via LinkTableMapper) You can use this.

func (*OwnershipModelWithIDBase) GetCreatedAt

func (b *OwnershipModelWithIDBase) GetCreatedAt() *time.Time

GetCreatedAt gets the time stamp the record is created

func (*OwnershipModelWithIDBase) GetID

GetID Get the ID field of the model (useful when using interface)

func (*OwnershipModelWithIDBase) GetModelID

func (o *OwnershipModelWithIDBase) GetModelID() *datatype.UUID

GetModelID gets the id of the model, comforms to IOwnership

func (*OwnershipModelWithIDBase) GetUpdatedAt

func (b *OwnershipModelWithIDBase) GetUpdatedAt() *time.Time

GetUpdatedAt gets the time stamp the record is updated

func (*OwnershipModelWithIDBase) GetUserID

func (o *OwnershipModelWithIDBase) GetUserID() *datatype.UUID

GetUserID gets the user id of the model, comforms to IOwnership

func (*OwnershipModelWithIDBase) SetID

func (o *OwnershipModelWithIDBase) SetID(id *datatype.UUID)

SetID Set the ID field of the model (useful when using interface)

func (*OwnershipModelWithIDBase) SetModelID

func (o *OwnershipModelWithIDBase) SetModelID(id *datatype.UUID)

SetModelID sets the id of the model, comforms to IOwnership

func (*OwnershipModelWithIDBase) SetUserID

func (o *OwnershipModelWithIDBase) SetUserID(id *datatype.UUID)

SetUserID sets the user id of the model, comforms to IOwnership

type UserIDFetchable

type UserIDFetchable interface {
	GetUserID() *datatype.UUID
}

Jump to

Keyboard shortcuts

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