Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

put and post not working #35

Open
jwaldner opened this issue Jan 10, 2021 · 2 comments
Open

put and post not working #35

jwaldner opened this issue Jan 10, 2021 · 2 comments

Comments

@jwaldner
Copy link

after swagger and the client generation branches the validator does not work after a successful product is validated, it fails a bad sku or price fine. keeps returning empty requests on posts and puts. A giant refactor without vids to back it up 👎

this is code that i used git clone with no code I typed myself up to episode 8 i was typing it out and it was great for learning 👍

@kwiat1990
Copy link

@jwaldner POST can be fixed with this update. I've checked it and it does work properly.

At the same time I struggle to make PUT work. It keeps overriding the very first product (with ID 0) and it doesn't throw any errors if I try to update some non-existing product, which I thought is already covered with var ErrInvalidProductPath = fmt.Errorf("invalid Path, path should be /products/[id]") from handlers/products.go.

@kwiat1990
Copy link

kwiat1990 commented Jan 12, 2022

@jwaldner The PUT method doesn't work as intended because we never get the real ID of a product. The ID passed in with the context is only a placeholder and equals always to zero. To access the real value, we need to extract it from the URL with the help of getProductID function, which is also used inside DELETE handler. So it can be fixed with those minor changes (all we need is to get the real product ID):

	prod := r.Context().Value(KeyProduct{}).(*data.Product)
        prod.ID = getProductID(r)
	t.l.Println("[DEBUG] updating product id", prod.ID)

	err := data.UpdateProduct(*prod)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants