From d43b356fc302d61728a08f08dbdf474906e3fa82 Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Tue, 27 Sep 2022 22:36:29 +0530 Subject: added some PUT request handlers --- item/item_router.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'item/item_router.go') diff --git a/item/item_router.go b/item/item_router.go index cc58793..d86af68 100644 --- a/item/item_router.go +++ b/item/item_router.go @@ -55,6 +55,28 @@ func Routes(route *gin.Engine) { ctx.JSON(http.StatusOK, nil) }) + i.PUT("/:itemId", func(ctx *gin.Context) { + id := ctx.Param("itemId") + objectId, err := primitive.ObjectIDFromHex(id) + if err != nil { + ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) + log.Printf("ERROR: Failed to modify item, Error parsing ID: %v\n", err.Error()) + return + } + + var i item.Item + ctx.BindJSON(&i) + err = item.ModifyItem(objectId, i) + if err != nil { + ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) + log.Printf("ERROR: Failed to modify item %v: %v\n", objectId, err.Error()) + return + } + + log.Printf("Modified item %v to %v.\n", objectId, i) + ctx.JSON(http.StatusOK, nil) + }) + i.DELETE("/:itemId", func(ctx *gin.Context) { id := ctx.Param("itemId") objectId, err := primitive.ObjectIDFromHex(id) -- cgit v1.2.3