shopy

package module
v0.0.0-...-895c7f9 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2017 License: Apache-2.0 Imports: 16 Imported by: 5

README

Shopy

Build Documentation Go Report Card

Get the environment ready FOR DEVELOPMENT

Certify yourself that the variable GOPATH is set and that $GOPATH/bin is in your PATH.

  1. go get github.com/upframe/shopy
  2. cd $GOPATH/src/github.com/upframe/shopy/cmd/fest
  3. go install && shopy

Documentation

Index

Constants

View Source
const (
	// OrderCanceled represents the order canceled status.
	OrderCanceled = -1
	// OrderPaymentWaiting represents an waiting payment status.
	OrderPaymentWaiting = 0
	// OrderPaymentDone represents the payment done status.
	OrderPaymentDone = 1
	// OrderPaymentFailed represents the failed payment status.
	OrderPaymentFailed = 2
	// OrderUnfulfilled represents a unfulfilled order.
	OrderUnfulfilled = 0
	// OrderFulfilled represents a fulfilled order.
	OrderFulfilled = 1
)
View Source
const (
	// UpdateAll is used as a placeholder to update all of the fields
	UpdateAll = "#update#"
)

Variables

View Source
var (
	// ErrAlreadyLoggedIn ...
	ErrAlreadyLoggedIn = errors.New("The user is already logged in.")
	// ErrNotLoggedIn ...
	ErrNotLoggedIn = errors.New("The user is not logged in.")
	// ErrNotFound ...
	ErrNotFound = errors.New("Not found.")
)

Functions

func DisplayCents

func DisplayCents(cents int) string

DisplayCents ...

func InitPayPal

func InitPayPal(client, secret string, development bool) (*paypalsdk.Client, error)

InitPayPal configures the paypal client variable

func UniqueHash

func UniqueHash(phrase string) string

UniqueHash returns a SHA256 hash based on the string and on the current time

Types

type Cart

type Cart struct {
	RawList  map[int]int
	Products []*CartItem
	Locked   bool
}

Cart does exactly what is says

func (*Cart) FillProducts

func (c *Cart) FillProducts(service ProductService) error

FillProducts ...

func (Cart) GetDescription

func (c Cart) GetDescription() string

GetDescription is used for the payment procedure

func (Cart) GetTotal

func (c Cart) GetTotal() int

GetTotal display the order total price

type CartItem

type CartItem struct {
	*Product
	Quantity int
}

CartItem handles products and its quantity

func (CartItem) GetPrice

func (i CartItem) GetPrice() int

GetPrice displays the product price * quantity

type CartService

type CartService interface {
	Save(w http.ResponseWriter, c *Cart) error
	Get(w http.ResponseWriter, r *http.Request) (*Cart, error)
	Reset(w http.ResponseWriter) error
}

CartService ...

type Config

type Config struct {
	DefaultInvites int
	InviteOnly     bool
	Port           string
	BaseAddress    string
	Templates      string
	Domain         string
	Scheme         string
	Assets         string
	CookieStore    *securecookie.SecureCookie
	PayPal         *paypalsdk.Client
	Logger         *log.Logger
	Services       *Services
}

Config ...

type Email

type Email struct {
	From    *mail.Address
	To      *mail.Address
	Subject string
	Body    string
}

Email contains the information about email

type EmailService

type EmailService interface {
	UseTemplate(e *Email, data interface{}, template string) error
	Send(e *Email) error
}

EmailService ...

type Link struct {
	Hash    string     `db:"hash"`
	User    int        `db:"user_id"`
	Path    string     `db:"path"`
	Used    bool       `db:"used"`
	Time    *time.Time `db:"time"`
	Expires *time.Time `db:"expires"`
}

Link ...

func (Link) IsValid

func (l Link) IsValid() bool

IsValid returns if the link is still valid and not used

type LinkService

type LinkService interface {
	Get(hash string) (*Link, error)
	Gets(first, limit int, order string) ([]*Link, error)

	Create(l *Link) error
	Update(l *Link, fields ...string) error
	Delete(hash string) error
}

LinkService ...

type NullInt64

type NullInt64 struct {
	sql.NullInt64
}

NullInt64 is a wraper for sql.NullInt64 that works with JSON Unmarshal

func (NullInt64) MarshalJSON

func (v NullInt64) MarshalJSON() ([]byte, error)

MarshalJSON wraps the json.Marshal function

func (*NullInt64) UnmarshalJSON

func (v *NullInt64) UnmarshalJSON(data []byte) error

UnmarshalJSON wraps the json.Unmarshal function

type NullString

type NullString struct {
	sql.NullString
}

NullString is a wraper for sql.NullString that works with JSON Unmarshal

