Skip to content

Commit

Permalink
Merge pull request #1 from parkersarahl/delete-feature
Browse files Browse the repository at this point in the history
added delete functionality
  • Loading branch information
parkersarahl authored Jul 11, 2024
2 parents 3199e2a + 95ea6e2 commit 93cebfe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions api/src/todos/todos.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class TodosController {
return await this.todoService.update(id, todo);
}

@Delete()
async delete(@Body() id: number) {
@Delete(':id')
async delete(@Param('id') id: number) {
return await this.todoService.delete(id);
}
}
11 changes: 11 additions & 0 deletions frontend/src/Todo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ const Todo = ({ todo, updateTodos }: Props) => {
});
};

const deleteTodo = () => {
axios
.delete(`http://${hosts}/api/todos/${todo.id}`)
.then((response) => {
updateTodos(response.data);
});
}

return (
<div
key={todo.id}
Expand Down Expand Up @@ -105,6 +113,9 @@ const Todo = ({ todo, updateTodos }: Props) => {
>
{complete ? "Mark Incomplete" : "Mark Complete"}
</button>

<button
onClick={deleteTodo}>Delete</button>
</div>
);
};
Expand Down

0 comments on commit 93cebfe

Please sign in to comment.