Second commit
added few test, first api to add book
This commit is contained in:
31
main.go
31
main.go
@@ -1,30 +1,29 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
"gorm.io/gorm"
|
||||
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/api"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/config"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/db"
|
||||
"git.artlef.fr/PersonalLibraryManager/internal/model"
|
||||
)
|
||||
|
||||
func GetBookHandler(c *gin.Context, db *gorm.DB) {
|
||||
var books []model.Book
|
||||
db.Model(&model.Book{}).Find(&books)
|
||||
c.JSON(http.StatusOK, books)
|
||||
}
|
||||
|
||||
func main() {
|
||||
c := config.LoadConfig("plm.toml")
|
||||
db := db.Initdb(".", c.DemoDataPath)
|
||||
r := gin.Default()
|
||||
r.Use(cors.Default()) // All origins allowed by default
|
||||
r.GET("/books", func(c *gin.Context) {
|
||||
GetBookHandler(c, db)
|
||||
})
|
||||
r := setup(&c)
|
||||
r.Run(":" + c.Port)
|
||||
}
|
||||
|
||||
func setup(config *config.Config) *gin.Engine {
|
||||
db := db.Initdb(config.DatabaseFilePath, config.DemoDataPath)
|
||||
r := gin.Default()
|
||||
r.Use(cors.Default()) // All origins allowed by default
|
||||
r.GET("/books", func(c *gin.Context) {
|
||||
api.GetBooksHanderl(c, db)
|
||||
})
|
||||
r.POST("/book", func(c *gin.Context) {
|
||||
api.PostBookHandler(c, db)
|
||||
})
|
||||
return r
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user