repositories

package
v0.0.0-...-52c8aec Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: MIT Imports: 7 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 uuid.UUID, 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 uuid.UUID, 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 uuid.UUID, permissions collections.Permission) (err error)
	ReplacePermissions(userID uuid.UUID, permissions collections.Permission) (err error)
	RemovePermissions(userID uuid.UUID, permissions collections.Permission) (err error)
	ClearPermissions(userID uuid.UUID) (err error)

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

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

	HasDirectPermission(userID uuid.UUID, permission models.Permission) (b bool, err error)
	HasAllDirectPermissions(userID uuid.UUID, permissions collections.Permission) (b bool, err error)
	HasAnyDirectPermissions(userID uuid.UUID, 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 uuid.UUID, 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 uuid.UUID, 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 uuid.UUID, permissions collections.Permission) error

AddPermissions add direct permissions to user. @param uuid.UUID @param collections.Permission @return error

func (*UserRepository) AddRoles

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

AddRoles add roles to user. @param uuid.UUID @param collections.Role @return error

func (*UserRepository) ClearPermissions

func (repository *UserRepository) ClearPermissions(userID uuid.UUID) (err error)

ClearPermissions remove all direct permissions of user. @param uuid.UUID @return error

func (*UserRepository) ClearRoles

func (repository *UserRepository) ClearRoles(userID uuid.UUID) (err error)

ClearRoles remove all roles of user. @param uuid.UUID @return error

func (*UserRepository) HasAllDirectPermissions

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

HasAllDirectPermissions does the user have all the given permissions? (not including the permissions of the roles) @param uuid.UUID @param collections.Permission @return bool, error

func (*UserRepository) HasAllRoles

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

HasAllRoles does the user have all the given roles? @param uuid.UUID @param collections.Role @return bool, error

func (*UserRepository) HasAnyDirectPermissions

func (repository *UserRepository) HasAnyDirectPermissions(userID uuid.UUID, 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 uuid.UUID @param collections.Permission @return bool, error

func (*UserRepository) HasAnyRoles

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

HasAnyRoles does the user have any of the given roles? @param uuid.UUID @param collections.Role @return bool, error

func (*UserRepository) HasDirectPermission

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

HasDirectPermission does the user have the given permission? (not including the permissions of the roles) @param uuid.UUID @param collections.Permission @return bool, error

func (*UserRepository) HasRole

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

HasRole does the user have the given role? @param uuid.UUID @param models.Role @return bool, error

func (*UserRepository) RemovePermissions

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

RemovePermissions remove direct permissions of user. @param uuid.UUID @param collections.Permission @return error

func (*UserRepository) RemoveRoles

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

RemoveRoles remove roles of user. @param uuid.UUID @param collections.Role @return error

func (*UserRepository) ReplacePermissions

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

ReplacePermissions replace direct permissions of user. @param uuid.UUID @param collections.Permission @return error

func (*UserRepository) ReplaceRoles

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

ReplaceRoles replace roles of user. @param uuid.UUID @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