I'm building an app where users can rotate a wheel of fortune. When they are lucky and get a specific field, they can win a coupon.
I wanted to store those coupons in firebase Firestore with following properties:
{
"code" : 381939,
"expire_date" : xxx,
"value" : 5,
"currency" : "EUR"
}
My thoughts were that when somebody rotates the wheel of fortune, a random coupon/document will be chosen from the database. If there aren't any coupons, the wheel of fortune should be inactive. So I think I need to place a button "check availability for coupons" or similar to check if there are any coupons left. When there are any, the wheel will be set to active.
Then there are two scenarios: 1) they win: The coupon will be assigned to the user and deleted from the database 2) they loose: The coupon will be stored back in the database.
Unfortunately I don't think that this will work pretty well, when lots of user want to use the wheel of fortune simultaneously because multiple users could read the same document/coupon.
So is it possible to "lock" a document, so nobody else can read it, after somebody reads it? Or how can I make sure that every user will read a different coupon/document from the database, so there aren't users sharing this coupon?
Hope you understand my question.
If you need any more information, just tell me.