service

package
v0.10.8 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBatchUpdateOrPatchOneNotFound = errors.New("at least one not found")
View Source
var ErrIDEmpty = errors.New("cannot operate when ID is empty")
View Source
var ErrIDNotMatch = errors.New("cannot operate when ID in HTTP body and URL parameter not match")
View Source
var ErrPatch = errors.New("patch syntax error") // json: cannot unmarshal object into Go value of type jsonpatch.Patch
View Source
var ErrPermission = errors.New("permission denied")

Error

View Source
var ErrPermissionWrongEndPoint = errors.New("permission denied. Change it through the resource endpoint or unable to change your own role.")

Functions

func RecursivelyQueryAllPeggedModels added in v0.9.7

func RecursivelyQueryAllPeggedModels(db *gorm.DB, modelObjs []mdl.IModel, begin time.Time, end time.Time) error

It is assumed that modelObjs are all from the same table (same IModel) If there is a third-level, it is not performant because it's depth first right now Wow, this is really difficult.

Types

type BaseService

type BaseService struct {
}

BaseService is the superclass of all services

func (*BaseService) CreateOneCore

func (serv *BaseService) CreateOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel, id *datatype.UUID, oldModelObj mdl.IModel) (mdl.IModel, error)

CreateOneCore create the model

func (*BaseService) DeleteOneCore

func (serv *BaseService) DeleteOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel, id *datatype.UUID, oldModelObjs mdl.IModel) (mdl.IModel, error)

func (*BaseService) ReadOneCore added in v0.5.0

func (serv *BaseService) ReadOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, id *datatype.UUID, options map[urlparam.Param]interface{}) (mdl.IModel, userrole.UserRole, error)

func (*BaseService) UpdateOneCore

func (serv *BaseService) UpdateOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel, id *datatype.UUID, oldModelObj mdl.IModel) (modelObj2 mdl.IModel, err error)

UpdateOneCore one, permissin should already be checked called for patch operation as well (after patch has already applied) Fuck, repeat the following code for now (you can't call the overriding method from the non-overriding one)

type GlobalService

type GlobalService struct {
	BaseService
}

func (*GlobalService) GetAllQueryContructCore added in v0.3.4

func (serv *GlobalService) GetAllQueryContructCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string) (*gorm.DB, error)

GetAllQueryContructCore construct the meat of the query

func (*GlobalService) GetAllRolesCore added in v0.3.4

func (serv *GlobalService) GetAllRolesCore(dbChained *gorm.DB, dbClean *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]userrole.UserRole, error)

GetAllRolesCore gets all roles according to the criteria

func (*GlobalService) GetManyCore added in v0.5.0

func (service *GlobalService) GetManyCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, ids []*datatype.UUID, options map[urlparam.Param]interface{}) ([]mdl.IModel, []userrole.UserRole, error)

func (*GlobalService) HookBeforeDeleteMany

func (serv *GlobalService) HookBeforeDeleteMany(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]mdl.IModel, error)

func (*GlobalService) HookBeforeDeleteOne

func (serv *GlobalService) HookBeforeDeleteOne(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel) (mdl.IModel, error)

func (*GlobalService) PermissionAndRole added in v0.10.7

func (serv *GlobalService) PermissionAndRole(data *hook.Data, ep *hook.EndPoint) (*hook.Data, *webrender.RetError)

func (*GlobalService) ReadOneCore added in v0.5.0

func (service *GlobalService) ReadOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, id *datatype.UUID, options map[urlparam.Param]interface{}) (mdl.IModel, userrole.UserRole, error)

ReadOneCore get one model object based on its type and its id string

func (*GlobalService) UpdateOneCore

func (serv *GlobalService) UpdateOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel, id *datatype.UUID, oldModelObj mdl.IModel) (modelObj2 mdl.IModel, err error)

