mongodb

package
v0.0.0-...-f09e3b1 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoDB

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

MongoDB implements webserver.TaskDatabase.

func New

func New(ctx context.Context, connectionURL string, logger *slog.Logger) (*MongoDB, error)

New connects to a mongo database and returns a new instance of *MongoDB.

func (*MongoDB) CreateAccount

func (mdb *MongoDB) CreateAccount(username, password string) error

CreateAccount creates a new user with the provided username and password. An ErrorInvalidRequest will be returned is the username already exists.

func (*MongoDB) CreateTask

func (mdb *MongoDB) CreateTask(userID string, taskDetail string) ([]*db.Task, error)

CreateTask creates a new task entry for a user.

func (*MongoDB) DeleteTask

func (mdb *MongoDB) DeleteTask(userID, taskID string) ([]*db.Task, error)

DeleteTask removes an existing task from the record of the user that match the provided userID. If no task match the provided taskID, an ErrorInvalidRequest is returned.

func (*MongoDB) Login

func (mdb *MongoDB) Login(username, password string) (*db.User, error)

Login checks that the provided username and password matches a record in the database and are correct. Returns ErrorInvalidRequest if the password or username does not match any record.

func (*MongoDB) Shutdown

func (mdb *MongoDB) Shutdown(ctx context.Context) error

Shutdown attempts to shutdown the database.

func (*MongoDB) Tasks

func (mdb *MongoDB) Tasks(userID string) ([]*db.Task, error)

Tasks returns all the tasks created by the provided userID.

func (*MongoDB) TasksWithStatus

func (mdb *MongoDB) TasksWithStatus(userID string, completed bool) ([]*db.Task, error)

TasksWithStatus returns user tasks that matches the provided filter.

func (*MongoDB) UpdateTask

func (mdb *MongoDB) UpdateTask(userID, taskID string, newTaskDetail string, markAsComplete *bool) ([]*db.Task, error)

UpdateTask updates an existing task for the provided userID. If no task match the provided taskID, an ErrorInvalidRequest is returned.

Jump to

Keyboard shortcuts

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