user

package
v0.0.0-...-677f796 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCouldNotFetch = status.Error(
	codes.Internal,
	"error occurred while fetching the user",
)

ErrCouldNotFetch is a GRPC error that occurs when an unknown error occurs while fetching a user.

View Source
var ErrNotFound = status.Error(
	codes.NotFound,
	"no user with that username exists",
)

ErrNotFound is a GRPC error that occurs when the user was not found.

View Source
var ErrNotSaved = status.Error(
	codes.Internal,
	"could not save the user details",
)

ErrNotSaved is a GRPC error that occurs when an unknown error occurs while saving a user.

View Source
var ErrPasswordUpdate = status.Error(codes.Internal, "could not save password")

ErrPasswordUpdate is a GRPC error that occurs when the password could not be updated.

View Source
var ErrUserIDConvert = status.Error(
	codes.Internal,
	"could not convert user ID to expected format",
)

ErrUserIDConvert is a GRPC error that is returned when the user ID could not be converted to the expected type.

View Source
var ErrUsernameTaken = status.Error(codes.AlreadyExists, "username is taken")

ErrUsernameTaken is a GRPC error that occurs when attempting to save a new user and the provided username is taken.

Functions

This section is empty.

Types

type DataRepository

type DataRepository interface {
	// Save saves the details of the user to the collection and returns the ID
	// of the saved user.
	Save(ctx context.Context, user *User) (string, error)

	// GetByUsername gets the details of the user by their username.
	GetByUsername(ctx context.Context, username string) (*User, error)

	// UpdatePassword updates the password of the user by the username and
	// returns the number of records that were updated.
	UpdatePassword(
		ctx context.Context,
		username string,
		password *Password,
	) (uint, error)
}

DataRepository is an interface to the operations that can be performed on the users collection.

type MongoDataRepository

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

func NewUserRepository

func NewUserRepository(
	ctx context.Context,
	db *mongo.Database,
) (*MongoDataRepository, error)

NewUserRepository creates a new repository for performing database operations in the users collection.

func (*MongoDataRepository) GetByUsername

func (u *MongoDataRepository) GetByUsername(
	ctx context.Context,
	username string,
) (*User, error)

func (*MongoDataRepository) Save

func (u *MongoDataRepository) Save(
	ctx context.Context,
	user *User,
) (string, error)

func (*MongoDataRepository) UpdatePassword

func (u *MongoDataRepository) UpdatePassword(
	ctx context.Context,
	username string,
	password *Password,
) (uint, error)

type Password

type Password struct {
	Hash []byte `bson:"hash" json:"hash"`
	Salt []byte `bson:"salt" json:"salt"`
}

Password is the password information for a user. This struct will be inlined with the User struct.

type User

type User struct {
	ID       string
	Name     string
	Email    string
	Username string
	Password *Password
}

The details of the user.

Jump to

Keyboard shortcuts

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