UpdateOneCore one, permissin should already be checked called for patch operation as well (after patch has already applied) Fuck, repeat the following code for now (you can't call the overriding method from the non-overriding one)

type IService

type IService interface {

	// HookBeforeCreateOne(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel) (mdl.IModel, error)
	// HookBeforeCreateMany(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]mdl.IModel, error)
	HookBeforeDeleteOne(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel) (mdl.IModel, error)
	HookBeforeDeleteMany(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]mdl.IModel, error)

	CreateOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel, id *datatype.UUID, oldModelObj mdl.IModel) (mdl.IModel, error)
	ReadOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, id *datatype.UUID, options map[urlparam.Param]interface{}) (mdl.IModel, userrole.UserRole, error)
	UpdateOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel, id *datatype.UUID, oldModelObj mdl.IModel) (modelObj2 mdl.IModel, err error)
	DeleteOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel, id *datatype.UUID, oldModelObjs mdl.IModel) (mdl.IModel, error)

	GetManyCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, ids []*datatype.UUID, options map[urlparam.Param]interface{}) ([]mdl.IModel, []userrole.UserRole, error)

	GetAllQueryContructCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string) (*gorm.DB, error)
	GetAllRolesCore(dbChained *gorm.DB, dbClean *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]userrole.UserRole, error)

	// Permitted is asking if this user has permission to add to it
	// 1. Ownership service: ask hook for permission, if the endpoint is allowed, then the role for the created item is admin
	// 2. Link service: If you're an admin or someone with permission to edit it (if hook allows it), then the role you can set is also restricted by the hook.
	// 3. Org/Org partition service(things under org): if you're admin or some permission which allows to write, determined by the hook, then the role
	// then no new role is needed
	// 4. User/Global: Either you have permission to edit or not, hook can determine that. No role needed.
	// Some permission stuff or role linking stuff such as ownership's model has extra stuffs such as associated link table's info).
	// So data.Ms itself can be modified, so a new set is returned
	PermissionAndRole(data *hook.Data, ep *hook.EndPoint) (*hook.Data, *webrender.RetError)
}

IService provice basic data fetch for various type of table to user relationships

type LinkTableService

type LinkTableService struct {
	BaseService
}

func (*LinkTableService) GetAllQueryContructCore added in v0.3.4

func (serv *LinkTableService) GetAllQueryContructCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string) (*gorm.DB, error)

GetAllQueryContructCore construct query core

func (*LinkTableService) GetAllRolesCore added in v0.3.4

func (serv *LinkTableService) GetAllRolesCore(dbChained *gorm.DB, dbClean *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]userrole.UserRole, error)

GetAllRolesCore gets all roles according to the criteria

func (*LinkTableService) GetManyCore added in v0.5.0

func (serv *LinkTableService) GetManyCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, ids []*datatype.UUID, options map[urlparam.Param]interface{}) ([]mdl.IModel, []userrole.UserRole, error)

func (*LinkTableService) HookBeforeDeleteMany

func (serv *LinkTableService) HookBeforeDeleteMany(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]mdl.IModel, error)

func (*LinkTableService) HookBeforeDeleteOne

func (serv *LinkTableService) HookBeforeDeleteOne(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel) (mdl.IModel, error)

func (*LinkTableService) PermissionAndRole added in v0.10.7

func (serv *LinkTableService) PermissionAndRole(data *hook.Data, ep *hook.EndPoint) (*hook.Data, *webrender.RetError)

func (*LinkTableService) ReadOneCore added in v0.5.0

func (service *LinkTableService) ReadOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, id *datatype.UUID, options map[urlparam.Param]interface{}) (mdl.IModel, userrole.UserRole, error)

ReadOneCore get one model object based on its type and its id string

func (*LinkTableService) UpdateOneCore

func (serv *LinkTableService) UpdateOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel, id *datatype.UUID, oldModelObj mdl.IModel) (modelObj2 mdl.IModel, err error)

UpdateOneCore one, permissin should already be checked called for patch operation as well (after patch has already applied) Fuck, repeat the following code for now (you can't call the overriding method from the non-overriding one)

type OrgPartition added in v0.9.7

type OrgPartition struct {
	BaseService
}

OrgPartition handles all the ownership specific db calls

func (*OrgPartition) GetAllQueryContructCore added in v0.9.7

func (serv *OrgPartition) GetAllQueryContructCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string) (*gorm.DB, error)

GetAllQueryContructCore construct query core

func (*OrgPartition) GetAllRolesCore added in v0.9.7

