controllers

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2020 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyLoggedIn = errors.New("auth: already logged in")

ErrAlreadyLoggedIn occurs when the user has already logged in

View Source
var ErrAuthFailed = errors.New("auth: incorrect password")

ErrAuthFailed occurs when the password is incorrect

View Source
var ErrBookBorrowed = errors.New("library: book already borrowed")

ErrBookBorrowed occurs when the user wants to borrow a book which has been borrowed before

View Source
var ErrBookNotBorrowed = errors.New("library: book not borrowed")

ErrBookNotBorrowed occurs when the user wants to return a book which has not been borrowed before

View Source
var ErrBookNotFound = errors.New("database: book not found")

ErrBookNotFound occurs when the queried book is not found

View Source
var ErrExceedMaxExtendTimes = errors.New("library: extended too many times")

ErrExceedMaxExtendTimes occurs when the user has extended the deadline too many times

View Source
var ErrExceedMaxOverdueBooks = errors.New("library: too many overdue books")

ErrExceedMaxOverdueBooks occurs when the user has too many overdue books, thus being suspended

View Source
var ErrInvalidSession = errors.New("auth: invalid session token, have you logged in?")

ErrInvalidSession occurs when the session token is not found or invalid

View Source
var ErrSaveSessionFailed = errors.New("auth: failed to save session")

ErrSaveSessionFailed occurs when failed to save session

View Source
var ErrUnauthorized = errors.New("auth: unauthorized")

ErrUnauthorized occurs when the user is unauthorized to perform the operation

View Source
var ErrUserNotExist = errors.New("auth: user not exist")

ErrUserNotExist occurs when the username is not found

View Source
var ErrUserNotFound = errors.New("database: user not found")

ErrUserNotFound occurs when the user is not found

View Source
var ErrUsernameExists = errors.New("database: username already exists")

ErrUsernameExists occurs when the username already exists

Functions

func AddBook

func AddBook(c *gin.Context)

AddBook adds a new book to the library POST /admin/books

func AddUser

func AddUser(c *gin.Context)

AddUser adds a new user to the database POST /admin/users

func AdminRequired

func AdminRequired(c *gin.Context)

AdminRequired is a middleware that validates the session Admin privilege required

func AuthRequired

func AuthRequired(c *gin.Context)

AuthRequired is a middleware that validates the session User privilege required

func BorrowBook

func BorrowBook(c *gin.Context)

BorrowBook adds a new record to the database POST /user/books/:id

func ExtendDeadline

func ExtendDeadline(c *gin.Context)

ExtendDeadline extends the deadline to return a book PATCH /user/books/:id

func FindBooks

func FindBooks(c *gin.Context)

FindBooks finds books by title / author / ISBN POST /books/find

func Login

func Login(c *gin.Context)

Login verifies user identity and saves the session token POST /login

func Logout

func Logout(c *gin.Context)

Logout removes the session token GET /logout

func Me

func Me(c *gin.Context)

Me shows the current logged-in user GET /user/me

func RemoveBook

func RemoveBook(c *gin.Context)

RemoveBook removes a book from the library DELETE /admin/books/:id

func RemoveUser

func RemoveUser(c *gin.Context)

RemoveUser removes a user from the database DELETE /admin/users/:id

func ReturnBook

func ReturnBook(c *gin.Context)

ReturnBook soft deletes the related record from the database DELETE /user/books/:id

func ShowBook

func ShowBook(c *gin.Context)

ShowBook shows the book of given ID GET /books/:id

func ShowBookList

func ShowBookList(c *gin.Context)

ShowBookList shows all books that the user has borrowed GET /user/books

func ShowBooks

func ShowBooks(c *gin.Context)

ShowBooks shows all books in the library GET /books

func ShowBorrowed

func ShowBorrowed(c *gin.Context)

ShowBorrowed shows a book that the user has borrowed Deadline is also returned in data.return_date GET /user/books/:id

func ShowHistory

func ShowHistory(c *gin.Context)

ShowHistory shows all records of the user GET /user/history

func ShowOverdueList

func ShowOverdueList(c *gin.Context)

ShowOverdueList shows all overdue books that the user has borrowed GET /user/overdue

func ShowUser

func ShowUser(c *gin.Context)

ShowUser shows the user of given ID GET /admin/users/:id

func ShowUsers

func ShowUsers(c *gin.Context)

ShowUsers shows all users in the library GET /admin/users

func Status

func Status(c *gin.Context)

Status shows the current login status GET /status

func UpdateBook

func UpdateBook(c *gin.Context)

UpdateBook updates data of a book PATCH /admin/books/:id

func UpdateUser

func UpdateUser(c *gin.Context)

UpdateUser updates data of a user PATCH /admin/users/:id

Types

type AddBookInput

type AddBookInput struct {
	Title     string `json:"title" binding:"required"`
	Author    string `json:"author"`
	Publisher string `json:"publisher"`
	ISBN      string `json:"isbn"`
}

AddBookInput is a schema that validates input to prevent invalid requests ID will be generated automatically

type AddRecordInput

type AddRecordInput struct {
	BorrowDate time.Time `json:"borrow_date"`
}

AddRecordInput is a schema that validates input to prevent invalid requests ID, UserID, BookID, ExtendTimes will be generated automatically BorrowDate will be set to current date if left blank

type AddUserInput

type AddUserInput struct {
	Username string `json:"username" binding:"required"`
	Password string `json:"password" binding:"required"`
	Level    uint   `json:"level" binding:"required"`
}

AddUserInput is a schema that validates input to prevent invalid requests ID will be generated automatically

type FindBookInput

type FindBookInput struct {
	Title  string `json:"title"`
	Author string `json:"author"`
	ISBN   string `json:"isbn"`
}

FindBookInput is a schema that validates input to prevent invalid requests

type RemoveBookInput

type RemoveBookInput struct {
	Message string `json:"message"`
}

RemoveBookInput is a schema that validates input to prevent invalid requests

type UpdateBookInput

type UpdateBookInput struct {
	Title     string `json:"title"`
	Author    string `json:"author"`
	Publisher string `json:"publisher"`
	ISBN      string `json:"isbn"`
}

UpdateBookInput is a schema that validates input to prevent invalid requests

type UpdateUserInput

type UpdateUserInput struct {
	Password string `json:"password"`
	Level    uint   `json:"level"`
}

UpdateUserInput is a schema that validates input to prevent invalid requests

Jump to

Keyboard shortcuts

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