Skip to content

Commit

Permalink
chore: added delete function according to the given condition
Browse files Browse the repository at this point in the history
  • Loading branch information
sharvil-lade committed Mar 28, 2024
1 parent b83bbae commit e971d9b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions contracts/tasktrackr.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ contract tasktrackr {
event TaskCompleted(uint256 indexed id);
event TaskUpdated(uint256 indexed id, string newTask);
event ContractDestroyed(address indexed destroyer);
event TaskDeleted(uint256 indexed id);

mapping(uint256 => TodoItem) public list;
uint256 public count = 0;
Expand Down Expand Up @@ -50,4 +51,28 @@ contract tasktrackr {
emit ContractDestroyed(msg.sender);
selfdestruct(payable(owner));
}

// Delete according to complete and incomplete

function deleteCompleteTask(uint256 id) public {
require(id < count, "Task with given ID does not exist");
require(list[id].isCompleted, "Task is not completed yet");
delete list[id];
emit TaskDeleted(id);
}

function deleteIncompleteTask(uint256 id) public {
require(id < count, "Task with given ID does not exist");
require(!list[id].isCompleted, "Task is already completed");
delete list[id];
emit TaskDeleted(id);
}

// Delete according to ID

function deleteTask(uint256 id) public {
require(id < count, "Task with given ID does not exist");
emit TaskDeleted(id);
delete list[id];
}
}

0 comments on commit e971d9b

Please sign in to comment.