This commit is contained in:
konrad 2017-11-07 16:35:10 +01:00 committed by kolaente
parent 110361361b
commit b4b0b737a3
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
39 changed files with 158 additions and 163 deletions

View File

@ -1,13 +1,13 @@
package main package main
import ( import (
"git.mowie.cc/konrad/Library/routes"
"git.mowie.cc/konrad/Library/models" "git.mowie.cc/konrad/Library/models"
"git.mowie.cc/konrad/Library/routes"
"fmt" "fmt"
) )
func main(){ func main() {
// Set Engine // Set Engine
err := models.SetEngine() err := models.SetEngine()

View File

@ -1,11 +1,11 @@
package models package models
type Author struct { type Author struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"` ID int64 `xorm:"int(11) autoincr not null unique pk"`
Forename string `xorm:"varchar(250)"` Forename string `xorm:"varchar(250)"`
Lastname string `xorm:"varchar(250) not null"` Lastname string `xorm:"varchar(250) not null"`
Created int64 `xorm:"created"` Created int64 `xorm:"created"`
Updated int64 `xorm:"updated"` Updated int64 `xorm:"updated"`
} }
func (Author) TableName() string { func (Author) TableName() string {
@ -13,9 +13,9 @@ func (Author) TableName() string {
} }
type AuthorBook struct { type AuthorBook struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"` ID int64 `xorm:"int(11) autoincr not null unique pk"`
AuthorID int64 `xorm:"int(11)"` AuthorID int64 `xorm:"int(11)"`
BookID int64 `xorm:"int(11)"` BookID int64 `xorm:"int(11)"`
Created int64 `xorm:"created"` Created int64 `xorm:"created"`
Updated int64 `xorm:"updated"` Updated int64 `xorm:"updated"`
@ -29,4 +29,4 @@ func GetAuthorByID(id int64) (author Author, exists bool, err error) {
has, err := x.Id(id).Get(&author) has, err := x.Id(id).Get(&author)
return author, has, err return author, has, err
} }

View File

@ -1,6 +1,6 @@
package models package models
func AddAuthor(author Author) (newAuthor Author, err error){ func AddAuthor(author Author) (newAuthor Author, err error) {
_, err = x.Insert(&author) _, err = x.Insert(&author)
if err != nil { if err != nil {
@ -11,4 +11,4 @@ func AddAuthor(author Author) (newAuthor Author, err error){
newAuthor, _, err = GetAuthorByID(author.ID) newAuthor, _, err = GetAuthorByID(author.ID)
return newAuthor, err return newAuthor, err
} }

View File

@ -1,6 +1,6 @@
package models package models
func DeleteAuthorByID(id int64) error { func DeleteAuthorByID(id int64) error {
// Delete the author // Delete the author
_, err := x.Id(id).Delete(&Author{}) _, err := x.Id(id).Delete(&Author{})
@ -9,7 +9,7 @@ func DeleteAuthorByID(id int64) error {
} }
// Delete all book relations associated with that author // Delete all book relations associated with that author
_, err = x.Delete(&AuthorBook{AuthorID:id}) _, err = x.Delete(&AuthorBook{AuthorID: id})
return err return err
} }

View File

@ -1,13 +1,12 @@
package models package models
func ListAuthors(searchterm string) (authors []Author, err error) { func ListAuthors(searchterm string) (authors []Author, err error) {
if searchterm == "" { if searchterm == "" {
err = x.Find(&authors) err = x.Find(&authors)
} else { } else {
err = x. err = x.
Where("forename LIKE ?", "%"+searchterm+"%"). Where("forename LIKE ?", "%"+searchterm+"%").
Or("lastname LIKE ?", "%"+searchterm+"%"). Or("lastname LIKE ?", "%"+searchterm+"%").
Find(&authors) Find(&authors)
} }
@ -16,4 +15,4 @@ func ListAuthors(searchterm string) (authors []Author, err error) {
} }
return authors, nil return authors, nil
} }

View File

@ -1,6 +1,6 @@
package models package models
func UpdateAuthor(author Author, id int64) (newAuthor Author, err error){ func UpdateAuthor(author Author, id int64) (newAuthor Author, err error) {
_, err = x.Where("id = ?", id).Update(&author) _, err = x.Where("id = ?", id).Update(&author)
if err != nil { if err != nil {
@ -11,4 +11,4 @@ func UpdateAuthor(author Author, id int64) (newAuthor Author, err error){
newAuthor, _, err = GetAuthorByID(id) newAuthor, _, err = GetAuthorByID(id)
return newAuthor, err return newAuthor, err
} }

View File

@ -3,25 +3,25 @@ package models
import "fmt" import "fmt"
type Book struct { type Book struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"` ID int64 `xorm:"int(11) autoincr not null unique pk"`
Title string `xorm:"varchar(250) not null"` Title string `xorm:"varchar(250) not null"`
Isbn string `xorm:"varchar(30)"` Isbn string `xorm:"varchar(30)"`
Year int64 `xorm:"int(11)"` Year int64 `xorm:"int(11)"`
Price float64 `xorm:"double"` Price float64 `xorm:"double"`
Status int64 `xorm:"int(11)"` Status int64 `xorm:"int(11)"`
Publisher int64 `xorm:"int(11)"` Publisher int64 `xorm:"int(11)"`
Created int64 `xorm:"created"` Created int64 `xorm:"created"`
Updated int64 `xorm:"updated"` Updated int64 `xorm:"updated"`
PublisherFull Publisher `xorm:"-"` PublisherFull Publisher `xorm:"-"`
Authors []Author `xorm:"-"` Authors []Author `xorm:"-"`
} }
func (Book) TableName() string{ func (Book) TableName() string {
return "books" return "books"
} }
func GetBookById(ID int64) (book Book, exists bool, err error) { func GetBookById(ID int64) (book Book, exists bool, err error) {
// Get the Book // Get the Book
has, err := x.ID(ID).Get(&book) has, err := x.ID(ID).Get(&book)
@ -36,7 +36,7 @@ func GetBookById(ID int64) (book Book, exists bool, err error) {
// Get all authors // Get all authors
var authors []Author var authors []Author
err = x. err = x.
Table("authors_books"). Table("authors_books").
Select("authors.*"). Select("authors.*").
Join("INNER", "authors", "authors_books.author_id = authors.id"). Join("INNER", "authors", "authors_books.author_id = authors.id").
Where("book_id = ?", book.ID). Where("book_id = ?", book.ID).
@ -49,4 +49,4 @@ func GetBookById(ID int64) (book Book, exists bool, err error) {
book.Authors = authors book.Authors = authors
return book, has, err return book, has, err
} }

View File

@ -13,7 +13,7 @@ die Datenbank eingetragen und mit dem Buch verknüpft.
Bei den Autoren wirdebenfalls überprüft, ob sie bereits existieren, wenn dem nicht so ist werden Bei den Autoren wirdebenfalls überprüft, ob sie bereits existieren, wenn dem nicht so ist werden
sie in die Datenbank eingetragen und mit dem Buch verknüpft. sie in die Datenbank eingetragen und mit dem Buch verknüpft.
*/ */
func AddBook(book Book) (newBook Book, err error) { func AddBook(book Book) (newBook Book, err error) {

View File

@ -1,6 +1,6 @@
package models package models
func DeleteBookByID(id int64) error { func DeleteBookByID(id int64) error {
// Delete the book // Delete the book
_, err := x.Id(id).Delete(&Book{}) _, err := x.Id(id).Delete(&Book{})
@ -9,7 +9,7 @@ func DeleteBookByID(id int64) error {
} }
// Delete all authors associated with that book // Delete all authors associated with that book
_, err = x.Delete(&AuthorBook{BookID:id}) _, err = x.Delete(&AuthorBook{BookID: id})
return err return err
} }

View File

@ -3,7 +3,7 @@ package models
import "fmt" import "fmt"
type BookPublisher struct { type BookPublisher struct {
Book `xorm:"extends"` Book `xorm:"extends"`
Publisher `xorm:"extends"` Publisher `xorm:"extends"`
} }
@ -11,19 +11,18 @@ func ListBooks(searchterm string) (books []*Book, err error) {
if searchterm == "" { if searchterm == "" {
err = x.Table("books"). err = x.Table("books").
//Join("INNER", "publishers", "books.publisher = publishers.id"). //Join("INNER", "publishers", "books.publisher = publishers.id").
Find(&books) Find(&books)
if err != nil { if err != nil {
fmt.Println("Error getting Books", err) fmt.Println("Error getting Books", err)
} }
} else { } else {
err = x.Where("title LIKE ?", "%" + searchterm + "%").Find(&books) err = x.Where("title LIKE ?", "%"+searchterm+"%").Find(&books)
if err != nil { if err != nil {
fmt.Println("Error getting Books", err) fmt.Println("Error getting Books", err)
} }
} }
// Get all authors and publishers // Get all authors and publishers
for i, book := range books { for i, book := range books {
@ -38,7 +37,7 @@ func ListBooks(searchterm string) (books []*Book, err error) {
// Get all authors // Get all authors
var authors []Author var authors []Author
err = x. err = x.
Table("authors_books"). Table("authors_books").
Join("INNER", "authors", "authors_books.author_id = authors.id"). Join("INNER", "authors", "authors_books.author_id = authors.id").
Where("book_id = ?", book.ID). Where("book_id = ?", book.ID).
Find(&authors) Find(&authors)

View File

@ -5,10 +5,10 @@ import (
"os" "os"
) )
var Config struct{ var Config struct {
Database struct{ Database struct {
Host string Host string
User string User string
Password string Password string
Database string Database string
} }
@ -16,7 +16,7 @@ var Config struct{
JWTLoginSecret []byte JWTLoginSecret []byte
} }
func SetConfig() error{ func SetConfig() error {
// File Checks // File Checks
if _, err := os.Stat("config.ini"); os.IsNotExist(err) { if _, err := os.Stat("config.ini"); os.IsNotExist(err) {
@ -35,4 +35,4 @@ func SetConfig() error{
Config.JWTLoginSecret = []byte(cfg.Section("General").Key("JWTSecret").String()) Config.JWTLoginSecret = []byte(cfg.Section("General").Key("JWTSecret").String())
return nil return nil
} }

View File

@ -1,5 +1,5 @@
package models package models
type Message struct{ type Message struct {
Message string Message string
} }

View File

@ -1,21 +1,20 @@
package models package models
import ( import (
"github.com/go-xorm/core"
_ "github.com/go-sql-driver/mysql"
"github.com/go-xorm/xorm"
"fmt" "fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/go-xorm/core"
"github.com/go-xorm/xorm"
) )
var x *xorm.Engine var x *xorm.Engine
func getEngine() (*xorm.Engine, error){ func getEngine() (*xorm.Engine, error) {
connStr := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true", connStr := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true",
"root", "jup2000", "127.0.0.1", "library2") "root", "jup2000", "127.0.0.1", "library2")
return xorm.NewEngine("mysql", connStr) return xorm.NewEngine("mysql", connStr)
} }
// SetEngine sets the xorm.Engine // SetEngine sets the xorm.Engine
func SetEngine() (err error) { func SetEngine() (err error) {
x, err = getEngine() x, err = getEngine()

View File

@ -1,10 +1,10 @@
package models package models
type Publisher struct { type Publisher struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"` ID int64 `xorm:"int(11) autoincr not null unique pk"`
Name string `xorm:"varchar(250) not null"` Name string `xorm:"varchar(250) not null"`
Created int64 `xorm:"created"` Created int64 `xorm:"created"`
Updated int64 `xorm:"updated"` Updated int64 `xorm:"updated"`
} }
func (Publisher) TableName() string { func (Publisher) TableName() string {
@ -15,4 +15,4 @@ func GetPublisherByID(id int64) (publisher Publisher, exists bool, err error) {
has, err := x.Id(id).Get(&publisher) has, err := x.Id(id).Get(&publisher)
return publisher, has, err return publisher, has, err
} }

View File

@ -1,6 +1,6 @@
package models package models
func AddPublisher(publisher Publisher) (newPublisher Publisher, err error){ func AddPublisher(publisher Publisher) (newPublisher Publisher, err error) {
_, err = x.Insert(&publisher) _, err = x.Insert(&publisher)
if err != nil { if err != nil {
@ -10,4 +10,4 @@ func AddPublisher(publisher Publisher) (newPublisher Publisher, err error){
newPublisher, _, err = GetPublisherByID(publisher.ID) newPublisher, _, err = GetPublisherByID(publisher.ID)
return newPublisher, err return newPublisher, err
} }

View File

@ -1,6 +1,6 @@
package models package models
func DeletePublisherByID(id int64) error { func DeletePublisherByID(id int64) error {
// Delete the publisher // Delete the publisher
_, err := x.Id(id).Delete(&Publisher{}) _, err := x.Id(id).Delete(&Publisher{})
@ -12,8 +12,7 @@ func DeletePublisherByID(id int64) error {
//book := Book{Publisher:0} //book := Book{Publisher:0}
//book.Publisher = 0 //book.Publisher = 0
//_, err = x.Where("publisher = ?", id).Update(book) //_, err = x.Where("publisher = ?", id).Update(book)
_, err = x.Table("books").Where("publisher = ?", id).Update(map[string]interface{}{"publisher":0}) _, err = x.Table("books").Where("publisher = ?", id).Update(map[string]interface{}{"publisher": 0})
return err return err
} }

View File

@ -6,7 +6,7 @@ func ListPublishers(searchterm string) (publishers []Publisher, err error) {
err = x.Find(&publishers) err = x.Find(&publishers)
} else { } else {
err = x. err = x.
Where("name LIKE ?", "%" + searchterm + "%"). Where("name LIKE ?", "%"+searchterm+"%").
Find(&publishers) Find(&publishers)
} }
@ -15,4 +15,4 @@ func ListPublishers(searchterm string) (publishers []Publisher, err error) {
} }
return publishers, nil return publishers, nil
} }

View File

@ -1,6 +1,6 @@
package models package models
func UpdatePublisher(publisher Publisher, id int64) (newPublisher Publisher, err error){ func UpdatePublisher(publisher Publisher, id int64) (newPublisher Publisher, err error) {
_, err = x.Where("id = ?", id).Update(&publisher) _, err = x.Where("id = ?", id).Update(&publisher)
if err != nil { if err != nil {
@ -11,4 +11,4 @@ func UpdatePublisher(publisher Publisher, id int64) (newPublisher Publisher, err
newPublisher, _, err = GetPublisherByID(id) newPublisher, _, err = GetPublisherByID(id)
return newPublisher, err return newPublisher, err
} }

View File

@ -1,18 +1,18 @@
package models package models
import ( import (
"golang.org/x/crypto/bcrypt"
"fmt" "fmt"
"golang.org/x/crypto/bcrypt"
) )
type User struct { type User struct {
ID int64 `xorm:"int(11) autoincr not null unique pk"` ID int64 `xorm:"int(11) autoincr not null unique pk"`
Name string `xorm:"varchar(250)"` Name string `xorm:"varchar(250)"`
Username string `xorm:"varchar(250) not null"` Username string `xorm:"varchar(250) not null"`
Password string `xorm:"varchar(250) not null"` Password string `xorm:"varchar(250) not null"`
Email string `xorm:"varchar(250) not null"` Email string `xorm:"varchar(250) not null"`
Created int64 `xorm:"created"` Created int64 `xorm:"created"`
Updated int64 `xorm:"updated"` Updated int64 `xorm:"updated"`
} }
func (User) TableName() string { func (User) TableName() string {
@ -26,10 +26,10 @@ func HashPassword(password string) (string, error) {
} }
// Check user credentials // Check user credentials
func CheckUserCredentials (username, password string) (User, error) { func CheckUserCredentials(username, password string) (User, error) {
// Check if the user exists // Check if the user exists
var user = User{Username:username} var user = User{Username: username}
exists, err := x.Get(&user) exists, err := x.Get(&user)
if err != nil { if err != nil {
return User{}, err return User{}, err
@ -47,4 +47,4 @@ func CheckUserCredentials (username, password string) (User, error) {
} }
return user, nil return user, nil
} }

View File

@ -1,10 +1,10 @@
package v1 package v1
import ( import (
"github.com/labstack/echo"
"strconv"
"net/http"
"git.mowie.cc/konrad/Library/models" "git.mowie.cc/konrad/Library/models"
"github.com/labstack/echo"
"net/http"
"strconv"
) )
func AuthorDelete(c echo.Context) error { func AuthorDelete(c echo.Context) error {
@ -37,4 +37,4 @@ func AuthorDelete(c echo.Context) error {
} }
return c.JSON(http.StatusOK, models.Message{"success"}) return c.JSON(http.StatusOK, models.Message{"success"})
} }

View File

@ -1,9 +1,9 @@
package v1 package v1
import ( import (
"git.mowie.cc/konrad/Library/models"
"github.com/labstack/echo" "github.com/labstack/echo"
"net/http" "net/http"
"git.mowie.cc/konrad/Library/models"
"strconv" "strconv"
) )

View File

@ -1,10 +1,10 @@
package v1 package v1
import ( import (
"encoding/json"
"git.mowie.cc/konrad/Library/models"
"github.com/labstack/echo" "github.com/labstack/echo"
"net/http" "net/http"
"git.mowie.cc/konrad/Library/models"
"encoding/json"
"strings" "strings"
) )

View File

@ -1,18 +1,18 @@
package v1 package v1
import ( import (
"git.mowie.cc/konrad/Library/models"
"github.com/labstack/echo" "github.com/labstack/echo"
"net/http" "net/http"
"git.mowie.cc/konrad/Library/models"
) )
func AuthorsList(c echo.Context) error { func AuthorsList(c echo.Context) error {
list, err := models.ListAuthors("") list, err := models.ListAuthors("")
if err != nil{ if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting authors"}) return c.JSON(http.StatusInternalServerError, models.Message{"Error getting authors"})
} }
return c.JSON(http.StatusOK, list) return c.JSON(http.StatusOK, list)
} }

View File

@ -19,14 +19,14 @@ func AuthorSearch(c echo.Context) error {
// Get the Authors // Get the Authors
list, err := models.ListAuthors(search) list, err := models.ListAuthors(search)
if err != nil{ if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting authors"}) return c.JSON(http.StatusInternalServerError, models.Message{"Error getting authors"})
} }
// Check if we have any results // Check if we have any results
if len(list) == 0{ if len(list) == 0 {
return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any authors matching your search term"}) return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any authors matching your search term"})
} }
return c.JSON(http.StatusOK, list) return c.JSON(http.StatusOK, list)
} }

View File

@ -1,12 +1,12 @@
package v1 package v1
import ( import (
"encoding/json"
"git.mowie.cc/konrad/Library/models"
"github.com/labstack/echo" "github.com/labstack/echo"
"net/http" "net/http"
"git.mowie.cc/konrad/Library/models"
"encoding/json"
"strings"
"strconv" "strconv"
"strings"
) )
func AuthorUpdate(c echo.Context) error { func AuthorUpdate(c echo.Context) error {

View File

@ -1,10 +1,10 @@
package v1 package v1
import ( import (
"github.com/labstack/echo"
"strconv"
"net/http"
"git.mowie.cc/konrad/Library/models" "git.mowie.cc/konrad/Library/models"
"github.com/labstack/echo"
"net/http"
"strconv"
) )
func BookDelete(c echo.Context) error { func BookDelete(c echo.Context) error {
@ -37,4 +37,4 @@ func BookDelete(c echo.Context) error {
} }
return c.JSON(http.StatusOK, models.Message{"success"}) return c.JSON(http.StatusOK, models.Message{"success"})
} }

View File

@ -1,9 +1,9 @@
package v1 package v1
import ( import (
"git.mowie.cc/konrad/Library/models"
"github.com/labstack/echo" "github.com/labstack/echo"
"net/http" "net/http"
"git.mowie.cc/konrad/Library/models"
"strconv" "strconv"
) )
@ -30,4 +30,4 @@ func BookShow(c echo.Context) error {
} }
return c.JSON(http.StatusOK, bookInfo) return c.JSON(http.StatusOK, bookInfo)
} }

View File

@ -1,10 +1,10 @@
package v1 package v1
import ( import (
"encoding/json"
"git.mowie.cc/konrad/Library/models"
"github.com/labstack/echo" "github.com/labstack/echo"
"net/http" "net/http"
"git.mowie.cc/konrad/Library/models"
"encoding/json"
"strings" "strings"
) )

View File

@ -11,9 +11,9 @@ func BookList(c echo.Context) error {
list, err := models.ListBooks("") list, err := models.ListBooks("")
if err != nil{ if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"}) return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"})
} }
return c.JSON(http.StatusOK, list) return c.JSON(http.StatusOK, list)
} }

View File

@ -19,14 +19,14 @@ func BookSearch(c echo.Context) error {
// Get the Books // Get the Books
list, err := models.ListBooks(search) list, err := models.ListBooks(search)
if err != nil{ if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"}) return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"})
} }
// Check if we have any results // Check if we have any results
if len(list) == 0{ if len(list) == 0 {
return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any books matching your search term"}) return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any books matching your search term"})
} }
return c.JSON(http.StatusOK, list) return c.JSON(http.StatusOK, list)
} }

View File

@ -1,9 +1,9 @@
package v1 package v1
import ( import (
"git.mowie.cc/konrad/Library/models"
"github.com/labstack/echo" "github.com/labstack/echo"
"net/http" "net/http"
"git.mowie.cc/konrad/Library/models"
"strconv" "strconv"
) )

View File

@ -1,10 +1,10 @@
package v1 package v1
import ( import (
"encoding/json"
"git.mowie.cc/konrad/Library/models"
"github.com/labstack/echo" "github.com/labstack/echo"
"net/http" "net/http"
"git.mowie.cc/konrad/Library/models"
"encoding/json"
"strings" "strings"
) )

View File

@ -1,10 +1,10 @@
package v1 package v1
import ( import (
"github.com/labstack/echo"
"strconv"
"net/http"
"git.mowie.cc/konrad/Library/models" "git.mowie.cc/konrad/Library/models"
"github.com/labstack/echo"
"net/http"
"strconv"
) )
func PublisherDelete(c echo.Context) error { func PublisherDelete(c echo.Context) error {
@ -37,4 +37,4 @@ func PublisherDelete(c echo.Context) error {
} }
return c.JSON(http.StatusOK, models.Message{"success"}) return c.JSON(http.StatusOK, models.Message{"success"})
} }

View File

@ -1,18 +1,18 @@
package v1 package v1
import ( import (
"git.mowie.cc/konrad/Library/models"
"github.com/labstack/echo" "github.com/labstack/echo"
"net/http" "net/http"
"git.mowie.cc/konrad/Library/models"
) )
func PublishersList(c echo.Context) error { func PublishersList(c echo.Context) error {
list, err := models.ListPublishers("") list, err := models.ListPublishers("")
if err != nil{ if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publishers"}) return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publishers"})
} }
return c.JSON(http.StatusOK, list) return c.JSON(http.StatusOK, list)
} }

