I'm working on a C # application that needs a queue of items of type Pedido
. Basically whenever a new request is created it is queued and the application shows the requests in sequential order that must be delivered. When a request is finalized it leaves the queue.
For the moment what I'm doing is basically keeping a enum
status property in the request class that when the request is created has StatusPedido.Enviado
value and when the request is delivered it has StatusPedido.Entregue
value. The queue therefore only includes items in the submitted state.
To persist this, the beginning is not difficult. My first idea was to create a DataModificacao
property in the requests and then sort the requests by the modification date reminding that queues are "first in first out". This way, the application will read the requests in the database, sort and assemble the queue.
So far so good, the problem is this: there is a requirement for users to be able to reorder the queue. This is because sometimes a request that can be delivered faster can be advanced and passed in front of others.
Doing this in code is easy. Basically it's just exchanging referrals and everything works. But what about persisting? Only modification date does not solve more, because when it loads the requests of the database will not have information of which were advanced. I thought of a new property that has the request ID that should come next, and a property containing a reference to the next request but I do not know if it's a good approach, because this seems more of a persistence implementation detail than something is part of the same domain.
In addition, a request when it is out of the queue (or before being queued, or after being delivered) no longer has this next, so the next request does not look like a property of class Pedido
even already that it only makes sense in certain cases.
How can I keep this kind of thing going: a queue that can be reordered and needs to be persisted?