mongodb

package
v0.0.0-...-d9c1e7a Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// DBName is the name of the database.
	DBName string `long:"dbname" env:"MONGODB_DB_NAME" default:"bob" description:"MongoDB database name"`
	// ConnectionUrl is the URL used to connect to the database.
	ConnectionURL string `long:"connectionurl" env:"MONGODB_CONNECTION_URL" description:"MongoDB connection URL"`
}

type MongoDB

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

MongoDB is the database handler for MongoDB. Implements db.DataStore.

func Connect

func Connect(ctx context.Context, cfg Config) (*MongoDB, error)

Connect connects to the database and returns a new *MongoDB instance.

func (*MongoDB) Close

func (m *MongoDB) Close() error

Close ends the connection to the database. Implements db.DataStore.

func (*MongoDB) CreateNewShortURL

func (m *MongoDB) CreateNewShortURL(userID, longURL, customShortURL string, isGuest bool) (*db.ShortURLInfo, error)

CreateNewShortURL creates a new short URL. "userID" is the user's email if they are logged in, otherwise it is the unique identifier for the guest user.

func (*MongoDB) CreateUser

func (m *MongoDB) CreateUser(username, email string, password []byte) error

CreateUser adds a new user to the database. The username must be unique and email must be unique. The password is hashed before being stored. Implements db.DataStore.

func (*MongoDB) LoginUser

func (m *MongoDB) LoginUser(email string, password []byte) (*db.UserInfo, error)

LoginUser logs a user in and returns a nil error if the user exists and the password is correct. Implements db.DataStore.

func (*MongoDB) RetrieveShortURLClicks

func (m *MongoDB) RetrieveShortURLClicks(shortURL string) ([]*db.ShortURLClick, error)

RetrieveShortURLClicks returns a list of complete click information for a short URL.

func (*MongoDB) RetrieveURLInfo

func (m *MongoDB) RetrieveURLInfo(shortURL string) (*db.ShortURLInfo, error)

RetrieveURLInfo fetches information about a short URL using the shortened URL. Implements db.DataStore.

func (*MongoDB) RetrieveUserInfo

func (m *MongoDB) RetrieveUserInfo(email string) (*db.UserInfo, error)

RetrieveUserInfo fetches information about a user using the email. Implements db.DataStore.

func (*MongoDB) RetrieveUserURLs

func (m *MongoDB) RetrieveUserURLs(email string) ([]*db.ShortURLInfo, error)

RetrieveUserURLs fetches all the shorted URLs for the specified user. Implements db.DataStore.

func (*MongoDB) ToggleShortLinkStatus

func (m *MongoDB) ToggleShortLinkStatus(shortURL string, disable bool) error

ToggleShortLinkStatus enables/disables a short link.

func (*MongoDB) UpdateShortURL

func (m *MongoDB) UpdateShortURL(shortURL, newLongURL string, click *db.ShortURLClick) error

UpdateShortURL updates the information for the specified short URL. This method is used for click update and link editing.

func (*MongoDB) UsernameExists

func (m *MongoDB) UsernameExists(username string) (bool, error)

UsernameExists checks if a username exists in the database. Implements db.DataStore.

Jump to

Keyboard shortcuts

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