repositories

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrates

func Migrates(repos ...Migratable) (err error)

Migrates migrate to migratable models.

func Seeds

func Seeds(repos ...Seedable) (err error)

Seeds seed to seedable models.

Types

type IPermissionRepository

type IPermissionRepository interface {
	Migratable

	GetPermissionByID(ID uint) (permission models.Permission, err error)
	GetPermissionByGuardName(guardName string) (permission models.Permission, err error)

	GetPermissions(IDs []uint) (permissions collections.Permission, err error)
	GetPermissionsByGuardNames(guardNames []string) (permissions collections.Permission, err error)

	GetPermissionIDs(pagination scopes.GormPager) (permissionIDs []uint, totalCount int64, err error)
	GetDirectPermissionIDsOfUserByID(userID uint, pagination scopes.GormPager) (permissionIDs []uint, totalCount int64, err error)
	GetPermissionIDsOfRolesByIDs(roleIDs []uint, pagination scopes.GormPager) (permissionIDs []uint, totalCount int64, err error)

	FirstOrCreate(permission *models.Permission) (err error)
	Updates(permission *models.Permission, updates map[string]interface{}) (err error)
	Delete(permission *models.Permission) (err error)
}

IPermissionRepository its data access layer abstraction of permission.

type IRoleRepository

type IRoleRepository interface {
	Migratable

	GetRoleByID(ID uint) (role models.Role, err error)
	GetRoleByIDWithPermissions(ID uint) (role models.Role, err error)

	GetRoleByGuardName(guardName string) (role models.Role, err error)
	GetRoleByGuardNameWithPermissions(guardName string) (role models.Role, err error)

	GetRoles(roleIDs []uint) (roles collections.Role, err error)
	GetRolesWithPermissions(roleIDs []uint) (roles collections.Role, err error)

	GetRolesByGuardNames(guardNames []string) (roles collections.Role, err error)
	GetRolesByGuardNamesWithPermissions(guardNames []string) (roles collections.Role, err error)

	GetRoleIDs(pagination scopes.GormPager) (roleIDs []uint, totalCount int64, err error)
	GetRoleIDsOfUser(userID uint, pagination scopes.GormPager) (roleIDs []uint, totalCount int64, err error)
	GetRoleIDsOfPermission(permissionID uint, pagination scopes.GormPager) (roleIDs []uint, totalCount int64, err error)

	FirstOrCreate(role *models.Role) (err error)
	Updates(role *models.Role, updates map[string]interface{}) (err error)
	Delete(role *models.Role) (err error)

	AddPermissions(role *models.Role, permissions collections.Permission) (err error)
	ReplacePermissions(role *models.Role, permissions collections.Permission) (err error)
	RemovePermissions(role *models.Role, permissions collections.Permission) (err error)
	ClearPermissions(role *models.Role) (err error)

	HasPermission(roles collections.Role, permission models.Permission) (b bool, err error)
	HasAllPermissions(roles collections.Role, permissions collections.Permission) (b bool, err error)
	HasAnyPermissions(roles collections.Role, permissions collections.Permission) (b bool, err error)
}

IRoleRepository its data access layer abstraction of role.

type IUserRepository

type IUserRepository interface {
	AddPermissions(userID uint, permissions collections.Permission) (err error)
	ReplacePermissions(userID uint, permissions collections.Permission) (err error)
	RemovePermissions(userID uint, permissions collections.Permission) (err error)
	ClearPermissions(userID uint) (err error)

	AddRoles(userID uint, roles collections.Role) (err error)
	ReplaceRoles(userID uint, roles collections.Role) (err error)
	RemoveRoles(userID uint, roles collections.Role) (err error)
	ClearRoles(userID uint) (err error)

	HasRole(userID uint, role models.Role) (b bool, err error)
	HasAllRoles(userID uint, roles collections.Role) (b bool, err error)
	HasAnyRoles(userID uint, roles collections.Role) (b bool, err error)

	HasDirectPermission(userID uint, permission models.Permission) (b bool, err error)
	HasAllDirectPermissions(userID uint, permissions collections.Permission) (b bool, err error)
	HasAnyDirectPermissions(userID uint, permissions collections.Permission) (b bool, err error)
}

