added comments

Signed-off-by: kolaente <konrad@kola-entertainments.de>
This commit is contained in:
konrad 2017-10-10 09:47:05 +02:00 committed by kolaente
parent 718f6bf6bb
commit 1249987e5f
3 changed files with 22 additions and 0 deletions

View File

@ -8,6 +8,8 @@ type Book struct {
Price float64 `xorm:"double"`
Status int64 `xorm:"int(11)"`
Publisher int64 `xorm:"int(11)"`
Created int64 `xorm:"created"`
Updated int64 `xorm:"updated"`
}
func (Book) TableName() string{

View File

@ -9,11 +9,13 @@ import (
)
func Add(c echo.Context) error {
// Check for Request Content
book := c.FormValue("book")
if book == "" {
return c.JSON(http.StatusBadRequest, models.Message{"No book model provided"})
}
// Decode the JSON
var bookstruct models.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"})
}
// Insert the book
err = models.AddBook(bookstruct)
if err != nil {

View File

@ -7,6 +7,7 @@ import (
"github.com/gorilla/sessions"
"github.com/labstack/echo-contrib/session"
"github.com/dgrijalva/jwt-go"
)
func NewEcho() *echo.Echo {
@ -30,14 +31,30 @@ func RegisterRoutes(e *echo.Echo) {
// API Routes
a := e.Group("/api/v1")
// Lookup Books
a.GET("/books/list", apiv1.List)
// Lookup Authors
// Lookup Publishers
// Login Route
e.POST("/login", Login)
// ===== Routes with Authetification =====
// Authetification
a.Use(middleware.JWT([]byte("secret")))
// Manage Books
a.POST("/books/add", apiv1.Add)
// Manage Authors
// Manage Publishers
// Manage Users
/*
Alles nur mit Api machen, davor dann einen onepager mit vue.js.