func (NullString) MarshalJSON

func (v NullString) MarshalJSON() ([]byte, error)

MarshalJSON wraps the json.Marshal function

func (*NullString) UnmarshalJSON

func (v *NullString) UnmarshalJSON(data []byte) error

UnmarshalJSON wraps the json.Unmarshal function

type Order

type Order struct {
	ID                int
	PayPal            string
	Value             int
	PaymentStatus     int16
	FulfillmentStatus int16
	Credits           int
	User              *User
	Promocode         *Promocode
	Products          []*OrderProduct
}

Order ...

func (*Order) FulfillmentStatusText

func (o *Order) FulfillmentStatusText() string

FulfillmentStatusText returns the text corresponding to the status variable.

func (*Order) PaymentStatusText

func (o *Order) PaymentStatusText() string

PaymentStatusText returns the text corresponding to the status variable.

type OrderProduct

type OrderProduct struct {
	ID       int
	Name     string
	Quantity int `db:"quantity"`
}

OrderProduct ...

type OrderService

type OrderService interface {
	Get(id int) (*Order, error)
	GetByPayPal(token string) (*Order, error)
	Gets(first, limit int, order string) ([]*Order, error)
	GetsWhere(first, limit int, order, where, sth string) ([]*Order, error)

	Total() (int, error)
	Create(o *Order) error
	Update(o *Order, fields ...string) error
	Delete(id int) error
}

OrderService ...

type Product

type Product struct {
	ID          int    `db:"id"`
	Name        string `db:"name"`
	Description string `db:"description"`
	Price       int    `db:"price"`
	Picture     string `db:"picture"`
	Deactivated bool   `db:"deactivated"`
}

Product ...

type ProductService

type ProductService interface {
	Get(id int) (*Product, error)
	Gets(first, limit int, order string) ([]*Product, error)
	GetsWhere(first, limit int, order, where, sth string) ([]*Product, error)
	GetsWhereIn(first, limit int, order, where, in string) ([]*Product, error)

	Total() (int, error)
	Create(p *Product) error
	Update(p *Product, fields ...string) error
	Delete(id int) error
}

ProductService ...

type Promocode

type Promocode struct {
	ID          int        `db:"id"`
	Code        string     `db:"code"`
	Expires     *time.Time `db:"expires"`
	Discount    int        `db:"discount"`
	Percentage  bool       `db:"percentage"`
	Used        int        `db:"used"`
	MaxUsage    int        `db:"maxusage"`
	Deactivated bool       `db:"deactivated"`
}

Promocode ...

type PromocodeService

type PromocodeService interface {
	Get(id int) (*Promocode, error)
	GetByCode(code string) (*Promocode, error)
	Gets(first, limit int, order string) ([]*Promocode, error)

	Total() (int, error)
	Create(p *Promocode) error
	Update(p *Promocode, fields ...string) error
	Delete(id int) error
}

PromocodeService ...

type Services

type Services struct {
	Order     OrderService
	Product   ProductService
	Promocode PromocodeService
	User      UserService
	Link      LinkService
	Email     EmailService
	Session   SessionService
	Cart      CartService
}

Services ...

type Session

type Session struct {
	Logged bool
	User   *User
}

Session ...

type SessionService

type SessionService interface {
	Save(w http.ResponseWriter, sess *Session) error
	Get(w http.ResponseWriter, r *http.Request) (*Session, error)
	Reset(w http.ResponseWriter) error
}

SessionService ...

type User

type User struct {
	ID           int        `db:"id"`
	FirstName    string     `db:"first_name"`
	LastName     string     `db:"last_name"`
	Email        string     `db:"email"`
	Address      NullString `db:"address"`
	Invites      int        `db:"invites"`
	Credit       int        `db:"credit"`
	Confirmed    bool       `db:"confirmed"`
	Admin        bool       `db:"admin"`
	Referral     string     `db:"referral"`
	Referrer     NullInt64  `db:"referrer"`
	PasswordSalt string     `db:"password_salt" json:"-"`
	PasswordHash string     `db:"password_hash" json:"-"`
	Deactivated  bool       `db:"deactivated"`
}

User contains the information of an User

func (*User) CheckPassword

func (u *User) CheckPassword(password string) (bool, error)

CheckPassword checks if the password of the user is correct

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword generates the salt and the hash of the user password

type UserService

type UserService interface {
	Get(id int) (*User, error)
	GetByEmail(email string) (*User, error)
	GetByReferral(referral string) (*User, error)
	Gets(first, limit int, order string) ([]*User, error)

	Total() (int, error)
	Create(u *User) error
	Update(u *User, fields ...string) error
	Delete(id int) error
}

UserService ...

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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