IUserRepository its data access layer abstraction of user.

type Migratable

type Migratable interface {
	Migrate() error
}

Migratable gives models the ability to migrate.

type PermissionRepository

type PermissionRepository struct {
	Database *gorm.DB
}

PermissionRepository its data access layer of permission.

func (*PermissionRepository) Delete

func (repository *PermissionRepository) Delete(permission *models.Permission) (err error)

Delete delete permission. Param: *models.Permission @return error

func (*PermissionRepository) FirstOrCreate

func (repository *PermissionRepository) FirstOrCreate(permission *models.Permission) error

FirstOrCreate create new permission if name not exist. Param: *models.Permission @return error

func (*PermissionRepository) GetDirectPermissionIDsOfUserByID

func (repository *PermissionRepository) GetDirectPermissionIDsOfUserByID(userID uint, pagination scopes.GormPager) (permissionIDs []uint, totalCount int64, err error)

GetDirectPermissionIDsOfUserByID get direct permission ids of user. (with pagination) Param: uint Param: repositories_scopes.GormPager @return []uint, int64, error

func (*PermissionRepository) GetPermissionByGuardName

func (repository *PermissionRepository) GetPermissionByGuardName(guardName string) (permission models.Permission, err error)

GetPermissionByGuardName get permission by guard name. Param: string @return models.Permission, error

func (*PermissionRepository) GetPermissionByID

func (repository *PermissionRepository) GetPermissionByID(ID uint) (permission models.Permission, err error)

GetPermissionByID get permission by id. Param: uint @return models.Permission, error

func (*PermissionRepository) GetPermissionIDs

func (repository *PermissionRepository) GetPermissionIDs(pagination scopes.GormPager) (permissionIDs []uint, totalCount int64, err error)

GetPermissionIDs get permission ids. (with pagination) Param: repositories_scopes.GormPager @return []uint, int64, error

func (*PermissionRepository) GetPermissionIDsOfRolesByIDs

func (repository *PermissionRepository) GetPermissionIDsOfRolesByIDs(roleIDs []uint, pagination scopes.GormPager) (permissionIDs []uint, totalCount int64, err error)

GetPermissionIDsOfRolesByIDs get permission ids of roles. (with pagination) Param: []uint Param: repositories_scopes.GormPager @return []uint, int64, error

func (*PermissionRepository) GetPermissions

func (repository *PermissionRepository) GetPermissions(IDs []uint) (permissions collections.Permission, err error)

GetPermissions get permissions by ids. Param: []uint @return collections.Role, error

func (*PermissionRepository) GetPermissionsByGuardNames

func (repository *PermissionRepository) GetPermissionsByGuardNames(guardNames []string) (permissions collections.Permission, err error)

GetPermissionsByGuardNames get permissions by guard names. Param: []string @return collections.Permission, error

func (*PermissionRepository) Migrate

func (repository *PermissionRepository) Migrate() (err error)

Migrate generate tables from the database. @return error

func (*PermissionRepository) Updates

func (repository *PermissionRepository) Updates(permission *models.Permission, updates map[string]interface{}) (err error)

Updates update permission. Param: *models.Permission Param: map[string]interface{} @return error

type RoleRepository

type RoleRepository struct {
	Database *gorm.DB
}

RoleRepository its data access layer of role.

func (*RoleRepository) AddPermissions

func (repository *RoleRepository) AddPermissions(role *models.Role, permissions collections.Permission) error

AddPermissions add permissions to role. Param: *models.Role Param: collections.Permission @return error

func (*RoleRepository) ClearPermissions

func (repository *RoleRepository) ClearPermissions(role *models.Role) (err error)

ClearPermissions remove all permissions of role. Param: *models.Role @return error

func (*RoleRepository) Delete

func (repository *RoleRepository) Delete(role *models.Role) (err error)

Delete delete role. Param: *models.Role @return error

func (*RoleRepository) FirstOrCreate

func (repository *RoleRepository) FirstOrCreate(role *models.Role) error

