Skip to content

Refactor

Yutaka Oishi edited this page Oct 2, 2024 · 28 revisions

What was refactored:

The main thing we changed the endpoints used in the backend. We made it so data isn't being passed around in path parameters anymore. Instead, a majority of any data being sent to the backend is now passed within the request body as JSON data.

Before, entities were uniquely identified using different fields such as the date_created for workouts. So, another change we made in the refactor is creating an ID field for all entities stored in the database (i.e. exercises, routines, workouts, etc.) to make it much easier to fetch a specific entity. This means that the only data that is passed to the backend as a path parameter is the entitity ID, better following RESTful principles.

An example of the change can be seen below:

image

Old endpoints for exercises (above)

image

New endpoints for exercises (above)

How this improves maintainability

This refactor greatly improves maintainability since if we wanted to change the kinds of data being passed to the backend, we no longer have to keep changing the endpoints anymore. Instead, we can keep all endpoints the same and only change the request body.

For example, if I wanted to change the data being sent when creating an exercise with the old endpoints, I would have to edit:

image

to include new path parameters.

Now, if I want to change the data being sent when creating an exercise, I wouldn't have to change the endpoint at all since the data is passed within the request body:

image

This means that it is a lot easier to make changes to the kinds of data that each entity has. This helped us out a lot in A2, since some of the new functionality required extra data being stored in each entity.

Furthermore, the changes to only use ID to fetch an entity from the backend made it a lot easier for us to do endpoint calls in the frontend. This is because, rather than having to pass multiple bits of information to the backend to fetch an exercise, we only need the ID. This also means that if future changes require removing certain fields from an entity, we can be sure that it won't affect the fetching logic since the ID field will never be removed.

For example, with the old endpoints, if we wanted to remove the name field, it would completely break the fetching logic. With the new endpoint, there would be no issues since we only use IDs to identify entities.

Clone this wiki locally