diff --git a/models/authors_add.go b/models/authors_add.go index d8844eb..2330196 100644 --- a/models/authors_add.go +++ b/models/authors_add.go @@ -1,6 +1,14 @@ package models -func AddAuthor(author Author) (err error){ +func AddAuthor(author Author) (newAuthor Author, err error){ _, err = x.Insert(&author) - return err + + if err != nil { + return Author{}, err + } + + // Get the newly inserted author + newAuthor, _, err = GetAuthorByID(author.ID) + + return newAuthor, err } \ No newline at end of file diff --git a/models/books_add.go b/models/books_add.go index f0de99d..09eb1c3 100644 --- a/models/books_add.go +++ b/models/books_add.go @@ -1,6 +1,14 @@ package models -func AddBook(book Book) (err error){ +func AddBook(book Book) (newBook Book, err error){ _, err = x.Insert(&book) - return err + + if err != nil { + return Book{}, err + } + + // Get the newly inserted book + newBook, _, err = GetBookById(book.ID) + + return book, err } \ No newline at end of file diff --git a/routes/api/v1/authors_add.go b/routes/api/v1/authors_add.go index 50307e0..ef709f6 100644 --- a/routes/api/v1/authors_add.go +++ b/routes/api/v1/authors_add.go @@ -25,11 +25,11 @@ func AuthorAdd(c echo.Context) error { } // Insert the author - err = models.AddAuthor(authorstruct) + newAuthor, err := models.AddAuthor(authorstruct) if err != nil { return c.JSON(http.StatusInternalServerError, models.Message{"Error"}) } - return c.JSON(http.StatusOK, models.Message{"success"}) + return c.JSON(http.StatusOK, newAuthor) } diff --git a/routes/api/v1/books_add.go b/routes/api/v1/books_add.go index bff8b38..c75ba09 100644 --- a/routes/api/v1/books_add.go +++ b/routes/api/v1/books_add.go @@ -25,11 +25,11 @@ func BookAdd(c echo.Context) error { } // Insert the book - err = models.AddBook(bookstruct) + newBook, err := models.AddBook(bookstruct) if err != nil { return c.JSON(http.StatusInternalServerError, models.Message{"Error"}) } - return c.JSON(http.StatusOK, models.Message{"success"}) + return c.JSON(http.StatusOK, newBook) } diff --git a/routes/routes.go b/routes/routes.go index 7ec5c00..9bf5965 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -27,17 +27,17 @@ func RegisterRoutes(e *echo.Echo) { // API Routes a := e.Group("/api/v1") // Lookup Books - a.GET("/books/list", apiv1.BookList) + a.GET("/books", apiv1.BookList) a.GET("/books/:id", apiv1.BookShow) a.GET("/books/search", apiv1.BookSearch) // Lookup Authors - a.GET("/authors/list", apiv1.AuthorsList) + a.GET("/authors", apiv1.AuthorsList) a.GET("/authors/:id", apiv1.AuthorShow) a.GET("/authors/search", apiv1.AuthorSearch) // Lookup Publishers - a.GET("/publishers/list", apiv1.PublishersList) + a.GET("/publishers", apiv1.PublishersList) a.GET("/publishers/:id", apiv1.PublisherShow) a.GET("/publishers/search", apiv1.PublisherSearch) @@ -90,10 +90,10 @@ func RegisterRoutes(e *echo.Echo) { GET /publishers/:id - ✔ Verlag anzeigen 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/search?s= - ✔ Verlage suchen - PUT /publishers/add - |Hinzufügen + PUT /publishers/add - ✔ |Hinzufügen GET /settings - |Nutzereinstellungen (Passwort, name etc) POST /settings - |Nutzereinstellungen (Passwort, name etc)