delete in the backend
This commit is contained in:
parent
f73f862bcf
commit
ba6e5a9c17
3 changed files with 22 additions and 1 deletions
|
@ -45,6 +45,10 @@ 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) CreateUser(username string, password string) error {
|
||||
user := User{Username: username, Password: password}
|
||||
result := db.ORM.Create(&user)
|
||||
|
|
|
@ -48,6 +48,16 @@
|
|||
});
|
||||
}
|
||||
|
||||
function deleteTask(id) {
|
||||
axios.delete("/tasks/" + id, axiosConfig)
|
||||
.then((response) => {
|
||||
console.log(response);
|
||||
})
|
||||
.catch((err) => {
|
||||
showErrorToast(err.response.data.message);
|
||||
});
|
||||
}
|
||||
|
||||
function addTaskToTasks(task) {
|
||||
const newTask = document.createElement('div');
|
||||
newTask.classList.add('row', 'g-0', 'align-items-center', 'mb-1');
|
||||
|
@ -57,7 +67,7 @@
|
|||
<div class="col-2 form-check form-switch d-flex justify-content-center">
|
||||
<input class="text-center form-check-input" type="checkbox" ${task.Done && "checked"} role="switch" id="flexSwitchCheckDefault">
|
||||
</div>
|
||||
<button class="col-1 btn btn-danger"><i class="bi bi-trash"></i></button>
|
||||
<button onclick="deleteTask(${task.ID})" class="col-1 btn btn-danger"><i class="bi bi-trash"></i></button>
|
||||
`;
|
||||
tasksEl.appendChild(newTask);
|
||||
}
|
||||
|
|
|
@ -55,6 +55,13 @@ func (wp *Webpage) defineRoutes() {
|
|||
c.JSON(200, gin.H{"task": task})
|
||||
}
|
||||
})
|
||||
tasks.DELETE(":id", func(c *gin.Context) {
|
||||
if wp.isLoggedInMiddleware(c) {
|
||||
id := c.Param("id")
|
||||
wp.Database.DeleteTask(id)
|
||||
c.JSON(200, gin.H{"message": "success", "id": id})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
auth := wp.Router.Group("/auth")
|
||||
|
|
Reference in a new issue