|
@@ -62,7 +62,7 @@ type TaskShelf interface {
|
|
|
// hopefully you dont need to call this! ;)
|
|
|
ResetDone(id int)
|
|
|
// Add a task to the shelf
|
|
|
- AddTask(t Task)
|
|
|
+ AddTask(title string, desc string, priority int, due time.Time)
|
|
|
// Retrieve all tasks in the shelf
|
|
|
GetAll() []Task
|
|
|
// Render a task to a task template
|
|
@@ -145,10 +145,30 @@ func (f *FilesystemShelf) GetAll() []Task {
|
|
|
/*
|
|
|
Add a task to the filesystem shelf
|
|
|
|
|
|
- :param t: the Task struct to add
|
|
|
+ :param title: the title to give the task
|
|
|
+ :param desc: the description to give the task
|
|
|
+ :param priority: the priority to give the task
|
|
|
+ :param due: the due date for the task
|
|
|
+ :returns: Nothing
|
|
|
*/
|
|
|
-func (f *FilesystemShelf) AddTask(t Task) {
|
|
|
- f.Tasks = append(f.Tasks, t)
|
|
|
+func (f *FilesystemShelf) AddTask(title string, desc string, priority int, due time.Time) {
|
|
|
+ var inc int
|
|
|
+ inc = 0
|
|
|
+ for i := range f.Tasks {
|
|
|
+ if f.Tasks[i].Id > inc {
|
|
|
+ inc = f.Tasks[i].Id
|
|
|
+ }
|
|
|
+ }
|
|
|
+ inc += 1
|
|
|
+ task := Task{
|
|
|
+ Id: inc,
|
|
|
+ Title: title,
|
|
|
+ Desc: desc,
|
|
|
+ Due: due,
|
|
|
+ Done: false,
|
|
|
+ Priority: priority,
|
|
|
+ }
|
|
|
+ f.Tasks = append(f.Tasks, task)
|
|
|
|
|
|
err := os.WriteFile(f.SaveLocation, marshalTaskToShelf(f.Tasks, f.Template), os.ModePerm)
|
|
|
if err != nil {
|
|
@@ -161,9 +181,48 @@ func (f *FilesystemShelf) ModifyDue(id int, due time.Time) {}
|
|
|
func (f *FilesystemShelf) ModifyDesc(id int, desc string) {}
|
|
|
func (f *FilesystemShelf) ModifyPriority(id int, pri int) {}
|
|
|
func (f *FilesystemShelf) ModifyTitle(id int, title string) {}
|
|
|
-func (f *FilesystemShelf) DeleteTask(id int) {}
|
|
|
-func (f *FilesystemShelf) MarkDone(id int) {}
|
|
|
-func (f *FilesystemShelf) ResetDone(id int) {}
|
|
|
+func (f *FilesystemShelf) DeleteTask(id int) {
|
|
|
+ replTasks := []Task{}
|
|
|
+ for i := range f.Tasks {
|
|
|
+ if f.Tasks[i].Id == id {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ replTasks = append(replTasks, f.Tasks[i])
|
|
|
+ }
|
|
|
+ os.WriteFile(f.SaveLocation, marshalTaskToShelf(replTasks, f.Template), os.ModePerm)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+Mark task as done and write the shelf to disk. since the Tasks within FilesystemShelf are
|
|
|
+values and not pointers, we need to copy the entirety of the shelf over to a new set
|
|
|
+and write it, as opposed to just modifying the pointer and then writing.
|
|
|
+
|
|
|
+ :param id: the ID of the task to mark as done
|
|
|
+ :returns: Nothing
|
|
|
+*/
|
|
|
+func (f *FilesystemShelf) MarkDone(id int) {
|
|
|
+ replTasks := []Task{}
|
|
|
+ for i := range f.Tasks {
|
|
|
+ if f.Tasks[i].Id == id {
|
|
|
+ doneTask := Task{
|
|
|
+ Id: f.Tasks[i].Id,
|
|
|
+ Title: f.Tasks[i].Title,
|
|
|
+ Desc: f.Tasks[i].Desc,
|
|
|
+ Due: f.Tasks[i].Due,
|
|
|
+ Done: true,
|
|
|
+ Priority: f.Tasks[i].Priority,
|
|
|
+ }
|
|
|
+ replTasks = append(replTasks, doneTask)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ replTasks = append(replTasks, f.Tasks[i])
|
|
|
+ }
|
|
|
+ os.WriteFile(f.SaveLocation, marshalTaskToShelf(replTasks, f.Template), os.ModePerm)
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func (f *FilesystemShelf) ResetDone(id int) {}
|
|
|
|
|
|
// private function for parsing the byte stream from the filesystem
|
|
|
func parseFilesystemShelf(data []byte) []Task {
|