func (serv *OrgPartition) GetAllRolesCore(dbChained *gorm.DB, dbClean *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]userrole.UserRole, error)

GetAllRolesCore gets all roles according to the criteria

func (*OrgPartition) GetManyCore added in v0.9.7

func (serv *OrgPartition) GetManyCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, ids []*datatype.UUID, options map[urlparam.Param]interface{}) ([]mdl.IModel, []userrole.UserRole, error)

func (*OrgPartition) HookBeforeDeleteMany added in v0.9.7

func (serv *OrgPartition) HookBeforeDeleteMany(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]mdl.IModel, error)

func (*OrgPartition) HookBeforeDeleteOne added in v0.9.7

func (serv *OrgPartition) HookBeforeDeleteOne(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel) (mdl.IModel, error)

func (*OrgPartition) PermissionAndRole added in v0.10.7

func (serv *OrgPartition) PermissionAndRole(data *hook.Data, ep *hook.EndPoint) (*hook.Data, *webrender.RetError)

func (*OrgPartition) ReadOneCore added in v0.9.7

func (serv *OrgPartition) ReadOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, id *datatype.UUID, options map[urlparam.Param]interface{}) (mdl.IModel, userrole.UserRole, error)

getOneWithIDCore get one model object based on its type and its id string since this is organizationMapper, need to make sure it's the same organization

func (*OrgPartition) UpdateOneCore added in v0.9.7

func (serv *OrgPartition) UpdateOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel, id *datatype.UUID, oldModelObj mdl.IModel) (modelObj2 mdl.IModel, err error)

UpdateOneCore one, permission should already be checked called for patch operation as well (after patch has already applied) Fuck, repeat the following code for now (you can't call the overriding method from the non-overriding one)

type OwnershipService

type OwnershipService struct {
	BaseService
}

OwnershipService handles all the ownership specific db calls

func (*OwnershipService) CreateOneCore

func (serv *OwnershipService) CreateOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel, id *datatype.UUID, oldModelObj mdl.IModel) (mdl.IModel, error)

CreateOneCore creates the stuff

func (*OwnershipService) GetAllQueryContructCore added in v0.3.4

func (serv *OwnershipService) GetAllQueryContructCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string) (*gorm.DB, error)

GetAllQueryContructCore construct the meat of the query

func (*OwnershipService) GetAllRolesCore added in v0.3.4

func (serv *OwnershipService) GetAllRolesCore(dbChained *gorm.DB, dbClean *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]userrole.UserRole, error)

GetAllRolesCore gets all roles according to the criteria

func (*OwnershipService) GetManyCore added in v0.5.0

func (serv *OwnershipService) GetManyCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, ids []*datatype.UUID, options map[urlparam.Param]interface{}) ([]mdl.IModel, []userrole.UserRole, error)

GetManyCore -

func (*OwnershipService) HookBeforeDeleteMany

func (serv *OwnershipService) HookBeforeDeleteMany(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]mdl.IModel, error)

HookBeforeDeleteMany deletes link table because GORM isn't automatic here when we customize it with UUID or when we have role

func (*OwnershipService) HookBeforeDeleteOne

func (serv *OwnershipService) HookBeforeDeleteOne(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel) (mdl.IModel, error)

func (*OwnershipService) PermissionAndRole added in v0.10.7

func (serv *OwnershipService) PermissionAndRole(data *hook.Data, ep *hook.EndPoint) (*hook.Data, *webrender.RetError)

func (*OwnershipService) ReadOneCore added in v0.5.0

func (serv *OwnershipService) ReadOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, id *datatype.UUID, options map[urlparam.Param]interface{}) (mdl.IModel, userrole.UserRole, error)

ReadOneCore get one model object based on its type and its id string

func (*OwnershipService) UpdateOneCore

func (serv *OwnershipService) UpdateOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel, id *datatype.UUID, oldModelObj mdl.IModel) (modelObj2 mdl.IModel, err error)

UpdateOneCore one, permissin should already be checked called for patch operation as well (after patch has already applied) Fuck, repeat the following code for now (you can't call the overriding method from the non-overriding one)

type UnderOrgService added in v0.10.7

type UnderOrgService struct {
	BaseService
}

UnderOrgService handles all the ownership specific db calls

func (*UnderOrgService) GetAllQueryContructCore added in v0.10.7

func (serv *UnderOrgService) GetAllQueryContructCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string) (*gorm.DB, error)

