Documentation ¶
Index ¶
- Variables
- func AddBook(c *gin.Context)
- func AddUser(c *gin.Context)
- func AdminRequired(c *gin.Context)
- func AuthRequired(c *gin.Context)
- func BorrowBook(c *gin.Context)
- func ExtendDeadline(c *gin.Context)
- func FindBooks(c *gin.Context)
- func Login(c *gin.Context)
- func Logout(c *gin.Context)
- func Me(c *gin.Context)
- func RemoveBook(c *gin.Context)
- func RemoveUser(c *gin.Context)
- func ReturnBook(c *gin.Context)
- func ShowBook(c *gin.Context)
- func ShowBookList(c *gin.Context)
- func ShowBooks(c *gin.Context)
- func ShowBorrowed(c *gin.Context)
- func ShowHistory(c *gin.Context)
- func ShowOverdueList(c *gin.Context)
- func ShowUser(c *gin.Context)
- func ShowUsers(c *gin.Context)
- func Status(c *gin.Context)
- func UpdateBook(c *gin.Context)
- func UpdateUser(c *gin.Context)
- type AddBookInput
- type AddRecordInput
- type AddUserInput
- type FindBookInput
- type RemoveBookInput
- type UpdateBookInput
- type UpdateUserInput
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyLoggedIn = errors.New("auth: already logged in")
ErrAlreadyLoggedIn occurs when the user has already logged in
var ErrAuthFailed = errors.New("auth: incorrect password")
ErrAuthFailed occurs when the password is incorrect
var ErrBookBorrowed = errors.New("library: book already borrowed")
ErrBookBorrowed occurs when the user wants to borrow a book which has been borrowed before
var ErrBookNotBorrowed = errors.New("library: book not borrowed")
ErrBookNotBorrowed occurs when the user wants to return a book which has not been borrowed before
var ErrBookNotFound = errors.New("database: book not found")
ErrBookNotFound occurs when the queried book is not found
var ErrExceedMaxExtendTimes = errors.New("library: extended too many times")
ErrExceedMaxExtendTimes occurs when the user has extended the deadline too many times
var ErrExceedMaxOverdueBooks = errors.New("library: too many overdue books")
ErrExceedMaxOverdueBooks occurs when the user has too many overdue books, thus being suspended
var ErrInvalidSession = errors.New("auth: invalid session token, have you logged in?")
ErrInvalidSession occurs when the session token is not found or invalid
var ErrSaveSessionFailed = errors.New("auth: failed to save session")
ErrSaveSessionFailed occurs when failed to save session
ErrUnauthorized occurs when the user is unauthorized to perform the operation
var ErrUserNotExist = errors.New("auth: user not exist")
ErrUserNotExist occurs when the username is not found
var ErrUserNotFound = errors.New("database: user not found")
ErrUserNotFound occurs when the user is not found
var ErrUsernameExists = errors.New("database: username already exists")
ErrUsernameExists occurs when the username already exists
Functions ¶
func AdminRequired ¶
AdminRequired is a middleware that validates the session Admin privilege required
func AuthRequired ¶
AuthRequired is a middleware that validates the session User privilege required
func BorrowBook ¶
BorrowBook adds a new record to the database POST /user/books/:id
func ExtendDeadline ¶
ExtendDeadline extends the deadline to return a book PATCH /user/books/:id
func RemoveBook ¶
RemoveBook removes a book from the library DELETE /admin/books/:id
func RemoveUser ¶
RemoveUser removes a user from the database DELETE /admin/users/:id
func ReturnBook ¶
ReturnBook soft deletes the related record from the database DELETE /user/books/:id
func ShowBookList ¶
ShowBookList shows all books that the user has borrowed GET /user/books
func ShowBorrowed ¶
ShowBorrowed shows a book that the user has borrowed Deadline is also returned in data.return_date GET /user/books/:id
func ShowHistory ¶
ShowHistory shows all records of the user GET /user/history
func ShowOverdueList ¶
ShowOverdueList shows all overdue books that the user has borrowed GET /user/overdue
func UpdateBook ¶
UpdateBook updates data of a book PATCH /admin/books/:id
func UpdateUser ¶
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 ¶
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 ¶
UpdateUserInput is a schema that validates input to prevent invalid requests