kiblee / tod0

A Terminal Client for Microsoft To-Do
MIT License
121 stars 19 forks source link

Reworked the API to allow changing multiple task / list properties at once #30

Closed devzeb closed 2 years ago

devzeb commented 3 years ago

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.:

todo_api.ModifyTask(task_list, try_parse_as_int(name))
    .set_reminder(datetime.now())
    .set_title("new title")
    .set_completed()

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.