Let's introduce a media service that will take care of loading/persisting media collections, removing that burden from the controller layer:
With this new design, our controller has fewer responsibilities. As an added benefit, this design also allows us to develop the service layer independently.
We have also added details for the view layer. This interface is the basis for the implementation as it already defines which operations our controller will be able to perform via the view.
For now, all of the code will still be co-located in the same TypeScript file; however, later on, we will see how we can better isolate things using TypeScript modules. For the time being, we only gain in terms of logical design and the distribution of responsibilities, but this is already a big improvement on what we did earlier.