Skip to content

feat: add stock balance endpoint#15

Open
jonasstenberg wants to merge 1 commit intoAlexGustafsson:mainfrom
jonasstenberg:main
Open

feat: add stock balance endpoint#15
jonasstenberg wants to merge 1 commit intoAlexGustafsson:mainfrom
jonasstenberg:main

Conversation

@jonasstenberg
Copy link

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.

@jonasstenberg
Copy link
Author

@AlexGustafsson friendly ping :)

@AlexGustafsson
Copy link
Owner

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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Successfully merging this pull request may close these issues.

2 participants