arumoy-shome / UWNerdist

Got free time? Check out what classes are going on at the UW campus that interest you!
MIT License
1 stars 1 forks source link

Make Term an ActiveRecord Model #44

Closed arumoy-shome closed 7 years ago

arumoy-shome commented 7 years ago

Details are in #32 but essentially this will allow us to have a more realistic data model and prevent data loss in the long run, which is something the current model lacks.

arumoy-shome commented 7 years ago

Attributes

Both will come from API only we can use the terms/list endpoint. We only want to create a record for the current term. So use the current_term field to grab the id and the list of terms per year to fetch the description of the term we are saving.

Sample response from terms/list

{"meta":
{"requests":226,
"timestamp":1501445962,
"status":200,
"message":"Request successful",
"method_id":1409,"method":{}},
"data":
{"previous_term":1171,
"current_term":1175,
"next_term":1179,
"listings":
{"2016":[{"id":1161,"name":"Winter 2016"},{"id":1165,"name":"Spring 2016"},{"id":1169,"name":"Fall 2016"}],
"2017":[{"id":1171,"name":"Winter 2017"},{"id":1175,"name":"Spring 2017"},{"id":1179,"name":"Fall 2017"}],
"2018":[{"id":1181,"name":"Winter 2018"},{"id":1185,"name":"Spring 2018"},{"id":1189,"name":"Fall 2018"}]}}}

Consider:

  1. new record will be created every 4 months
  2. it's managed internally, not though UI
  3. new record will always fetch id and description from API

We can add a polymorphic new method which adds the above functionality and uses the built in new from active record behind the scenes.