So, I'm creating this PR again now that the smaller changes have been merged.
Main motivation for this PR
The main motivation behind these changes were, that I wanted to be able to commit multiple changes to an object of the API at once.
Prior to these changes, a function call existed for every "action" which can be performed on a task/todolist (e.g. separate functions for "create task", "set task reminder", "set task completed").
This function based approach comes with a big flaw in my opinion:
If multiple changed were to be made to e.g. a task, multiple functions had to be called.
Each function is a separate request to the API, and one request takes relatively long to process.
Example: If I wanted to change the due date of a task and also the task name, two separate API request would be performed and that takes twice as long.
This vastly decreases the UX of the cli application as the processing times multiplies.
So instead, I propose a new way of "building" requests: With the use of objects.
todo_api.py now defines objects which represent a API request, e.g. todo_api.ModifyTask.
These objects contain functions which can be called by method chaining.
e.g.:
When a request is completely built, it can be executed with the .execute() function.
To keep the usage consistent, I also created objects for API actions like deleting a task (e.g. todo_api.DeleteTask), even though they do not support any additional properties and therefore also no method chaining.
Change in project structure
This PR also contains a rework of the existing file structure.
todo_api.py was moved into the new folder (todo_api/todo_api.py) and split into several smaller files.
todo_api/exceptions.py: this file contains all the exceptions which can occur when using the api (extracted from the old todo_api.py)
todo_api/queries.py: this file contains all the functions to do the lookup from a name to an API ID (e.g. get API ID of a specific task)
todo_api/todo_api_util.py -> moved from todo_api_util.py
So, I'm creating this PR again now that the smaller changes have been merged.
Main motivation for this PR
The main motivation behind these changes were, that I wanted to be able to commit multiple changes to an object of the API at once. Prior to these changes, a function call existed for every "action" which can be performed on a task/todolist (e.g. separate functions for "create task", "set task reminder", "set task completed").
This function based approach comes with a big flaw in my opinion: If multiple changed were to be made to e.g. a task, multiple functions had to be called. Each function is a separate request to the API, and one request takes relatively long to process.
Example: If I wanted to change the due date of a task and also the task name, two separate API request would be performed and that takes twice as long.
This vastly decreases the UX of the cli application as the processing times multiplies.
So instead, I propose a new way of "building" requests: With the use of objects.
todo_api.py now defines objects which represent a API request, e.g. todo_api.ModifyTask.
These objects contain functions which can be called by method chaining. e.g.:
When a request is completely built, it can be executed with the
.execute()
function.To keep the usage consistent, I also created objects for API actions like deleting a task (e.g. todo_api.DeleteTask), even though they do not support any additional properties and therefore also no method chaining.
Change in project structure
This PR also contains a rework of the existing file structure.
todo_api.py was moved into the new folder (todo_api/todo_api.py) and split into several smaller files.