diff --git a/models/book.go b/models/book.go index 9c64345..b6b1a5f 100644 --- a/models/book.go +++ b/models/book.go @@ -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{ diff --git a/routes/api/v1/books_add.go b/routes/api/v1/books_add.go index 3f1dff3..76039a2 100644 --- a/routes/api/v1/books_add.go +++ b/routes/api/v1/books_add.go @@ -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 { diff --git a/routes/routes.go b/routes/routes.go index fe1bfd8..d3d5e19 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -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.