mongodb

package
v0.0.0-...-568b1a2 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MongoObjectIDField is the default mongodb unique key.
	MongoObjectIDField = "_id"

	// PermissionCollectionName is the name of the permissions collection.
	PermissionCollectionName = "permissions"

	// PermissionBSONFileIDField is the name of the fileID field in BSON.
	PermissionBSONFileIDField = "fileID"

	// PermissionBSONUserIDField is the name of the userID field in BSON.
	PermissionBSONUserIDField = "userID"

	// PermissionBSONRoleField is the name of the role field in BSON.
	PermissionBSONRoleField = "role"

	// PermissionBSONCreatorField is the name of the creator field in BSON.
	PermissionBSONCreatorField = "creator"

	// PermissionBSONAppIDField is the name of the appID field in BSON.
	PermissionBSONAppIDField = "appID"

	// PermissionBSONCreatedAtField is the name of the createdAt field in BSON.
	PermissionBSONCreatedAtField = "createdAt"

	// PermissionBSONUpdatedAtField is the name of the updatedAt field in BSON.
	PermissionBSONUpdatedAtField = "updatedAt"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BSON

type BSON struct {
	ID        primitive.ObjectID `bson:"_id,omitempty"`
	FileID    string             `bson:"fileID,omitempty"`
	UserID    string             `bson:"userID,omitempty"`
	Role      pb.Role            `bson:"role"`
	Creator   string             `bson:"creator"`
	AppID     string             `bson:"appID"`
	CreatedAt time.Time          `bson:"createdAt" json:"createdAt,omitempty"`
	UpdatedAt time.Time          `bson:"updatedAt" json:"updatedAt,omitempty"`
}

BSON is the structure that represents a permission as it's stored.

func (BSON) GetAppID

func (b BSON) GetAppID() string

GetAppID returns b.AppID.

func (BSON) GetCreatedAt

func (b BSON) GetCreatedAt() time.Time

GetCreatedAt returns b.CreatedAt.

func (BSON) GetCreator

func (b BSON) GetCreator() string

GetCreator returns b.Creator.

func (BSON) GetFileID

func (b BSON) GetFileID() string

GetFileID returns b.FileID.

func (BSON) GetID

func (b BSON) GetID() string

GetID returns the string value of the b.ID.

func (BSON) GetRole

func (b BSON) GetRole() pb.Role

GetRole returns b.Role.

func (BSON) GetUpdatedAt

func (b BSON) GetUpdatedAt() time.Time

GetUpdatedAt returns b.UpdatedAt.

func (BSON) GetUserID

func (b BSON) GetUserID() string

GetUserID returns b.UserID.

func (BSON) MarshalProto

func (b BSON) MarshalProto(permission *pb.PermissionObject) error

MarshalProto marshals b into a permission.

func (*BSON) SetAppID

func (b *BSON) SetAppID(appID string) error

SetAppID sets b.AppID to appID.

func (*BSON) SetCreator

func (b *BSON) SetCreator(creator string) error

SetCreator sets b.Creator to creator.

func (*BSON) SetFileID

func (b *BSON) SetFileID(fileID string) error

SetFileID sets b.FileID to fileID.

func (*BSON) SetID

func (b *BSON) SetID(id string) error

SetID sets the b.ID ObjectID's string value to id.

func (*BSON) SetRole

func (b *BSON) SetRole(role pb.Role) error

SetRole sets b.Role to role.

func (*BSON) SetUserID

func (b *BSON) SetUserID(userID string) error

SetUserID sets b.UserID to userID.

type Controller

type Controller struct {
	// contains filtered or unexported fields
}

Controller is the permissions service business logic implementation using MongoStore.

func NewMongoController

func NewMongoController(db *mongo.Database) (Controller, error)

NewMongoController returns a new controller.

func (Controller) CreatePermission

func (c Controller) CreatePermission(
	ctx context.Context,
	fileID string,
	userID string,
	role pb.Role,
	creator string,
	override bool,
	appID string) (service.Permission, error)

