Documentation ¶
Index ¶
- Constants
- type BSON
- func (b BSON) GetFileID() string
- func (b BSON) GetID() string
- func (b BSON) GetReqID() string
- func (b BSON) GetStatus() string
- func (b BSON) GetUserID() string
- func (b BSON) MarshalProto(permit *pb.PermitObject) error
- func (b *BSON) SetFileID(fileID string) error
- func (b *BSON) SetID(id string) error
- func (b *BSON) SetReqID(reqID string) error
- func (b *BSON) SetStatus(status string) error
- func (b *BSON) SetUserID(userID string) error
- type Controller
- func (c Controller) CreatePermit(ctx context.Context, reqID string, fileID string, userID string, status string) (service.Permit, error)
- func (c Controller) GetPermitsByFileID(ctx context.Context, fileID string) ([]*pb.UserStatus, error)
- func (c Controller) HasPermit(ctx context.Context, fileID string, userID string) (bool, error)
- func (c Controller) HealthCheck(ctx context.Context) (bool, error)
- func (c Controller) UpdatePermitStatus(ctx context.Context, reqID string, status string) (bool, error)
- type MongoStore
- func (s MongoStore) Create(ctx context.Context, permit service.Permit) (service.Permit, error)
- func (s MongoStore) Get(ctx context.Context, filter interface{}) (service.Permit, error)
- func (s MongoStore) GetAll(ctx context.Context, filter interface{}) ([]service.Permit, error)
- func (s MongoStore) HealthCheck(ctx context.Context) (bool, error)
- func (s MongoStore) UpdateStatus(ctx context.Context, reqID string, status string) error
Constants ¶
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) MarshalProto ¶
func (b BSON) MarshalProto(permit *pb.PermitObject) error
MarshalProto marshals b into a permission.
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 ¶
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 ¶
MongoStore holds the mongodb database and implements Store interface.
func (MongoStore) Create ¶
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 ¶
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 ¶
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 ¶
UpdateStatus updates all permits with a given reqID to a given status