user

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package user implements a user management system.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserDuplicate = errors.New("duplicate user")
	ErrUserNotFound  = errors.New("user not found")
)

Errors.

Functions

This section is empty.

Types

type FirestoreManager

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

FirestoreManager is an UserManager implementation that uses firebase firestore as the underlying user information storage engine.

func NewFirestoreManager

func NewFirestoreManager(client *firestore.Client,
	collectionName string) *FirestoreManager

NewFirestoreManager creates a new FirestoreManager with the given firestore client and collection name.

func (*FirestoreManager) Add

func (m *FirestoreManager) Add(ctx context.Context, usr *User) (<-chan *User,
	<-chan error)

Add adds a user to the database of users.

Please note that a user is considered a duplicate if any of the following already exist on a different user: Email, PhoneNumber, and Username. The Add method will return ErrUserDuplicate in this case.

func (*FirestoreManager) Find

func (m *FirestoreManager) Find(ctx context.Context,
	queries ...datastore.Query) (<-chan *User, <-chan error)

Find finds the user based on the given query criterion.

If multiple queries are sent, the queries are combined with OR condition. Please refer to https://pkg.go.dev/github.com/qqiao/webapp/v2/datastore/firestore#Or for limitations of OR queries.

func (*FirestoreManager) Update

func (m *FirestoreManager) Update(ctx context.Context,
	usr *User) (<-chan *User, <-chan error)

Update updates the given user record.

Update will return ErrUserNotFound if the user cannot be found in the underlying datastore

type Manager

type Manager interface {
	// Add adds a user to the database of users.
	//
	// Please note that a user is considered a duplicate if any of the
	// following already exist on a different user: Email, PhoneNumber, and
	// Username. The Add method will return ErrUserDuplicate in this case.
	Add(ctx context.Context, user *User) (<-chan *User, <-chan error)

	// Find finds the user based on the given query criterion.
	//
	// If multiple queries are sent, the queries are combined with OR
	// condition. Please refer to https://pkg.go.dev/github.com/qqiao/webapp/v2/firebase/firestore#Or
	// for limitations of OR queries.
	Find(ctx context.Context, queries ...datastore.Query) (<-chan *User,
		<-chan error)

	// Update updates the given user record.
	//
	// Update will return ErrUserNotFound if the user cannot be found in the
	// underlying datastore
	Update(ctx context.Context, user *User) (<-chan *User, <-chan error)
}

Manager is responsible for all user related operations. This interface defines common operations for managing user records.

Depending on how users are stored and queried, there could be multiple implementations of the Manager interface.

type User

type User struct {
	DisplayName string `json:"displayName,omitempty"`
	Email       string `json:"email,omitempty"`
	Password    string `json:"password,omitempty"`
	PhoneNumber string `json:"phoneNumber,omitempty"`
	PhotoURL    string `json:"photoUrl,omitempty"`
	Suspended   bool   `json:"-"`
	UID         string `json:"uid,omitempty" firestore:"-"`
	Username    string `json:"username,omitempty"`
}

User represents a user record stored in the underlying datastore.

func NewUser

func NewUser() *User

NewUser returns a new User instance with all fields being blank.

func (*User) WithDisplayName

func (u *User) WithDisplayName(displayName string) *User

WithDisplayName sets the DisplayName of the user.

func (*User) WithEmail

func (u *User) WithEmail(email string) *User

WithEmail sets the Email of the user.

func (*User) WithPassword

func (u *User) WithPassword(password string) *User

WithPassword sets the Password of the user.

func (*User) WithPhoneNumber

func (u *User) WithPhoneNumber(phoneNumber string) *User

WithPhoneNumber sets the PhoneNumber of the user.

func (*User) WithPhotoURL

func (u *User) WithPhotoURL(photoURL string) *User

WithPhotoURL sets the PhotoURL of the user.

func (*User) WithSuspended

func (u *User) WithSuspended(suspended bool) *User

WithSuspended sets the Suspended of the user.

func (*User) WithUID

func (u *User) WithUID(uid string) *User

WithUID sets the UID of the user.

func (*User) WithUsername

func (u *User) WithUsername(username string) *User

WithUsername sets the Username of the user.

Jump to

Keyboard shortcuts

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