diff options
Diffstat (limited to 'item/item_router.go')
-rw-r--r-- | item/item_router.go | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/item/item_router.go b/item/item_router.go index 1af42c0..f57dd2e 100644 --- a/item/item_router.go +++ b/item/item_router.go @@ -11,13 +11,24 @@ import ( func Routes(route *gin.Engine) { i := route.Group("/item") { + i.GET("/", func(ctx *gin.Context) { + // TODO: add functionality to filter results + items, err := item.GetItems(nil) + if err != nil { + ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + log.Printf("ERROR: Failed to read items from DB: %v\n", err.Error()) + } + + ctx.JSON(http.StatusOK, items) + }) + i.POST("/", func(ctx *gin.Context) { var x item.Item ctx.Bind(&x) err := x.Save() if err != nil { ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) - log.Printf("ERROR: Failed to add new item \"%s\": %v", x.Name, err.Error()) + log.Printf("ERROR: Failed to add new item \"%s\": %v\n", x.Name, err.Error()) } log.Println("Added new item to database: ", x.Name) @@ -30,7 +41,7 @@ func Routes(route *gin.Engine) { err := x.Delete() if err != nil { ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) - log.Printf("ERROR: Failed to delete item \"%s\": %v", x.Name, err.Error()) + log.Printf("ERROR: Failed to delete item \"%s\": %v\n", x.Name, err.Error()) } log.Println("Deleted item: ", x.Name) |