added comments
Signed-off-by: kolaente <konrad@kola-entertainments.de>
This commit is contained in:
parent
718f6bf6bb
commit
1249987e5f
|
@ -8,6 +8,8 @@ type Book struct {
|
||||||
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"`
|
||||||
|
Updated int64 `xorm:"updated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (Book) TableName() string{
|
func (Book) TableName() string{
|
||||||
|
|
|
@ -9,11 +9,13 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Add(c echo.Context) error {
|
func Add(c echo.Context) error {
|
||||||
|
// Check for Request Content
|
||||||
book := c.FormValue("book")
|
book := c.FormValue("book")
|
||||||
if book == "" {
|
if book == "" {
|
||||||
return c.JSON(http.StatusBadRequest, models.Message{"No book model provided"})
|
return c.JSON(http.StatusBadRequest, models.Message{"No book model provided"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decode the JSON
|
||||||
var bookstruct models.Book
|
var bookstruct models.Book
|
||||||
dec := json.NewDecoder(strings.NewReader(book))
|
dec := json.NewDecoder(strings.NewReader(book))
|
||||||
|
|
||||||
|
@ -22,6 +24,7 @@ func Add(c echo.Context) error {
|
||||||
return c.JSON(http.StatusInternalServerError, models.Message{"Error decoding book"})
|
return c.JSON(http.StatusInternalServerError, models.Message{"Error decoding book"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert the book
|
||||||
err = models.AddBook(bookstruct)
|
err = models.AddBook(bookstruct)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
"github.com/labstack/echo-contrib/session"
|
"github.com/labstack/echo-contrib/session"
|
||||||
|
"github.com/dgrijalva/jwt-go"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewEcho() *echo.Echo {
|
func NewEcho() *echo.Echo {
|
||||||
|
@ -30,14 +31,30 @@ func RegisterRoutes(e *echo.Echo) {
|
||||||
|
|
||||||
// API Routes
|
// API Routes
|
||||||
a := e.Group("/api/v1")
|
a := e.Group("/api/v1")
|
||||||
|
// Lookup Books
|
||||||
a.GET("/books/list", apiv1.List)
|
a.GET("/books/list", apiv1.List)
|
||||||
|
|
||||||
|
// Lookup Authors
|
||||||
|
|
||||||
|
// Lookup Publishers
|
||||||
|
|
||||||
// Login Route
|
// Login Route
|
||||||
e.POST("/login", Login)
|
e.POST("/login", Login)
|
||||||
|
|
||||||
|
|
||||||
|
// ===== Routes with Authetification =====
|
||||||
|
// Authetification
|
||||||
a.Use(middleware.JWT([]byte("secret")))
|
a.Use(middleware.JWT([]byte("secret")))
|
||||||
|
|
||||||
|
// Manage Books
|
||||||
a.POST("/books/add", apiv1.Add)
|
a.POST("/books/add", apiv1.Add)
|
||||||
|
|
||||||
|
// Manage Authors
|
||||||
|
|
||||||
|
// Manage Publishers
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue