Space-Market / API

MIT License
7 stars 3 forks source link

barcodes #7

Open m0ppers opened 3 years ago

m0ppers commented 3 years ago

TL;DR: is the barcode a string or an integer?


I am having a hard time figuring out how the barcodes are intended.

I want to store a UUID foreign identifier for users in there (it is some unique user identifier specified in an app and being retrieved via NFC - we are still in the process of figuring out things so an integer is possible as well. but a UUID feels "nicer". so it is not a barcode but really just a foreign identifier)

Now the barcode creation (https://space-market.github.io/API/#tag/barcodes) specifies that the barcode should be a string (nice nice!):

Then the new barcode is being returned with an integer id and the barcode as a string. Apart from the fact that instead of returning the barcode directly it returns it wrapped in an array (which I am totally ok with - was just unexpected) this is exactly what I want.

But now I am confused about how to go on from here.

All the other APIs specify that the barcode should be an integer so apparently the resulting id and not the barcode as string is intended:

https://space-market.github.io/API/#tag/users%2Fpaths%2F~1users~1%7Bid%7D~1buy~1barcode~1%2Fpost https://space-market.github.io/API/#tag/users%2Fpaths%2F~1users~1barcode~1%7Bbarcode%7D~1%2Fget

There is no search operation specified on barcodes (something like /barcodes?barcode=MY_FANCY_UUID - in fact there is not even a list operation) so I can never really retrieve the barcode id with my external UUID and so I have to somehow save the space market barcode id in my external app or whatever.

Interestingly in v1 the barcode id was the string itself (which would ease things) however the id for buying something for the user was specified as being integer (https://space-market.github.io/API/preview/v1/#tag/users%2Fpaths%2F~1users~1%7Bid%7D~1buy_barcode.json%2Fpost) but my guess is that this was just a mistake and https://github.com/chaosdorf/mete just accepts the plain string (so nice).

Maybe you can clarify things? :S

YtvwlD commented 3 years ago

You are totally right. Real barcodes may contain any characters, so we would need to support this. Also, listing (and possibly) searching for barcodes by value would be very useful. It would be great if you could write a PR adding those and I'd be happy to review them (otherwise it's in my backlog, just like other things).

Yes, mete currently handles barcodes a bit differently, but we're in the (very slow) process to bring it up to this spec (see https://github.com/chaosdorf/mete/issues/52 for details).

uwap commented 1 year ago

Hey! I'm also unsure why they are even handled that way in the API. I'm in the process of implementing Space-Market API for Fnordcredit (Would be nice to have a common standard) and in Fnordcredit users have barcodes or RFID tokens and products also have barcodes. However, the barcodes for products are just | seperated strings. There are no id's attached to barcodes as they are tied to users or products. To me, it would make more sense if the API would return an array of barcodes for both users and products or null if none exist or it is not implemented.

I'm also a bit confused because according to the docs, the user actually returns a barcode field https://space-market.github.io/API/#tag/users%2Fpaths%2F~1users~1%2Fget but https://space-market.github.io/API/#tag/barcodes exists too. What's the recommended way to comply with the API here? Or should the specification maybe be adjusted to return an array tied to the user / product?