user

package
v0.0.0-...-f078915 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2024 License: BSD-3-Clause Imports: 11 Imported by: 1

README

user

import "github.com/blueprint-uservices/blueprint/examples/sockshop/workflow/user"

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

type Address

A street address

type Address struct {
    Street   string
    Number   string
    Country  string
    City     string
    PostCode string
    ID       string
}

type Card

A credit card

type Card struct {
    LongNum string
    Expires string
    CCV     string
    ID      string
}

type User

A user with an account. Accounts are optional for ordering.

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:"-,omitempty" bson:"-"`
    Cards     []Card    `json:"-,omitempty" bson:"-"`
    UserID    string    `json:"id" bson:"-"`
    Salt      string    `json:"-" bson:"salt"`
}

type UserService

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.

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
}

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

Generated by gomarkdoc

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 Card

type Card struct {
	LongNum string
	Expires string
	CCV     string
	ID      string
}

A credit card

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

Jump to

Keyboard shortcuts

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