FirstOrCreate create new role if name not exist. Param: *models.Role @return error

func (*RoleRepository) GetRoleByGuardName

func (repository *RoleRepository) GetRoleByGuardName(guardName string) (role models.Role, err error)

GetRoleByGuardName get role by guard name. Param: string @return models.Role, error

func (*RoleRepository) GetRoleByGuardNameWithPermissions

func (repository *RoleRepository) GetRoleByGuardNameWithPermissions(guardName string) (role models.Role, err error)

GetRoleByGuardNameWithPermissions get role by guard name with its permissions. Param: string @return models.Role, error

func (*RoleRepository) GetRoleByID

func (repository *RoleRepository) GetRoleByID(ID uint) (role models.Role, err error)

GetRoleByID get role by id. Param: uint @return models.Role, error

func (*RoleRepository) GetRoleByIDWithPermissions

func (repository *RoleRepository) GetRoleByIDWithPermissions(ID uint) (role models.Role, err error)

GetRoleByIDWithPermissions get role by id with its permissions. Param: uint @return models.Role, error

func (*RoleRepository) GetRoleIDs

func (repository *RoleRepository) GetRoleIDs(pagination scopes.GormPager) (roleIDs []uint, totalCount int64, err error)

GetRoleIDs get role ids. (with pagination) Param: repositories_scopes.GormPager @return []uint, int64, error

func (*RoleRepository) GetRoleIDsOfPermission

func (repository *RoleRepository) GetRoleIDsOfPermission(permissionID uint, pagination scopes.GormPager) (roleIDs []uint, totalCount int64, err error)

GetRoleIDsOfPermission get role ids of permission. (with pagination) Param: uint Param: repositories_scopes.GormPager @return []uint, int64, error

func (*RoleRepository) GetRoleIDsOfUser

func (repository *RoleRepository) GetRoleIDsOfUser(userID uint, pagination scopes.GormPager) (roleIDs []uint, totalCount int64, err error)

GetRoleIDsOfUser get role ids of user. (with pagination) Param: uint Param: repositories_scopes.GormPager @return []uint, int64, error

func (*RoleRepository) GetRoles

func (repository *RoleRepository) GetRoles(IDs []uint) (roles collections.Role, err error)

GetRoles get roles by ids. Param: []uint @return collections.Role, error

func (*RoleRepository) GetRolesByGuardNames

func (repository *RoleRepository) GetRolesByGuardNames(guardNames []string) (roles collections.Role, err error)

GetRolesByGuardNames get roles by guard names. Param: []string @return collections.Role, error

func (*RoleRepository) GetRolesByGuardNamesWithPermissions

func (repository *RoleRepository) GetRolesByGuardNamesWithPermissions(guardNames []string) (roles collections.Role, err error)

GetRolesByGuardNamesWithPermissions get roles by guard names. Param: []string @return collections.Role, error

func (*RoleRepository) GetRolesWithPermissions

func (repository *RoleRepository) GetRolesWithPermissions(IDs []uint) (roles collections.Role, err error)

GetRolesWithPermissions get roles by ids with its permissions. Param: []uint @return collections.Role, error

func (*RoleRepository) HasAllPermissions

func (repository *RoleRepository) HasAllPermissions(roles collections.Role, permissions collections.Permission) (b bool, err error)

HasAllPermissions does the role or roles have all the given permissions? Param: collections.Role Param: collections.Permission @return bool, error

func (*RoleRepository) HasAnyPermissions

func (repository *RoleRepository) HasAnyPermissions(roles collections.Role, permissions collections.Permission) (b bool, err error)

HasAnyPermissions does the role or roles have any of the given permissions? Param: collections.Role Param: collections.Permission @return bool, error

func (*RoleRepository) HasPermission

func (repository *RoleRepository) HasPermission(roles collections.Role, permission models.Permission) (b bool, err error)

HasPermission does the role or any of the roles have given permission? Param: collections.Role Param: models.Permission @return bool, error

func (*RoleRepository) Migrate

func (repository *RoleRepository) Migrate() (err error)

Migrate generate tables from the database. @return error

