models

package
v0.0.0-...-14b83ed Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDB

func GetDB() *gorm.DB

func Login

func Login(email, password string) (map[string]interface{}, int)

Login takes an email and password and, if it matches a registered user, returns its information with the JWT. Status return parameter indicates if the log in was successful.

Types

type Account

type Account struct {
	gorm.Model
	Email    string `json:"email"`
	Password string `json:"password"`
	Admin    bool   `json:"admin"`
	Token    string `json:"token";sql:"-"`
}

a struct to rep user account

func GetUser

func GetUser(u uint) *Account

GetUser returns the information for user with id u or nil if the user does not exists. User password field, when user is found, is blank.

func GetUsers

func GetUsers() []Account

GetUsers returns all the registered users.

func (*Account) Create

func (account *Account) Create(admin bool) (map[string]interface{}, int)

Create generates a password, and JWToken for account and stores it in the DB.

func (*Account) Validate

func (account *Account) Validate() (map[string]interface{}, bool)

Validate incoming user details.

type Book

type Book struct {
	gorm.Model
	Name   string `json:"name"`
	Author string `json:"author"`
	ISBN   string `json:"isbn"`
}

func GetBook

func GetBook(isbn uint) *Book

func GetBooks

func GetBooks() ([]Book, int)

func (*Book) Create

func (book *Book) Create() (map[string]interface{}, int)

func (*Book) Validate

func (book *Book) Validate() (map[string]interface{}, bool)
This struct function validate the required parameters sent through the http request body

returns message and true if the requirement is met

type Review

type Review struct {
	gorm.Model
	Text     string `json:"text"`
	UserId   uint   `json:"user_id"`   //The user that this review belongs to
	BookISBN string `json:"book_isbn"` //The book that this review belongs to
}

func GetReviews

func GetReviews(isbn string) ([]Review, int)

GetReviews returns the reviews of the book associated with 'isbn' and the status code for the request Reviews are returned as a list or nil if no reviews are found.

func (*Review) Create

func (review *Review) Create() (map[string]interface{}, int)

func (*Review) Validate

func (review *Review) Validate() (map[string]interface{}, bool)

Validate checks that the struct function pass contains the required parameters sent through the http request body. Returns message and true if the requirement is met

type Token

type Token struct {
	UserId uint
	jwt.StandardClaims
}

JWT claims struct

Jump to

Keyboard shortcuts

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