GetAllQueryContructCore construct query core

func (*UnderOrgService) GetAllRolesCore added in v0.10.7

func (serv *UnderOrgService) GetAllRolesCore(dbChained *gorm.DB, dbClean *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]userrole.UserRole, error)

GetAllRolesCore gets all roles according to the criteria

func (*UnderOrgService) GetManyCore added in v0.10.7

func (serv *UnderOrgService) GetManyCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, ids []*datatype.UUID, options map[urlparam.Param]interface{}) ([]mdl.IModel, []userrole.UserRole, error)

func (*UnderOrgService) HookBeforeDeleteMany added in v0.10.7

func (serv *UnderOrgService) HookBeforeDeleteMany(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]mdl.IModel, error)

func (*UnderOrgService) HookBeforeDeleteOne added in v0.10.7

func (serv *UnderOrgService) HookBeforeDeleteOne(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel) (mdl.IModel, error)

func (*UnderOrgService) PermissionAndRole added in v0.10.7

func (serv *UnderOrgService) PermissionAndRole(data *hook.Data, ep *hook.EndPoint) (*hook.Data, *webrender.RetError)

func (*UnderOrgService) ReadOneCore added in v0.10.7

func (serv *UnderOrgService) ReadOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, id *datatype.UUID, options map[urlparam.Param]interface{}) (mdl.IModel, userrole.UserRole, error)

getOneWithIDCore get one model object based on its type and its id string since this is organizationMapper, need to make sure it's the same organization

func (*UnderOrgService) UpdateOneCore added in v0.10.7

func (serv *UnderOrgService) UpdateOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel, id *datatype.UUID, oldModelObj mdl.IModel) (modelObj2 mdl.IModel, err error)

UpdateOneCore one, permission should already be checked called for patch operation as well (after patch has already applied) Fuck, repeat the following code for now (you can't call the overriding method from the non-overriding one)

type UserService

type UserService struct {
	BaseService
}

func (*UserService) GetAllQueryContructCore added in v0.3.4

func (serv *UserService) GetAllQueryContructCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string) (*gorm.DB, error)

GetAllQueryContructCore :-

func (*UserService) GetAllRolesCore added in v0.3.4

func (serv *UserService) GetAllRolesCore(dbChained *gorm.DB, dbClean *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]userrole.UserRole, error)

GetAllRolesCore :-

func (*UserService) GetManyCore added in v0.5.0

func (serv *UserService) GetManyCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, ids []*datatype.UUID, options map[urlparam.Param]interface{}) ([]mdl.IModel, []userrole.UserRole, error)

func (*UserService) HookBeforeDeleteMany

func (serv *UserService) HookBeforeDeleteMany(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObjs []mdl.IModel) ([]mdl.IModel, error)

func (*UserService) HookBeforeDeleteOne

func (serv *UserService) HookBeforeDeleteOne(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel) (mdl.IModel, error)

func (*UserService) PermissionAndRole added in v0.10.7

func (serv *UserService) PermissionAndRole(data *hook.Data, ep *hook.EndPoint) (*hook.Data, *webrender.RetError)

func (*UserService) ReadOneCore added in v0.5.0

func (serv *UserService) ReadOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, id *datatype.UUID, options map[urlparam.Param]interface{}) (mdl.IModel, userrole.UserRole, error)

ReadOneCore get one model object based on its type and its id string ReadOne get one model object based on its type and its id string without invoking read hookpoing

func (*UserService) UpdateOneCore

func (serv *UserService) UpdateOneCore(db *gorm.DB, who mdlutil.UserIDFetchable, typeString string, modelObj mdl.IModel, id *datatype.UUID, oldModelObj mdl.IModel) (modelObj2 mdl.IModel, err error)

UpdateOneCore one, permissin should already be checked called for patch operation as well (after patch has already applied) Fuck, repeat the following code for now (you can't call the overriding method from the non-overriding one)

Jump to

Keyboard shortcuts

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