View File

@ -19,14 +19,14 @@ func PublisherSearch(c echo.Context) error {
// Get the Publishers // Get the Publishers
list, err := models.ListPublishers(search) list, err := models.ListPublishers(search)
if err != nil{ if err != nil {
return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publisher"}) return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publisher"})
} }
// Check if we have any results // Check if we have any results
if len(list) == 0{ if len(list) == 0 {
return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any publisher matching your search term"}) return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any publisher matching your search term"})
} }
return c.JSON(http.StatusOK, list) return c.JSON(http.StatusOK, list)
} }

View File

@ -1,12 +1,12 @@
package v1 package v1
import ( import (
"encoding/json"
"git.mowie.cc/konrad/Library/models"
"github.com/labstack/echo" "github.com/labstack/echo"
"net/http" "net/http"
"git.mowie.cc/konrad/Library/models"
"encoding/json"
"strings"
"strconv" "strconv"
"strings"
) )
func PublisherUpdate(c echo.Context) error { func PublisherUpdate(c echo.Context) error {

View File

@ -1,16 +1,16 @@
package v1 package v1
import ( import (
"github.com/labstack/echo"
"github.com/dgrijalva/jwt-go"
"fmt" "fmt"
"github.com/dgrijalva/jwt-go"
"github.com/labstack/echo"
) )
func CheckToken(c echo.Context) error { func CheckToken(c echo.Context) error {
user := c.Get("user").(*jwt.Token) user := c.Get("user").(*jwt.Token)
fmt.Println(user.Valid) fmt.Println(user.Valid)
return nil return nil
} }

View File

@ -1,11 +1,11 @@
package routes package routes
import ( import (
"github.com/labstack/echo"
"github.com/dgrijalva/jwt-go"
"time"
"net/http"
"git.mowie.cc/konrad/Library/models" "git.mowie.cc/konrad/Library/models"
"github.com/dgrijalva/jwt-go"
"github.com/labstack/echo"
"net/http"
"time"
) )
func Login(c echo.Context) error { func Login(c echo.Context) error {

View File

@ -1,9 +1,9 @@
package routes package routes
import ( import (
apiv1 "git.mowie.cc/konrad/Library/routes/api/v1"
"github.com/labstack/echo" "github.com/labstack/echo"
"github.com/labstack/echo/middleware" "github.com/labstack/echo/middleware"
apiv1 "git.mowie.cc/konrad/Library/routes/api/v1"
"git.mowie.cc/konrad/Library/models" "git.mowie.cc/konrad/Library/models"
) )
@ -44,7 +44,6 @@ func RegisterRoutes(e *echo.Echo) {
// Login Route // Login Route
e.POST("/login", Login) e.POST("/login", Login)
// ===== Routes with Authetification ===== // ===== Routes with Authetification =====
// Authetification // Authetification
a.Use(middleware.JWT(models.Config.JWTLoginSecret)) a.Use(middleware.JWT(models.Config.JWTLoginSecret))
@ -67,41 +66,41 @@ func RegisterRoutes(e *echo.Echo) {
// Manage Users // Manage Users
/* /*
Alles nur mit Api machen, davor dann einen onepager mit vue.js. Alles nur mit Api machen, davor dann einen onepager mit vue.js.
(Alles mit | benötigt Authentifizierung) (Alles mit | benötigt Authentifizierung)
Routes: Routes:
GET / - entweder übersicht anzeigen (wenn der nutzer eingeloggt ist) oder auf /login weiterleiten GET / - entweder übersicht anzeigen (wenn der nutzer eingeloggt ist) oder auf /login weiterleiten
POST /login - Einloggen POST /login - Einloggen
POST /logout - ausloggen POST /logout - ausloggen
GET /books/:id - Buch anzeigen GET /books/:id - Buch anzeigen
POST /books/:id - |Buch bearbeiten (inkl mengen) POST /books/:id - |Buch bearbeiten (inkl mengen)
DELETE /books/:id - |Buch löschen (+alle einträge in authors_books löschen dessen Bush dazu gehört) DELETE /books/:id - |Buch löschen (+alle einträge in authors_books löschen dessen Bush dazu gehört)
GET /books/search?s=se - Suchen GET /books/search?s=se - Suchen
GET /books/list - Auflisten GET /books/list - Auflisten
PUT /books/add - |Hinzufügen PUT /books/add - |Hinzufügen
GET /authors/:id - Autor anzeigen GET /authors/:id - Autor anzeigen
POST /authors/:id - |Autor bearbeiten POST /authors/:id - |Autor bearbeiten
DELETE /authors/:id - |Autor löschen (auch mit allem in books_author) DELETE /authors/:id - |Autor löschen (auch mit allem in books_author)
GET /authors/list - Autoren auflisten GET /authors/list - Autoren auflisten
GET /authors/search?s=d - Autoren suchen GET /authors/search?s=d - Autoren suchen
PUT /authors/add - |Hinzufügen PUT /authors/add - |Hinzufügen
GET /publishers/:id - Verlag anzeigen GET /publishers/:id - Verlag anzeigen
POST /publishers/:id - |Verlag bearbeiten POST /publishers/:id - |Verlag bearbeiten
DELETE /publishers/:id - |Verlag löschen (bei büchern Verlag auf 0 setzen) DELETE /publishers/:id - |Verlag löschen (bei büchern Verlag auf 0 setzen)
GET /publishers/list - Verlage auflisten GET /publishers/list - Verlage auflisten
GET /publishers/search?s= - Verlage suchen GET /publishers/search?s= - Verlage suchen
PUT /publishers/add - |Hinzufügen PUT /publishers/add - |Hinzufügen
GET /settings - |Nutzereinstellungen (Passwort, name etc) GET /settings - |Nutzereinstellungen (Passwort, name etc)
POST /settings - |Nutzereinstellungen (Passwort, name etc) POST /settings - |Nutzereinstellungen (Passwort, name etc)
GET /user - Nutzer anzeigen GET /user - Nutzer anzeigen
PUT /user - |neue Nutzer anlegen PUT /user - |neue Nutzer anlegen
DELETE /user/:id - |nutzer löschen DELETE /user/:id - |nutzer löschen
POST /user/:id - |nutzer bearbeiten POST /user/:id - |nutzer bearbeiten
*/ */
} }