antikhonov / cashapp

0 stars 0 forks source link

Implementation of Transaction logic #4

Open antikhonov opened 9 years ago

antikhonov commented 9 years ago

Unlike other entities, the transactions affect other entities: accounts. Thus a decision needs to be made how to handle this logic. This needs to be done either in the Transaction class itslef or in the TransactionEntity class which actually acts as the transaction manager. The latter is preferred IMO.

Add basic functionality to the Transaction and TransactionEntity classes.

  1. Add possibility to commit and rollback a transaction;
  2. Prevent transactions to be commited and rolled back many times. Will define two flags for that.
antikhonov commented 9 years ago

Did the following. Added field "commited" to the Transaction class with default value of true. If the entity is fetched from the database, it is always true. If not, the constructor sets it to false.

antikhonov commented 9 years ago

Created test case for update. Transaction can be updated, but account balance id not. Need to deal with it.

antikhonov commented 9 years ago

Was mistaken. Update looks good. Current logic:

  1. Added Method to commit and rollback methods to the Transaction class and committed flag and
  2. Commit method is called by Doctrine for new entities;
  3. If a amount is changed on the committed transaction, it is first rolled back and then re-committed;
  4. Doctrine calls rollback method on delete;
antikhonov commented 9 years ago

Changed logic a little bit. getBalance method now returns the sum of initial amount and the balance

antikhonov commented 9 years ago

Now to deal with tags. Tags are passed as a string and needs to be parsed. Tags that are not found must be created.