database

package
v0.0.0-...-057e48f Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FindOne routineType = iota
	UpdateOne
	InsertOne
	DeleteOne
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlacklistService

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

BlacklistService is used by the app to manage all group related controllers and functionality

func NewBlacklistService

func NewBlacklistService(db DBClient, handler *DBHandler[*blacklistModel]) *BlacklistService

NewBlacklistService is an exported function used to initialize a new GroupService struct

func (*BlacklistService) BlacklistAuthToken

func (a *BlacklistService) BlacklistAuthToken(authToken string) error

BlacklistAuthToken is used during sign-out to add the now invalid auth-token/api key to the blacklist collection

func (*BlacklistService) CheckTokenBlacklist

func (a *BlacklistService) CheckTokenBlacklist(authToken string) bool

CheckTokenBlacklist to determine if the submitted Auth-Token or API-Key with what's in the blacklist collection

type DBClient

type DBClient interface {
	Connect() error
	Close() error
	GetBucket(bucketName string) (*gridfs.Bucket, error)
	GetCollection(collectionName string) DBCollection
	NewDBHandler(collectionName string) *DBHandler[dbModel]
	NewUserHandler() *DBHandler[*userModel]
	NewGroupHandler() *DBHandler[*groupModel]
	NewBlacklistHandler() *DBHandler[*blacklistModel]
	NewTaskHandler() *DBHandler[*taskModel]
	NewFileHandler() *DBHandler[*fileModel]
}

DBClient is an abstraction of the dbClient and testDBClient types

func InitializeNewClient

func InitializeNewClient() (DBClient, error)

InitializeNewClient returns an initialized DBClient based on the ENV

type DBCollection

type DBCollection interface {
	InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)
	InsertMany(ctx context.Context, documents []interface{}, opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error)
	DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
	FindOneAndDelete(ctx context.Context, filter interface{}, opts ...*options.FindOneAndDeleteOptions) *mongo.SingleResult
	UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	UpdateByID(ctx context.Context, id interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (cur *mongo.Cursor, err error)
	FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult
	CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error)
	DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
}

DBCollection is an abstraction of the dbClient and testDBClient types

type DBCursor

type DBCursor interface {
	Next(ctx context.Context) bool
	Decode(val interface{}) error
	Close(ctx context.Context) error
}

DBCursor is an abstraction of the dbClient and testDBClient types

type DBHandler

type DBHandler[T dbModel] struct {
	// contains filtered or unexported fields
}

DBHandler is a Generic type struct for organizing dbModel methods

func (*DBHandler[T]) DeleteMany

func (h *DBHandler[T]) DeleteMany(filter T) (T, error)

DeleteMany adds a new dbModel record to a collection

func (*DBHandler[T]) DeleteOne

func (h *DBHandler[T]) DeleteOne(filter T) (T, error)

DeleteOne adds a new dbModel record to a collection

func (*DBHandler[T]) FindMany

func (h *DBHandler[T]) FindMany(filter T) ([]T, error)

FindMany is used to get a slice of dbModels from the db with custom filter

func (*DBHandler[T]) FindOne

func (h *DBHandler[T]) FindOne(filter T) (T, error)

FindOne is used to get a dbModel from the db with custom filter

func (*DBHandler[T]) FindOneAsync

func (h *DBHandler[T]) FindOneAsync(tCh chan T, eCh chan error, filter T, wg *sync.WaitGroup)

FindOneAsync is used to get a dbModel from the db with custom filter

func (*DBHandler[T]) InsertOne

func (h *DBHandler[T]) InsertOne(m T) (T, error)

InsertOne adds a new dbModel record to a collection

func (*DBHandler[T]) UpdateOne

func (h *DBHandler[T]) UpdateOne(filter T, m T) (T, error)

UpdateOne Function to update a dbModel from datasource with custom filter and update model

type FileService

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

FileService is used by the app to manage all File related controllers and functionality

func NewFileService

func NewFileService(db DBClient, fHandler *DBHandler[*fileModel], uHandler *DBHandler[*userModel], gHandler *DBHandler[*groupModel]) *FileService

NewFileService is an exported function used to initialize a new FileService struct

func (*FileService) FileCreate

func (p *FileService) FileCreate(g *models.File, content []byte) (*models.File, error)

FileCreate creates a new GridFS File

func (*FileService) FileDelete

func (p *FileService) FileDelete(g *models.File) (*models.File, error)

FileDelete is used to delete a GridFS File

func (*FileService) FileDeleteMany

func (p *FileService) FileDeleteMany(g []*models.File) error

FileDeleteMany is used to delete a GridFS File

func (*FileService) FileFind

func (p *FileService) FileFind(g *models.File) (*models.File, error)

FileFind is used to find a specific file

func (*FileService) FileUpdate

func (p *FileService) FileUpdate(g *models.File, content []byte) (*models.File, error)

FileUpdate is used to update an existing File

func (*FileService) FilesFind

func (p *FileService) FilesFind(g *models.File) ([]*models.File, error)

