k4cg / matomat-service

Matomat as a Service (MaaS)
MIT License
5 stars 2 forks source link

ItemsId controlled by Client when adding new Item #3

Closed noqqe closed 5 years ago

noqqe commented 5 years ago

Hi,

I recently tried to use the items_item_id_patch Method

https://github.com/k4cg/matomat-service/blob/master/maas-client-tty/swagger_client/api/items_api.py#L408

Its defined as

items_item_id_patch(self, item_id, name, cost, **kwargs)

So as a client, I need to calculate the item_id I want the drink to have in the future. Im not sure if this is intended. I would have assumed i just set name and cost and the item_id is being generated from the backend for my newly created item.

I wanted to bring that up for discussion. However, i did not want the user to be asked to type the item_id so i worked around this with this simple hack

# this is a quick hack for generating the latest drink id
itemsid = int(items_client.items_get()[-1].to_dict()["id"]) + 1

It fetches all Items, gets last object in list and adds 1 to the id

winterMate commented 5 years ago

Hi,

If i understand you correctly, you are trying to create a new item. To create a new item use POST. PATCH is only for updating. If you POST, you only need to specify name and costand on successful creation you'll get the id of the newly created item in the response.

.... in theory ;-)

noqqe commented 5 years ago

Ah, well. Thats right. Solved my problem.

Using items_post instead of items_item_id_patch now.