CreatePermission creates a Permission in store and returns its unique ID.

func (Controller) DeleteFilePermissions

func (c Controller) DeleteFilePermissions(ctx context.Context,
	fileID string) ([]*pb.PermissionObject, error)

DeleteFilePermissions deletes all permissions that exist for fileID and returns a slice of Permissions that were deleted.

func (Controller) DeletePermission

func (c Controller) DeletePermission(
	ctx context.Context,
	fileID string,
	userID string,
) (service.Permission, error)

DeletePermission deletes the permission in store that matches fileID and userID and returns the deleted permission.

func (Controller) GetByFileAndUser

func (c Controller) GetByFileAndUser(
	ctx context.Context,
	fileID string,
	userID string) (service.Permission, error)

GetByFileAndUser retrieves the permissoin that matches fileID and userID, and any error if occurred.

func (Controller) GetFilePermissions

func (c Controller) GetFilePermissions(ctx context.Context,
	fileID string) ([]*pb.GetFilePermissionsResponse_UserRole, error)

GetFilePermissions returns a slice of UserRole, otherwise returns nil and any error if occurred.

func (Controller) GetPermissionByMongoID

func (c Controller) GetPermissionByMongoID(
	ctx context.Context,
	mongoID string) (service.Permission, error)

GetPermissionByMongoID retrieves the permissoin by the recived mongo id.

func (Controller) GetUserPermissions

func (c Controller) GetUserPermissions(
	ctx context.Context,
	userID string, pageNum int64, pageSize int64, isShared bool, appID string) (*pb.GetUserPermissionsResponse, error)

GetUserPermissions returns a slice of FileRole, otherwise returns nil and any error if occurred.

func (Controller) HealthCheck

func (c Controller) HealthCheck(ctx context.Context) (bool, error)

HealthCheck runs store's healthcheck and returns true if healthy, otherwise returns false and any error if occurred.

type MongoStore

type MongoStore struct {
	DB *mongo.Database
}

MongoStore holds the mongodb database and implements Store interface.

func (MongoStore) Create

func (s MongoStore) Create(
	ctx context.Context,
	permission service.Permission,
	override bool,
) (service.Permission, error)

Create creates a permission of a file to a user, If permission already exists then it's updated to have permission values, If successful returns the permission and a nil error, Override indicates whether to update the permission if already exists, or not and return error. otherwise returns empty string and non-nil error if any occurred.

func (MongoStore) Delete

func (s MongoStore) Delete(ctx context.Context, filter interface{}) (service.Permission, error)

Delete finds the first permission that matches filter and deletes it, if successful returns the deleted permission, otherwise returns nil, and non-nil error if any occurred.

func (MongoStore) Get

func (s MongoStore) Get(ctx context.Context, filter interface{}) (service.Permission, error)

Get finds one permission that matches filter, if successful returns the permission, and a nil error, if the permission is not found it would return nil and NotFound error, otherwise returns nil and non-nil error if any occurred.

func (MongoStore) GetAll

func (s MongoStore) GetAll(ctx context.Context, filter interface{}) ([]service.Permission, error)

GetAll finds all permissions that matches filter, if successful returns the permissions, and a nil error, otherwise returns nil and non-nil error if any occurred.

func (MongoStore) GetUserPermissionsByPage

func (s MongoStore) GetUserPermissionsByPage(ctx context.Context, pn int64, ps int64, sortBy bson.D, filter interface{}) (*PagingRes, error)

GetUserPermissionsByPage returns a slice of the permissions requested by the filter, in the page they belong to by page number and page size. sortBy is the field by which the sorting of the permissions will be committed, defaulting to reverse mongoID.

func (MongoStore) HealthCheck

func (s MongoStore) HealthCheck(ctx context.Context) (bool, error)

HealthCheck checks the health of the service, returns true if healthy, or false otherwise.

type PagingRes

type PagingRes struct {
	// contains filtered or unexported fields
}

PagingRes is the struct of the result from the pagination requests

Jump to

Keyboard shortcuts

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