summaryrefslogtreecommitdiff
path: root/controller/recipe.go
AgeCommit message (Collapse)Author
2024-04-07model: Add helper function for safe CRUDxengineering
This removes the redundant setup of a database/sql.Tx in each HTTP handler.
2024-04-06model: Always pass *sql.Tx to CRUD methodsxengineering
When nesting objects like steps into other objects like recipes it is required to pass a *sql.Tx value to the CRUD methods of the inner object to be able to roll back the whole transaction. The top level object used to be responsible for the creation of this *sql.Tx inside its CRUD methods. This is now moved to the caller of the CRUD methods (here the HTTP handler function). The advantage is that all CRUD methods now accept a *sql.Tx as only argument which makes those methods more consistent.
2024-03-12model: Remove .Touch() methodxengineering
The model package should never modify the data. Thus the functionality to update timestamps is moved to the controller package which is intended to modify data.
2024-03-05model: Move timestamp updates to controllerxengineering
The model package should handle the object relational mapping (ORM). This requires implementing the four CRUD methods: - create - read - update - delete On create and update the model package used to modify the timestamps like `last_changed`. This was detected by the unit tests which tested that the data is not changed in a create / read cycle or is updated correctly in an update / read cycle. This raised the question if it is a good idea that the model package is "smart" and updates timestamps. To keep the model package and the included unit tests simple the new design enforces that the complete data - including metadata - is always exactly the same after using any CRUD methods. The functionality of updating the timestamp is moved to the HTTP handler inside the controller package. This also matches the definition of the controller package as the part of the code which is alone responsible to actually change the data. This commit finally fixes the unit test suite.
2024-03-03view: Add recipe createxengineering
2024-03-03controller: Provide recipe create via HTTPxengineering
2024-03-03Add ID to URL in recipe updatesxengineering
This makes the update URL more consistent with the other ones. A check ensures consistency of the URL and JSON ID values.
2024-03-03controller: Provide recipe deletion via HTTPxengineering
2024-03-03controller: Update recipe based on JSONxengineering