Fixed lint
the build failed Details

This commit is contained in:
konrad 2017-11-08 10:55:17 +01:00 committed by kolaente
parent bbfb661bab
commit 64dd0ce2d0
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
38 changed files with 55 additions and 6 deletions

View File

@ -1,5 +1,6 @@
package models
// Author holds infos about an author
type Author struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"`
Forename string `xorm:"varchar(250)"`
@ -8,10 +9,12 @@ type Author struct {
Updated int64 `xorm:"updated"`
}
// TableName returns the table name for struct author
func (Author) TableName() string {
return "authors"
}
// AuthorBook holds the relation between an author and a books
type AuthorBook struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"`
AuthorID int64 `xorm:"int(11)"`
@ -21,10 +24,12 @@ type AuthorBook struct {
Updated int64 `xorm:"updated"`
}
// TableName returns the name for the relation author <-> book
func (AuthorBook) TableName() string {
return "authors_books"
}
// GetAuthorByID gets information about an author by its ID
func GetAuthorByID(id int64) (author Author, exists bool, err error) {
has, err := x.Id(id).Get(&author)

View File

@ -1,5 +1,6 @@
package models
// AddAuthor adds a new author based on an author struct
func AddAuthor(author Author) (newAuthor Author, err error) {
_, err = x.Insert(&author)

View File

@ -1,5 +1,6 @@
package models
// DeleteAuthorByID deletes an author by its ID
func DeleteAuthorByID(id int64) error {
// Delete the author
_, err := x.Id(id).Delete(&Author{})

View File

@ -1,5 +1,6 @@
package models
// ListAuthors returns a list with all authors, filtered by an optional searchstring
func ListAuthors(searchterm string) (authors []Author, err error) {
if searchterm == "" {

View File

@ -1,5 +1,6 @@
package models
// UpdateAuthor updates an author by its ID and a new author struct
func UpdateAuthor(author Author, id int64) (newAuthor Author, err error) {
_, err = x.Where("id = ?", id).Update(&author)

View File

@ -2,6 +2,7 @@ package models
import "fmt"
// Book holds a book
type Book struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"`
Title string `xorm:"varchar(250) not null"`
@ -17,11 +18,13 @@ type Book struct {
Authors []Author `xorm:"-"`
}
// TableName returns the name for the books table
func (Book) TableName() string {
return "books"
}
func GetBookById(ID int64) (book Book, exists bool, err error) {
// GetBookByID gets a Book by its ID
func GetBookByID(ID int64) (book Book, exists bool, err error) {
// Get the Book
has, err := x.ID(ID).Get(&book)

View File

@ -15,6 +15,7 @@ sie in die Datenbank eingetragen und mit dem Buch verknüpft.
*/
// AddBook adds a new book, it takes a book struct with author and publisher. Inserts them if they don't already exist
func AddBook(book Book) (newBook Book, err error) {
// Take Publisher, check if it exists. If not, insert it

View File

@ -1,5 +1,6 @@
package models
// DeleteBookByID deletes a book by its ID
func DeleteBookByID(id int64) error {
// Delete the book
_, err := x.Id(id).Delete(&Book{})

View File

@ -2,11 +2,13 @@ package models
import "fmt"
// BookPublisher struct to join books with publishers
type BookPublisher struct {
Book `xorm:"extends"`
Publisher `xorm:"extends"`
}
// ListBooks returns a list with all books, filtered by an optional searchstring
func ListBooks(searchterm string) (books []*Book, err error) {
if searchterm == "" {

View File

@ -5,6 +5,7 @@ import (
"os"
)
// Config holds the config struct
var Config struct {
Database struct {
Host string
@ -16,6 +17,7 @@ var Config struct {
JWTLoginSecret []byte
}
// SetConfig initianlises the config and publishes it for other functions to use
func SetConfig() error {
// File Checks

View File

@ -1,5 +1,6 @@
package models
// Message is a standard message
type Message struct {
Message string
}

View File

@ -2,7 +2,7 @@ package models
import (
"fmt"
_ "github.com/go-sql-driver/mysql"
_ "github.com/go-sql-driver/mysql" // Because.
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
)

View File

@ -1,5 +1,6 @@
package models
// Publisher holds publisher informations
type Publisher struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"`
Name string `xorm:"varchar(250) not null"`
@ -7,10 +8,12 @@ type Publisher struct {
Updated int64 `xorm:"updated"`
}
// TableName returns the table name for publishers struct
func (Publisher) TableName() string {
return "publishers"
}
// GetPublisherByID returns a publisher by its ID
func GetPublisherByID(id int64) (publisher Publisher, exists bool, err error) {
has, err := x.Id(id).Get(&publisher)

View File

@ -1,5 +1,6 @@
package models
// AddPublisher adds a publisher from a publisher struct
func AddPublisher(publisher Publisher) (newPublisher Publisher, err error) {
_, err = x.Insert(&publisher)

View File

@ -1,5 +1,6 @@
package models
// DeletePublisherByID deletes a publisher by its ID
func DeletePublisherByID(id int64) error {
// Delete the publisher
_, err := x.Id(id).Delete(&Publisher{})

View File

@ -1,5 +1,6 @@
package models
// ListPublishers returns a list with all publishers, filtered by an optional searchstring
func ListPublishers(searchterm string) (publishers []Publisher, err error) {
if searchterm == "" {

View File

@ -1,5 +1,6 @@
package models
// UpdatePublisher updates a publisher, takes an ID and a publisher struct with the new publisher infos
func UpdatePublisher(publisher Publisher, id int64) (newPublisher Publisher, err error) {
_, err = x.Where("id = ?", id).Update(&publisher)

View File

@ -5,6 +5,7 @@ import (
"golang.org/x/crypto/bcrypt"
)
// User holds information about an user
type User struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"`
Name string `xorm:"varchar(250)"`
@ -15,17 +16,18 @@ type User struct {
Updated int64 `xorm:"updated"`
}
// TableName returns the table name for users
func (User) TableName() string {
return "users"
}
// Hash a password
// HashPassword hashes a password
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
return string(bytes), err
}
// Check user credentials
// CheckUserCredentials checks user credentials
func CheckUserCredentials(username, password string) (User, error) {
// Check if the user exists
@ -36,7 +38,7 @@ func CheckUserCredentials(username, password string) (User, error) {
}
if !exists {
return User{}, fmt.Errorf("User does not exist!")
return User{}, fmt.Errorf("user does not exist")
}
// Check the users password

View File

@ -7,6 +7,7 @@ import (
"strconv"
)
// AuthorDelete is the handler for deleting an author
func AuthorDelete(c echo.Context) error {
id := c.Param("id")

View File

@ -7,6 +7,7 @@ import (
"strconv"
)
// AuthorShow is the handler to show an author
func AuthorShow(c echo.Context) error {
author := c.Param("id")

View File

@ -8,6 +8,7 @@ import (
"strings"
)
// AuthorAdd is the handler to add an author
func AuthorAdd(c echo.Context) error {
// Check for Request Content
author := c.FormValue("author")

View File

@ -6,6 +6,7 @@ import (
"net/http"
)
// AuthorsList is the handler to list authors
func AuthorsList(c echo.Context) error {
list, err := models.ListAuthors("")

View File

@ -7,6 +7,7 @@ import (
"git.mowie.cc/konrad/Library/models"
)
// AuthorSearch is the handler to search for authors
func AuthorSearch(c echo.Context) error {
// Prepare the searchterm

View File

@ -9,6 +9,7 @@ import (
"strings"
)
// AuthorUpdate is the handler to update an author
func AuthorUpdate(c echo.Context) error {
// Check for Request Content
author := c.FormValue("author")

View File

@ -7,6 +7,7 @@ import (
"strconv"
)
// BookDelete is the handler to delete a book
func BookDelete(c echo.Context) error {
id := c.Param("id")

View File

@ -7,6 +7,7 @@ import (
"strconv"
)
// BookShow is the handler to show informations about a book
func BookShow(c echo.Context) error {
book := c.Param("id")

View File

@ -8,6 +8,7 @@ import (
"strings"
)
// BookAdd is the handler to add a book
func BookAdd(c echo.Context) error {
// Check for Request Content
book := c.FormValue("book")

View File

@ -7,6 +7,7 @@ import (
"git.mowie.cc/konrad/Library/models"
)
// BookList is the handler to list books
func BookList(c echo.Context) error {
list, err := models.ListBooks("")

View File

@ -7,6 +7,7 @@ import (
"git.mowie.cc/konrad/Library/models"
)
// BookSearch is the handler to search for books
func BookSearch(c echo.Context) error {
// Prepare the searchterm

View File

@ -7,6 +7,7 @@ import (
"strconv"
)
// PublisherShow is the handler to show informations about a publisher
func PublisherShow(c echo.Context) error {
publisher := c.Param("id")

View File

@ -8,6 +8,7 @@ import (
"strings"
)
// PublisherAdd is the handler to add a publisher
func PublisherAdd(c echo.Context) error {
// Check for Request Content
publisher := c.FormValue("publisher")

View File

@ -7,6 +7,7 @@ import (
"strconv"
)
// PublisherDelete is the handler to delete a publisher
func PublisherDelete(c echo.Context) error {
id := c.Param("id")

View File

@ -6,6 +6,7 @@ import (
"net/http"
)
// PublishersList is the handler to list publishers
func PublishersList(c echo.Context) error {
list, err := models.ListPublishers("")

View File

@ -7,6 +7,7 @@ import (
"git.mowie.cc/konrad/Library/models"
)
// PublisherSearch is the handler to search for a publisher
func PublisherSearch(c echo.Context) error {
// Prepare the searchterm

View File

@ -9,6 +9,7 @@ import (
"strings"
)
// PublisherUpdate is the handler to update a publishers information
func PublisherUpdate(c echo.Context) error {
// Check for Request Content
publisher := c.FormValue("publisher")

View File

@ -6,6 +6,7 @@ import (
"github.com/labstack/echo"
)
// CheckToken checks prints a message if the token is valid or not. Currently only used for testing pourposes.
func CheckToken(c echo.Context) error {
user := c.Get("user").(*jwt.Token)

View File

@ -8,6 +8,7 @@ import (
"time"
)
// Login is the login handler
func Login(c echo.Context) error {
username := c.FormValue("username")
password := c.FormValue("password")

View File

@ -8,6 +8,7 @@ import (
"git.mowie.cc/konrad/Library/models"
)
// NewEcho registers a new Echo instance
func NewEcho() *echo.Echo {
e := echo.New()
@ -22,6 +23,7 @@ func NewEcho() *echo.Echo {
return e
}
// RegisterRoutes registers all routes for the application
func RegisterRoutes(e *echo.Echo) {
// API Routes