Menu

One function defines not-found for our scanner, our capture gate and our reward check, because three copies of it drifted
📰

One function defines not-found for our scanner, our capture gate and our reward check, because three copies of it drifted

DEV Community: postgres·Daniel Pertu·4 days ago
#wezXlhGs
#devtopostgresql#devto#dev#capture#return
Reading 0:00
15s threshold

Munchable scans a barcode and checks the product against conditions the reader has. When the barcode is not in the catalogue, the app asks the reader to photograph the ingredients panel instead, and that capture becomes a row everyone else benefits from. Contributors get a subscription discount for finds.

That means a few hundred lines of code are answering questions like "is this barcode open for a capture", "what does an accepted capture do to the row that is already there", and "has this product actually been contributed, or does it merely exist". Getting those wrong does not throw. It quietly tells a user who just did the work that their product was not wanted, or it loses them a reward they earned.

Everything below lives in two files of pure functions with no I/O. The routes gather facts under a row lock and call them; the unit tests exercise the exact decision tables without a database.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.