feat: add stock balance endpoint#15
feat: add stock balance endpoint#15jonasstenberg wants to merge 1 commit intoAlexGustafsson:mainfrom
Conversation
|
@AlexGustafsson friendly ping :) |
|
Hi @jonasstenberg thanks for the PR, ping. Sorry about the delay. The code seems to work well and looks to fit in great with the existing code base (granted you're inheriting some perhaps questionable choices from my end). There's one issue I think we should adress before merging this; An item that does not exists returns the default value for each field; ./build/systembolaget stock --store-id 0605 --product-number x{
"productId": "x",
"storeId": "0605",
"stock": 0,
"shelf": ""
}The same goes for a store that does not exist ./build/systembolaget stock --store-id x --product-number 1{
"productId": "",
"storeId": "",
"stock": 0,
"shelf": ""
}Let's throw an error in those cases. |
| return nil, err | ||
| } | ||
|
|
||
| if res.StatusCode != http.StatusOK { |
There was a problem hiding this comment.
Interesting that the status code seems to be 200 in the error case as well. Here's the body in the error case:
{"productId":null,"storeId":null,"shelf":null,"stock":null,"isInStoreAssortment":false}I guess one solution is to have an internal stockBalance type that more closely follows the API;
type stockBalance struct {
ProductNumber *string `json:"productId"`
StoreID *string `json:"storeId"`
StockLevel int `json:"stock"`
Shelf *string `json:"shelf"`
}And then check if shelf etc. is nil, if it is, return some error. Otherwise, map the values onto the current StockBalance type.
Added stock balance API to retrieve stock level and shelf tag.
I'm by no means a professional Go developer so please review and be thorough.