diff --git a/Lab01/app/database/database.go b/Lab01/app/database/database.go index df27a29..014d6ae 100644 --- a/Lab01/app/database/database.go +++ b/Lab01/app/database/database.go @@ -45,8 +45,22 @@ func (db *Database) CreateTask(username string, description string) Task { return task } -func (db *Database) DeleteTask(id string) { - db.ORM.Delete(&Task{}, id) +func (db *Database) DeleteTask(id string) bool { + result := db.ORM.Delete(&Task{}, id) + if result.RowsAffected == 0 { + return false + } + return true +} + +func (db *Database) UpdateTask(id string, done string) bool { + task := Task{} + db.ORM.First(&task, id) + result := db.ORM.Model(&task).Update("done", done) + if result.RowsAffected == 0 { + return false + } + return true } func (db *Database) CreateUser(username string, password string) error { diff --git a/Lab01/app/templates/tasks.tmpl b/Lab01/app/templates/tasks.tmpl index 971c200..52e3d05 100644 --- a/Lab01/app/templates/tasks.tmpl +++ b/Lab01/app/templates/tasks.tmpl @@ -50,7 +50,7 @@ } function deleteTask(id) { - axios.delete("/tasks/" + id, axiosConfig) + axios.delete("/tasks", {params: {id: id}, headers: {username: username}}) .then(() => { getAllTasks(); }) @@ -59,6 +59,13 @@ }); } + function updateTask(id, done) { + axios.put("/tasks", null, {params: {id: id, done: done}, headers: {username: username}}) + .catch((err) => { + showErrorToast(err.response.data.message); + }); + } + function addTaskToTasks(task, number) { tasks.push(task); const newTask = document.createElement('div'); @@ -68,7 +75,7 @@