summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-09-25 15:35:49 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-09-25 15:35:49 +0530
commit511cd255e8754e54b0c3edc71e045f1bd7034ecf (patch)
tree3eff05244dd886fc8b83c636d68a140e590db76c
parent2326633e76aaf9c5e733e08045c0a26b81f9f4e6 (diff)
ACTUALLY added endpoints to add and delete data
-rw-r--r--brand/brand_router.go14
-rw-r--r--client/client_router.go14
-rw-r--r--item/item_router.go14
3 files changed, 42 insertions, 0 deletions
diff --git a/brand/brand_router.go b/brand/brand_router.go
index 3930931..74432dd 100644
--- a/brand/brand_router.go
+++ b/brand/brand_router.go
@@ -17,10 +17,24 @@ func Routes(route *gin.Engine) {
err := x.Save()
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
+ log.Printf("ERROR: Failed to add new brand \"%s\": %v", x.Name, err.Error())
}
log.Println("Added new brand to database: ", x.Name)
ctx.JSON(http.StatusOK, nil)
})
+
+ b.DELETE("/", func(ctx *gin.Context) {
+ var x brand.Brand
+ ctx.Bind(&x)
+ err := x.Delete()
+ if err != nil {
+ ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
+ log.Printf("ERROR: Failed to delete brand \"%s\": %v", x.Name, err.Error())
+ }
+
+ log.Println("Delete brand: ", x.Name)
+ ctx.JSON(http.StatusOK, nil)
+ })
}
}
diff --git a/client/client_router.go b/client/client_router.go
index 8b16f2e..a36ec48 100644
--- a/client/client_router.go
+++ b/client/client_router.go
@@ -16,10 +16,24 @@ func Routes(route *gin.Engine) {
err := x.Save()
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
+ log.Printf("ERROR: Failed to add new client \"%s\": %v", x.Name, err.Error())
}
log.Println("Added new client to database: ", x.Name)
ctx.JSON(http.StatusOK, nil)
})
+
+ c.DELETE("/", func(ctx *gin.Context) {
+ var x client.Client
+ ctx.Bind(&x)
+ err := x.Delete()
+ if err != nil {
+ ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
+ log.Printf("ERROR: Failed to delete client \"%s\": %v", x.Name, err.Error())
+ }
+
+ log.Println("Deleted client: ", x.Name)
+ ctx.JSON(http.StatusOK, nil)
+ })
}
}
diff --git a/item/item_router.go b/item/item_router.go
index b10c986..1af42c0 100644
--- a/item/item_router.go
+++ b/item/item_router.go
@@ -17,10 +17,24 @@ func Routes(route *gin.Engine) {
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.Println("Added new item to database: ", x.Name)
ctx.JSON(http.StatusOK, nil)
})
+
+ i.DELETE("/", func(ctx *gin.Context) {
+ var x item.Item
+ ctx.Bind(&x)
+ 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.Println("Deleted item: ", x.Name)
+ ctx.JSON(http.StatusOK, nil)
+ })
}
}