Second commit

added few test, first api to add book
This commit is contained in:
2025-09-23 17:16:48 +02:00
parent 0457ca2011
commit 8432902df1
19 changed files with 298 additions and 123 deletions

27
internal/api/routes.go Normal file
View File

@@ -0,0 +1,27 @@
package api
import (
"net/http"
"git.artlef.fr/PersonalLibraryManager/internal/model"
"github.com/gin-gonic/gin"
"gorm.io/gorm"
)
func GetBooksHanderl(c *gin.Context, db *gorm.DB) {
var books []model.Book
db.Model(&model.Book{}).Find(&books)
c.JSON(http.StatusOK, books)
}
func PostBookHandler(c *gin.Context, db *gorm.DB) {
var book bookPostCreate
err := c.ShouldBindJSON(&book)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
bookDb := book.toBook()
db.Model(&model.Book{}).Save(&bookDb)
c.String(200, "Success")
}