Documentation ¶
Overview ¶
Package user implements the SockShop user microservice.
The service stores three kinds of information:
- user accounts
- addresses
- credit cards
The sock shop allows customers to check out without creating a user account; in this case the customer's address and credit card data will be stored without a user accont.
The UserService thus uses three collections for the above information. To get the data for a user also means more than one database call.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Address ¶
type Address struct { Street string Number string Country string City string PostCode string ID string }
A street address
type User ¶
type User struct { FirstName string `json:"firstName" bson:"firstName"` LastName string `json:"lastName" bson:"lastName"` Email string `json:"-" bson:"email"` Username string `json:"username" bson:"username"` Password string `json:"-" bson:"password,omitempty"` Addresses []Address `json:"addresses" bson:"-"` Cards []Card `json:"cards" bson:"-"` UserID string `json:"id" bson:"-"` Salt string `json:"-" bson:"salt"` }
A user with an account. Accounts are optional for ordering.
type UserService ¶
type UserService interface { // Log in to an existing user account. Returns an error if the password // doesn't match the registered password Login(ctx context.Context, username, password string) (User, error) // Register a new user account. // Returns the user ID Register(ctx context.Context, username, password, email, first, last string) (string, error) // Look up a user by id. If id is the empty string, returns all users. GetUsers(ctx context.Context, id string) ([]User, error) // Insert a (possibly new) user into the DB. Returns the user's ID PostUser(ctx context.Context, user User) (string, error) // Look up an address by id. If id is the empty string, returns all addresses. GetAddresses(ctx context.Context, id string) ([]Address, error) // Insert a (possibly new) address into the DB. Returns the address ID PostAddress(ctx context.Context, userid string, address Address) (string, error) // Look up a card by id. If id is the empty string, returns all cards. GetCards(ctx context.Context, cardid string) ([]Card, error) // Insert a (possibly new) card into the DB. Returns the card ID PostCard(ctx context.Context, userid string, card Card) (string, error) // Deletes an entity with ID id from the DB. // // entity can be one of "customers", "addresses", or "cards". // ID should be the id of the entity to delete Delete(ctx context.Context, entity string, id string) error }
UserService stores information about user accounts. Having a user account is optional, and not required for placing orders. UserService also stores addresses and credit card details used in orders that aren't associated with a user account.
func NewUserServiceImpl ¶
func NewUserServiceImpl(ctx context.Context, db backend.NoSQLDatabase) (UserService, error)
Creates a UserService implementation that stores user, address, and credit card information in a NoSQLDatabase.
Returns an error if unable to get the users, addresses, or cards collection from the DB