user

package
v0.0.0-...-ec63eb9 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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

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

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

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

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

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

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

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

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

Functions

func NewUserRepository

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

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

Types

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       primitive.ObjectID `bson:"_id,omitempty"`
	Name     string             `bson:"name" json:"name"`
	Email    string             `bson:"email" json:"email"`
	Username string             `bson:"username" json:"username"`
	Password Password           `bson:"inline" json:"password"`
}

The details of the user.

type UserRepository

type UserRepository interface {
	// Save saves the details of the user to the collection.
	Save(ctx context.Context, user *User) (*mongo.InsertOneResult, error)

	// GetByUsername fetches 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.
	UpdatePassword(
		ctx context.Context,
		username string,
		password *Password,
	) (*mongo.UpdateResult, error)
}

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

Jump to

Keyboard shortcuts

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