FilesFind is used to find many files

func (*FileService) RetrieveFile

func (p *FileService) RetrieveFile(g *models.File) (*bytes.Buffer, error)

RetrieveFile returns the content bytes for a GridFS File

type GroupService

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

GroupService is used by the app to manage all group related controllers and functionality

func NewGroupService

func NewGroupService(db DBClient, handler *DBHandler[*groupModel]) *GroupService

NewGroupService is an exported function used to initialize a new GroupService struct

func (*GroupService) GroupCreate

func (p *GroupService) GroupCreate(g *models.Group) (*models.Group, error)

GroupCreate is used to create a new user group

func (*GroupService) GroupDelete

func (p *GroupService) GroupDelete(g *models.Group) (*models.Group, error)

GroupDelete is used to delete a group doc

func (*GroupService) GroupDeleteMany

func (p *GroupService) GroupDeleteMany(g *models.Group) (*models.Group, error)

GroupDeleteMany is used to delete many Groups

func (*GroupService) GroupDocInsert

func (p *GroupService) GroupDocInsert(g *models.Group) (*models.Group, error)

GroupDocInsert is used to insert a group doc directly into mongodb for testing purposes

func (*GroupService) GroupFind

func (p *GroupService) GroupFind(g *models.Group) (*models.Group, error)

GroupFind is used to find a specific group doc

func (*GroupService) GroupUpdate

func (p *GroupService) GroupUpdate(g *models.Group) (*models.Group, error)

GroupUpdate is used to update an existing group

func (*GroupService) GroupsFind

func (p *GroupService) GroupsFind(g *models.Group) ([]*models.Group, error)

GroupsFind is used to find all group docs in a MongoDB Collection

type TaskService

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

TaskService is used by the app to manage all Task related controllers and functionality

func NewTaskService

func NewTaskService(db DBClient, tHandler *DBHandler[*taskModel], uHandler *DBHandler[*userModel], gHandler *DBHandler[*groupModel]) *TaskService

NewTaskService is an exported function used to initialize a new TaskService struct

func (*TaskService) TaskCreate

func (p *TaskService) TaskCreate(g *models.Task) (*models.Task, error)

TaskCreate is used to create a new user Task

func (*TaskService) TaskDelete

func (p *TaskService) TaskDelete(g *models.Task) (*models.Task, error)

TaskDelete is used to delete a Task doc

func (*TaskService) TaskDeleteMany

func (p *TaskService) TaskDeleteMany(g *models.Task) (*models.Task, error)

TaskDeleteMany is used to delete many Tasks

func (*TaskService) TaskDocInsert

func (p *TaskService) TaskDocInsert(g *models.Task) (*models.Task, error)

TaskDocInsert is used to insert a Task doc directly into mongodb for testing purposes

func (*TaskService) TaskFind

func (p *TaskService) TaskFind(g *models.Task) (*models.Task, error)

TaskFind is used to find a specific Task doc

func (*TaskService) TaskUpdate

func (p *TaskService) TaskUpdate(g *models.Task) (*models.Task, error)

TaskUpdate is used to update an existing Task

func (*TaskService) TasksFind

func (p *TaskService) TasksFind(g *models.Task) ([]*models.Task, error)

TasksFind is used to find all Task docs in a MongoDB Collection

type UserService

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

UserService is used by the app to manage all user related controllers and functionality

func NewUserService

func NewUserService(db DBClient, uHandler *DBHandler[*userModel], gHandler *DBHandler[*groupModel]) *UserService

NewUserService is an exported function used to initialize a new UserService struct

func (*UserService) AuthenticateUser

func (p *UserService) AuthenticateUser(u *models.User) (*models.User, error)

AuthenticateUser is used to authenticate users that are signing in

func (*UserService) UpdatePassword

func (p *UserService) UpdatePassword(u *models.User, currentPassword string, newPassword string) (*models.User, error)

UpdatePassword is used to update the currently logged-in user's password

func (*UserService) UserCreate

func (p *UserService) UserCreate(u *models.User) (*models.User, error)

UserCreate is used to create a new user

func (*UserService) UserDelete

func (p *UserService) UserDelete(u *models.User) (*models.User, error)

UserDelete is used to delete an User

func (*UserService) UserDeleteMany

func (p *UserService) UserDeleteMany(u *models.User) (*models.User, error)

UserDeleteMany is used to delete many Users

func (*UserService) UserDocInsert

func (p *UserService) UserDocInsert(u *models.User) (*models.User, error)

UserDocInsert is used to insert user doc directly into mongodb for testing purposes

func (*UserService) UserFind

func (p *UserService) UserFind(u *models.User) (*models.User, error)

UserFind is used to find a specific user doc

func (*UserService) UserUpdate

func (p *UserService) UserUpdate(u *models.User) (*models.User, error)

UserUpdate is used to update an existing user doc

func (*UserService) UsersFind

func (p *UserService) UsersFind(u *models.User) ([]*models.User, error)

UsersFind is used to find all user docs

Jump to

Keyboard shortcuts

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