func (*RoleRepository) RemovePermissions

func (repository *RoleRepository) RemovePermissions(role *models.Role, permissions collections.Permission) error

RemovePermissions remove permissions of role. Param: *models.Role Param: collections.Permission @return error

func (*RoleRepository) ReplacePermissions

func (repository *RoleRepository) ReplacePermissions(role *models.Role, permissions collections.Permission) error

ReplacePermissions replace permissions of role. Param: *models.Role Param: collections.Permission @return error

func (*RoleRepository) Updates

func (repository *RoleRepository) Updates(role *models.Role, updates map[string]interface{}) (err error)

Updates update role. Param: *models.Role Param: map[string]interface{} @return error

type Seedable

type Seedable interface {
	Seed() error
}

Seedable gives models the ability to seed.

type UserRepository

type UserRepository struct {
	Database *gorm.DB
}

UserRepository its data access layer of user.

func (*UserRepository) AddPermissions

func (repository *UserRepository) AddPermissions(userID uint, permissions collections.Permission) error

AddPermissions add direct permissions to user. Param: uint Param: collections.Permission @return error

func (*UserRepository) AddRoles

func (repository *UserRepository) AddRoles(userID uint, roles collections.Role) error

AddRoles add roles to user. Param: uint Param: collections.Role @return error

func (*UserRepository) ClearPermissions

func (repository *UserRepository) ClearPermissions(userID uint) (err error)

ClearPermissions remove all direct permissions of user. Param: uint @return error

func (*UserRepository) ClearRoles

func (repository *UserRepository) ClearRoles(userID uint) (err error)

ClearRoles remove all roles of user. Param: uint @return error

func (*UserRepository) HasAllDirectPermissions

func (repository *UserRepository) HasAllDirectPermissions(userID uint, permissions collections.Permission) (b bool, err error)

HasAllDirectPermissions does the user have all the given permissions? (not including the permissions of the roles) Param: uint Param: collections.Permission @return bool, error

func (*UserRepository) HasAllRoles

func (repository *UserRepository) HasAllRoles(userID uint, roles collections.Role) (b bool, err error)

HasAllRoles does the user have all the given roles? Param: uint Param: collections.Role @return bool, error

func (*UserRepository) HasAnyDirectPermissions

func (repository *UserRepository) HasAnyDirectPermissions(userID uint, permissions collections.Permission) (b bool, err error)

HasAnyDirectPermissions does the user have any of the given permissions? (not including the permissions of the roles) Param: uint Param: collections.Permission @return bool, error

func (*UserRepository) HasAnyRoles

func (repository *UserRepository) HasAnyRoles(userID uint, roles collections.Role) (b bool, err error)

HasAnyRoles does the user have any of the given roles? Param: uint Param: collections.Role @return bool, error

func (*UserRepository) HasDirectPermission

func (repository *UserRepository) HasDirectPermission(userID uint, permission models.Permission) (b bool, err error)

HasDirectPermission does the user have the given permission? (not including the permissions of the roles) Param: uint Param: collections.Permission @return bool, error

func (*UserRepository) HasRole

func (repository *UserRepository) HasRole(userID uint, role models.Role) (b bool, err error)

HasRole does the user have the given role? Param: uint Param: models.Role @return bool, error

func (*UserRepository) RemovePermissions

func (repository *UserRepository) RemovePermissions(userID uint, permissions collections.Permission) error

RemovePermissions remove direct permissions of user. Param: uint Param: collections.Permission @return error

func (*UserRepository) RemoveRoles

func (repository *UserRepository) RemoveRoles(userID uint, roles collections.Role) error

RemoveRoles remove roles of user. Param: uint Param: collections.Role @return error

func (*UserRepository) ReplacePermissions

func (repository *UserRepository) ReplacePermissions(userID uint, permissions collections.Permission) error

ReplacePermissions replace direct permissions of user. Param: uint Param: collections.Permission @return error

func (*UserRepository) ReplaceRoles

func (repository *UserRepository) ReplaceRoles(userID uint, roles collections.Role) error

ReplaceRoles replace roles of user. Param: uint Param: collections.Role @return error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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