Documentation
¶
Index ¶
- Constants
- Variables
- type ForeignKeySpec
- type MySQLRepository
- func (repo MySQLRepository) Create(ctx context.Context, objectType ObjectType) (int64, error)
- func (repo MySQLRepository) DeleteByTypeId(ctx context.Context, typeId string) error
- func (repo MySQLRepository) GetById(ctx context.Context, id int64) (*ObjectType, error)
- func (repo MySQLRepository) GetByTypeId(ctx context.Context, typeId string) (*ObjectType, error)
- func (repo MySQLRepository) List(ctx context.Context, listParams middleware.ListParams) ([]ObjectType, error)
- func (repo MySQLRepository) UpdateByTypeId(ctx context.Context, typeId string, objectType ObjectType) error
- type ObjectType
- type ObjectTypeListParamParser
- type ObjectTypeRepository
- type ObjectTypeService
- func (svc ObjectTypeService) Create(ctx context.Context, objectTypeSpec ObjectTypeSpec) (*ObjectTypeSpec, error)
- func (svc ObjectTypeService) DeleteByTypeId(ctx context.Context, typeId string) error
- func (svc ObjectTypeService) GetByTypeId(ctx context.Context, typeId string) (*ObjectTypeSpec, error)
- func (svc ObjectTypeService) GetRoutes() []service.Route
- func (svc ObjectTypeService) List(ctx context.Context, listParams middleware.ListParams) ([]ObjectTypeSpec, error)
- func (svc ObjectTypeService) UpdateByTypeId(ctx context.Context, typeId string, objectTypeSpec ObjectTypeSpec) (*ObjectTypeSpec, error)
- type ObjectTypeSpec
- type PostgresRepository
- func (repo PostgresRepository) Create(ctx context.Context, objectType ObjectType) (int64, error)
- func (repo PostgresRepository) DeleteByTypeId(ctx context.Context, typeId string) error
- func (repo PostgresRepository) GetById(ctx context.Context, id int64) (*ObjectType, error)
- func (repo PostgresRepository) GetByTypeId(ctx context.Context, typeId string) (*ObjectType, error)
- func (repo PostgresRepository) List(ctx context.Context, listParams middleware.ListParams) ([]ObjectType, error)
- func (repo PostgresRepository) UpdateByTypeId(ctx context.Context, typeId string, objectType ObjectType) error
- type RelationRule
- type Source
Constants ¶
View Source
const ( ObjectTypeFeature = "feature" ObjectTypePermission = "permission" ObjectTypePricingTier = "pricing-tier" ObjectTypeRole = "role" ObjectTypeTenant = "tenant" ObjectTypeUser = "user" RelationAdmin = "admin" RelationManager = "manager" RelationMember = "member" RelationParent = "parent" RelationOwner = "owner" RelationEditor = "editor" RelationViewer = "viewer" InheritIfAllOf = "allOf" InheritIfAnyOf = "anyOf" InheritIfNoneOf = "noneOf" )
Variables ¶
View Source
var FeatureObjectTypeSpec = ObjectTypeSpec{ Type: ObjectTypeFeature, Relations: map[string]RelationRule{ RelationMember: { InheritIf: InheritIfAnyOf, Rules: []RelationRule{ { InheritIf: RelationMember, OfType: ObjectTypeFeature, WithRelation: RelationMember, }, { InheritIf: RelationMember, OfType: ObjectTypePricingTier, WithRelation: RelationMember, }, }, }, }, }
View Source
var PermissionObjectTypeSpec = ObjectTypeSpec{ Type: ObjectTypePermission, Relations: map[string]RelationRule{ RelationOwner: {}, RelationEditor: { InheritIf: RelationOwner, }, RelationViewer: { InheritIf: RelationEditor, }, RelationMember: { InheritIf: InheritIfAnyOf, Rules: []RelationRule{ { InheritIf: RelationMember, OfType: ObjectTypePermission, WithRelation: RelationMember, }, { InheritIf: RelationMember, OfType: ObjectTypeRole, WithRelation: RelationMember, }, }, }, }, }
View Source
var PricingTierObjectTypeSpec = ObjectTypeSpec{ Type: ObjectTypePricingTier, Relations: map[string]RelationRule{ RelationMember: { InheritIf: RelationMember, OfType: ObjectTypePricingTier, WithRelation: RelationMember, }, }, }
View Source
var RoleObjectTypeSpec = ObjectTypeSpec{ Type: ObjectTypeRole, Relations: map[string]RelationRule{ RelationOwner: {}, RelationEditor: { InheritIf: RelationOwner, }, RelationViewer: { InheritIf: RelationEditor, }, RelationMember: { InheritIf: RelationMember, OfType: ObjectTypeRole, WithRelation: RelationMember, }, }, }
View Source
var TenantObjectTypeSpec = ObjectTypeSpec{ Type: ObjectTypeTenant, Relations: map[string]RelationRule{ RelationAdmin: {}, RelationManager: { InheritIf: RelationAdmin, }, RelationMember: { InheritIf: RelationManager, }, }, }
View Source
var UserObjectTypeSpec = ObjectTypeSpec{ Type: ObjectTypeUser, Relations: map[string]RelationRule{ RelationParent: { InheritIf: RelationParent, OfType: ObjectTypeUser, WithRelation: RelationParent, }, }, }
Functions ¶
This section is empty.
Types ¶
type ForeignKeySpec ¶
type MySQLRepository ¶
type MySQLRepository struct {
database.SQLRepository
}
func NewMySQLRepository ¶
func NewMySQLRepository(db *database.MySQL) MySQLRepository
func (MySQLRepository) Create ¶
func (repo MySQLRepository) Create(ctx context.Context, objectType ObjectType) (int64, error)
func (MySQLRepository) DeleteByTypeId ¶
func (repo MySQLRepository) DeleteByTypeId(ctx context.Context, typeId string) error
func (MySQLRepository) GetById ¶
func (repo MySQLRepository) GetById(ctx context.Context, id int64) (*ObjectType, error)
func (MySQLRepository) GetByTypeId ¶
func (repo MySQLRepository) GetByTypeId(ctx context.Context, typeId string) (*ObjectType, error)
func (MySQLRepository) List ¶
func (repo MySQLRepository) List(ctx context.Context, listParams middleware.ListParams) ([]ObjectType, error)
func (MySQLRepository) UpdateByTypeId ¶
func (repo MySQLRepository) UpdateByTypeId(ctx context.Context, typeId string, objectType ObjectType) error
type ObjectType ¶
type ObjectType struct {
ID int64 `mysql:"id" postgres:"id"`
TypeId string `mysql:"typeId" postgres:"type_id"`
Definition string `mysql:"definition" postgres:"definition"`
CreatedAt time.Time `mysql:"createdAt" postgres:"created_at"`
UpdatedAt time.Time `mysql:"updatedAt" postgres:"updated_at"`
DeletedAt database.NullTime `mysql:"deletedAt" postgres:"deleted_at"`
}
ObjectType model
func (ObjectType) ToObjectTypeSpec ¶
func (objectType ObjectType) ToObjectTypeSpec() (*ObjectTypeSpec, error)
type ObjectTypeListParamParser ¶
type ObjectTypeListParamParser struct{}
func (ObjectTypeListParamParser) GetDefaultSortBy ¶
func (parser ObjectTypeListParamParser) GetDefaultSortBy() string
func (ObjectTypeListParamParser) GetSupportedSortBys ¶
func (parser ObjectTypeListParamParser) GetSupportedSortBys() []string
func (ObjectTypeListParamParser) ParseValue ¶
func (parser ObjectTypeListParamParser) ParseValue(val string, sortBy string) (interface{}, error)
type ObjectTypeRepository ¶
type ObjectTypeRepository interface {
Create(ctx context.Context, objectType ObjectType) (int64, error)
GetById(ctx context.Context, id int64) (*ObjectType, error)
GetByTypeId(ctx context.Context, typeId string) (*ObjectType, error)
List(ctx context.Context, listParams middleware.ListParams) ([]ObjectType, error)
UpdateByTypeId(ctx context.Context, typeId string, objectType ObjectType) error
DeleteByTypeId(ctx context.Context, typeId string) error
}
func NewRepository ¶
func NewRepository(db database.Database) (ObjectTypeRepository, error)
type ObjectTypeService ¶
type ObjectTypeService struct {
service.BaseService
}
func NewService ¶
func NewService(env service.Env) ObjectTypeService
func (ObjectTypeService) Create ¶
func (svc ObjectTypeService) Create(ctx context.Context, objectTypeSpec ObjectTypeSpec) (*ObjectTypeSpec, error)
func (ObjectTypeService) DeleteByTypeId ¶
func (svc ObjectTypeService) DeleteByTypeId(ctx context.Context, typeId string) error
func (ObjectTypeService) GetByTypeId ¶
func (svc ObjectTypeService) GetByTypeId(ctx context.Context, typeId string) (*ObjectTypeSpec, error)
func (ObjectTypeService) GetRoutes ¶
func (svc ObjectTypeService) GetRoutes() []service.Route
GetRoutes registers all route handlers for this module
func (ObjectTypeService) List ¶
func (svc ObjectTypeService) List(ctx context.Context, listParams middleware.ListParams) ([]ObjectTypeSpec, error)
func (ObjectTypeService) UpdateByTypeId ¶
func (svc ObjectTypeService) UpdateByTypeId(ctx context.Context, typeId string, objectTypeSpec ObjectTypeSpec) (*ObjectTypeSpec, error)
type ObjectTypeSpec ¶
type ObjectTypeSpec struct {
Type string `json:"type" validate:"required,valid_object_type"`
Source *Source `json:"source,omitempty"`
Relations map[string]RelationRule `json:"relations" validate:"required,min=1,dive"` // NOTE: map key = name of relation
}
func (ObjectTypeSpec) ToObjectType ¶
func (spec ObjectTypeSpec) ToObjectType() (*ObjectType, error)
type PostgresRepository ¶ added in v0.4.0
type PostgresRepository struct {
database.SQLRepository
}
func NewPostgresRepository ¶ added in v0.4.0
func NewPostgresRepository(db *database.Postgres) PostgresRepository
func (PostgresRepository) Create ¶ added in v0.4.0
func (repo PostgresRepository) Create(ctx context.Context, objectType ObjectType) (int64, error)
func (PostgresRepository) DeleteByTypeId ¶ added in v0.4.0
func (repo PostgresRepository) DeleteByTypeId(ctx context.Context, typeId string) error
func (PostgresRepository) GetById ¶ added in v0.4.0
func (repo PostgresRepository) GetById(ctx context.Context, id int64) (*ObjectType, error)
func (PostgresRepository) GetByTypeId ¶ added in v0.4.0
func (repo PostgresRepository) GetByTypeId(ctx context.Context, typeId string) (*ObjectType, error)
func (PostgresRepository) List ¶ added in v0.4.0
func (repo PostgresRepository) List(ctx context.Context, listParams middleware.ListParams) ([]ObjectType, error)
func (PostgresRepository) UpdateByTypeId ¶ added in v0.4.0
func (repo PostgresRepository) UpdateByTypeId(ctx context.Context, typeId string, objectType ObjectType) error
type RelationRule ¶
type RelationRule struct {
InheritIf string `json:"inheritIf,omitempty" validate:"required_with=Rules OfType WithRelation,valid_inheritif"`
Rules []RelationRule `json:"rules,omitempty" validate:"required_if_oneof=InheritIf anyOf allOf noneOf,omitempty,min=1,dive"` // Required if InheritIf is "anyOf", "allOf", or "noneOf", empty otherwise
OfType string `json:"ofType,omitempty" validate:"required_with=WithRelation,valid_relation"`
WithRelation string `json:"withRelation,omitempty" validate:"required_with=OfType,valid_relation"`
}
RelationRule type represents the rule or set of rules that imply a particular relation if met
type Source ¶
type Source struct {
DatabaseType string `json:"dbType" validate:"required"`
DatabaseName string `json:"dbName" validate:"required"`
Table string `json:"table" validate:"required"`
PrimaryKey []string `json:"primaryKey" validate:"min=1"`
ForeignKeys []ForeignKeySpec `json:"foreignKeys,omitempty"`
}
Click to show internal directories.
Click to hide internal directories.