M
M
Michael2018-02-23 18:29:41
PHP
Michael, 2018-02-23 18:29:41

How does a repository work with API?

I'm trying repositories along with the API and already realized that I was facing a problem with object copies. There may be a situation when, for example, an order is loaded and used to count something (in essence, as a nested object) and the same order is updated through the form and repository->save, as a result, we have incorrect order data in the entity. As far as I understood, people use aggregate to solve this kind of problem. As a result, it is not clear:
1. What to do in a situation when, after loading data to update the data, an error occurred repository-> save (entity) in the infrastructure. What if you need to use real entity data and there is not saved data with an error? Probably, you need to load the data first into a copy of the entity, then try to save it, and then delete all the old entity objects and leave only the new one in their place.
2. Did I understand correctly that you need to write factories, root storage and work with all this in repositories so that all objects are stored in 1 place and there are only links to them from other places?
3. When editing the client's address in the order, it also changes for the client (as an example) => after repository->save(), the client's addresses will be incorrect or outdated. So the repository should remove the old client address objects?
Scheme:

API <=> ApiClient <=> Repository (entity) <=> Service <= Html forms

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
rPman, 2018-02-24
@rPman

I hardly understand what kind of problems you have and with which particular repository?
Divide all the work into atomic operations, between which your database will be in the correct state, and let a specially allocated part be responsible for execution and integrity control within the atomic operation - for example, transactional databases, or a dedicated service that blocks simultaneous work with the same the same data (there are locks on the entire database, on the data type / table and even on individual objects, this is a matter of choosing a tool)
When it comes to the interface, you will have to take care of problems and conflicts yourself, for example, an edit form can keep an open connection to the server and promptly inform everyone about changes and resolve conflicts.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question