Skip to content

UpdateRecipes looses ID #8

@ChristianKniep

Description

@ChristianKniep

I am going through your Gin book and I reckon we loose the id when updating the pizza recipe in chapter02.

In the book example the PUT request does not include the ID and thus the ID is going to be empty in the resulting id filed.

Overwriting the ID with what came in from PUT solves this.

+++ b/chapter02/main.go
@@ -102,11 +102,11 @@ func UpdateRecipeHandler(c *gin.Context) {
                c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
                return
        }
-
+       recipe.ID = id
        index := -1
        for i := 0; i < len(recipes); i++ {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions