mongodb

package
v0.0.0-...-2dead57 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PermitCollectionName is the name of the permits collection.
	PermitCollectionName = "permits"

	// MongoObjectIDField is the default mongodb unique key.
	MongoObjectIDField = "_id"

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

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

	// PermitBSONReqIDField is the name of the reqID field in BSON.
	PermitBSONReqIDField = "reqID"

	// PermitBSONStatusField is the name of the reqID field in BSON.
	PermitBSONStatusField = "status"
)

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"`
	Status string             `bson:"status,omitempty"`
	UserID string             `bson:"userID,omitempty"`
	ReqID  string             `bson:"reqID,omitempty"`
}

BSON is the struct that represents a permit as it's stored.

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) GetReqID

func (b BSON) GetReqID() string

GetReqID returns b.reqID.

func (BSON) GetStatus

func (b BSON) GetStatus() string

GetStatus returns b.Status.

func (BSON) GetUserID

func (b BSON) GetUserID() string

GetUserID returns b.UserID.

func (BSON) MarshalProto

func (b BSON) MarshalProto(permit *pb.PermitObject) error

MarshalProto marshals b into a permission.

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) SetReqID

func (b *BSON) SetReqID(reqID string) error

SetReqID sets b.ReqID to reqID.

func (*BSON) SetStatus

func (b *BSON) SetStatus(status string) error

SetStatus sets b.SharerID to status.

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 permisison service business logic implementation using MongoStore.

func NewMongoController

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

NewMongoController returns a new controller.

func (Controller) CreatePermit

func (c Controller) CreatePermit(ctx context.Context, reqID string, fileID string, userID string, status string) (service.Permit, error)

CreatePermit creates a permit in store and returns its unique ID.

func (Controller) GetPermitsByFileID

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

GetPermitsByFileID returns the statuses of the permits of each user associated with the fileID.

func (Controller) HasPermit

func (c Controller) HasPermit(ctx context.Context, fileID string, userID string) (bool, error)

HasPermit returns true if a permit exists with the given fileID and userID, and false if it does not.

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 occured.

func (Controller) UpdatePermitStatus

func (c Controller) UpdatePermitStatus(ctx context.Context, reqID string, status string) (bool, error)

UpdatePermitStatus todo

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, permit service.Permit) (service.Permit, error)

Create creates a permit of a file to a user, If permit already exists then its updated to have the permit values, If successful returns the permit and a nil error, otherwise returns empty string and non-nil error if any occurred.

func (MongoStore) Get

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

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

func (MongoStore) GetAll

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

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

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.

func (MongoStore) UpdateStatus

func (s MongoStore) UpdateStatus(ctx context.Context, reqID string, status string) error

UpdateStatus updates all permits with a given reqID to a given status

Jump to

Keyboard shortcuts

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