scottohara / tvmanager

PWA for tracking recorded, watched & upcoming TV shows
MIT License
3 stars 0 forks source link

Reduce duplication in models #84

Open scottohara opened 5 years ago

scottohara commented 5 years ago

All models currently extend from a Base model.

The base model holds a reference to the db (from ApplicationController) used for all database operations, but that's all it does.

There are a lot of similar methods/functionality in models, and it would be ideal if we could rationalise any duplication and move it higher up in the hierarchy for reuse; and define the minimum interface that models performing a specific role are required to implement (e.g. all entities need the methods find, save, remove,fromJson,torsion` etc.)

The table below lists the common methods for each model:

Model List Find Count Remove All From JSON Save Remove To JSON
Episode listBySeries listByUnscheduled (list) find totalCount countByStatus (count) removeAll fromJson save remove toJson
Program list find count removeAll fromJson save remove toJson
Series listByProgram listByNowShowing listByStatus lisByIncomplete (list) find count removeAll fromJson save remove toJson
Setting   get       save remove  
Sync list   count removeAll     remove  

In addition, both the Program & Series models have a number of similar setXXXCount() methods that update the progress bar display, which may be able to refactored to reduce duplicate code.