uppsaladatavetare / foobar-api

The backend of the FooBar kiosk and inventory system.
MIT License
12 stars 6 forks source link

Improve referencing in the API for the wallet and shop #12

Open flaeppe opened 7 years ago

flaeppe commented 7 years ago

UUID referencing in the wallet and shop models should be replaced to be more generic yet still more identifying.

A single UUID reference does not, in some cases, achieve enough object identification, whereas if we mimic a generic foreign key relation we can instead identify an object with its type and UUID.

This can all be done without exposing any underlying model(for wallet and shop), hence we can better protect against eventual sidestepping of their API and unwanted usage/behaviour.

kjagiello commented 7 years ago

Checklist:

flaeppe commented 7 years ago

This issue is going to be complicated to resolve before any adjustments to the following field on the WalletTransaction is in place:

reference = models.CharField(max_length=128, blank=True, null=True)

As this field can be filled in with custom text (i.e. Swishinsättning), it would not be wise to enforce stronger generic referencing with ContentType, as sometimes the reference is not a database object.

However, this argument assumes that the reference for a transaction should always be an object stored somewhere in the database.

The question here would be: Should we represent a reference like Swishinsättning differently? Is it enough with a CharField?

kjagiello commented 7 years ago

IMO we should. In a couple of months, as soon Länsförsäkringar has released Swish för handel, we will be in need of storing more metadata about Swish payments and a CharField won't be enough. Feels like the most natural way of solving this is to store the metadata in a separate table.