database

package
v0.0.0-...-91d8d9f Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	COL_CUSTOMERS     = "customers"
	COL_BOOKS         = "books"
	COL_CARTS         = "carts"
	COL_ORDERS        = "orders"
	COL_COMMENT       = "comments"
	COL_PAYMENT       = "payments"
	COL_SHIPPING_INFO = "shipping_infos"
	COL_STAFF         = "staffs"
)

Variables

This section is empty.

Functions

func GetMongoDB

func GetMongoDB() *mgo.Database

GetMongoDB ...

func InitMongo

func InitMongo()

InitMongo ...

Types

type Book

type Book struct {
	ID            bson.ObjectId `json:"id" bson:"_id,omitempty" form:"id,omitempty"`
	Title         string        `json:"title"`
	Description   string        `json:"description"`
	Organization  string        `json:"organization"`
	Author        string        `json:"author"`
	Inventory     uint64        `json:"inventory"`
	FromTime      uint64        `json:"from_time"`
	ToTime        uint64        `json:"to_time"`
	Price         uint64        `json:"price"`
	DiscountPrice uint64        `json:"discount_price"`
	CategoryName  string        `json:"category_name"`
	Images        []string      `json:"images"`
	Comments      []Comment     `json:"comments"`
}

Books ...

func CreateBook

func CreateBook(
	title, description, organization, author string,
	inventory, fromTime, toTime, price, discountPrice uint64,
	categoryName string, images []string, comments []Comment) (Book, error)

CreateBook ...

func (*Book) Delete

func (book *Book) Delete() error

func (*Book) Update

func (book *Book) Update(newBook Book) error

Update ...

type Cart

type Cart struct {
	ID     bson.ObjectId `json:"id" bson:"_id,omitempty" form:"id,omitempty"`
	Amount int           `json:"amount"`
	BookID bson.ObjectId `json:"book_id" bson:"_book_id,omitempty" form:"book_id,omitempty"`
}

Cart ...

func CreateCart

func CreateCart(amount int, bookID bson.ObjectId) (Cart, error)

CreateCart ...

type Comment

type Comment struct {
	ID          bson.ObjectId `json:"id" bson:"_id,omitempty" form:"id,omitempty"`
	ObjectID    bson.ObjectId `json:"object_id" bson:"_object_id,omitempty"`
	ObjectType  string        `json:"object_type"`
	Content     string        `json:"content"`
	CommentDate uint64        `json:"comment_date"`
	StatusReply bool          `json:"status_reply"`
}

Comment ...

func (*Comment) Delete

func (comment *Comment) Delete() error

func (*Comment) Update

func (comment *Comment) Update(newCommnent Comment) error

Update ...

type Customer

type Customer struct {
	ID        bson.ObjectId `json:"id" bson:"_id,omitempty" form:"id,omitempty"`
	Email     string        `json:"email" form:"email,omitempty"`
	Password  string        `json:"-" form:"-" bson:"password,omitempty"`
	FirstName string        `json:"first_name" form:"first_name,omitempty"`
	LastName  string        `json:"last_name" form:"last_name,omitempty"`
	Phone     string        `json:"phone" form:"phone,omitempty"`
	Username  string        `json:"username" form:"username,omitempty"`
	Avatar    string        `json:"avatar"`
	Carts     []Cart        `json:"carts"`
}

Customer ...

func CreateCustomer

func CreateCustomer(email string, password string) (Customer, error)

CreateCustomer ...

func (*Customer) RemoveCart

func (customer *Customer) RemoveCart(s int)

Remove ...

func (*Customer) Update

func (customer *Customer) Update(newCustomer *Customer) error

Update ...

type Order

type Order struct {
	ID          bson.ObjectId   `json:"id" bson:"_id,omitempty" form:"id,omitempty"`
	Note        string          `json:"note"`
	OrderDate   uint64          `json:"order_date"`
	ShippingFee uint64          `json:"shipping_fee"`
	Status      uint64          `json:"status"`
	BookIDs     []bson.ObjectId `json:"book_id" bson:"_book_id,omitempty"`
	Payment     Payment         `json:"payment"`
	CustomerID  bson.ObjectId   `json:"customer_id" bson:"_customer_id,omitempty"`
}

Order ...

func CreateOrder

func CreateOrder(
	note string,
	orderdate, shippingFee, status uint64,
	bookIDs []bson.ObjectId, payment Payment,
	customerID bson.ObjectId) (Order, error)

func GetAllOrders

func GetAllOrders() ([]Order, error)

GetAllOrders...

type Payment

type Payment struct {
	ID     bson.ObjectId `json:"id" bson:"_id,omitempty" form:"id,omitempty"`
	Method string        `json:"method"`
}

Payment ...

func CreatePayment

func CreatePayment(method string) (Payment, error)

CreatePayment ...

func (*Payment) Delete

func (payment *Payment) Delete() error

func (*Payment) Update

func (payment *Payment) Update(newPayment Payment) error

Update ...

type Staff

type Staff struct {
	ID        bson.ObjectId `json:"id" bson:"_id,omitempty" form:"id,omitempty"`
	Email     string        `json:"email" form:"email,omitempty"`
	Password  string        `json:"-" form:"-" bson:"password,omitempty"`
	FirstName string        `json:"first_name" form:"first_name,omitempty"`
	LastName  string        `json:"last_name" form:"last_name,omitempty"`
	Phone     string        `json:"phone" form:"phone,omitempty"`
	Username  string        `json:"username" form:"username,omitempty"`
	Position  string        `json:"position"`
	Avatar    string        `json:"avatar"`
}

Staff ...

func (*Staff) Delete

func (staff *Staff) Delete() error

Delete

func (*Staff) Update

func (staff *Staff) Update(newStaff Staff) error

Update ...

Jump to

Keyboard shortcuts

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