I am trying to learn
Java Spring framework. I have been following some books and guides however they are all the standard ToDo ( HelloWorld ) type applications.
One topic that has commonly been untouched in the guides I have been following is how to update other system records upon the execution of crud operations of an entirely different (however usually related) record.
Here is a contrived example.
I have an object ToDo which is persisted in the database. I also have another object ToDoDailyReport which is persisted in the database ( ignore the fact that this could probably be calculated on the fly ).
If I execute any crud operation on a ToDo I would like to update the ToDoDailyReport
I am using spring-boot-starter-data-rest and creating CrudRepositories annotating them with @RepositoryRestResource similar to this example (
https://spring.io/guides/gs/accessing-data-rest/ )
I imagine I could create a bunch of custom controllers using @RestController and implement whatever behaviour I want however I like the idea of leaving their CrudRepositories as is and simply executing a function before or after the crud operation is fired. I have seen discussion of AOP and AspectJ however I am not sure if these approaches are meant for my use case or what approach I should be implementing and how I would fire a AOP advice before or after the crud operation.
My concern with custom controllers is that lets say coming back to my example I want to update the ToDoDailyReport every time a CRUD operation is executed on a ToDo. If I implement this on a custom controller then I would have to repeat this code for any other custom controller which executes a CRUD operation on a ToDo.
Any advice or direction would be appreciated.