Skip to content

Commit

Permalink
chore: delete accordingly updated
Browse files Browse the repository at this point in the history
  • Loading branch information
sharvil-lade committed Mar 29, 2024
1 parent f019c14 commit c7a4fa3
Showing 1 changed file with 4 additions and 35 deletions.
39 changes: 4 additions & 35 deletions contracts/tasktrackr.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,23 @@ 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);
count--;
}

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);
count--;
}

// Delete according to ID
Expand All @@ -74,39 +76,6 @@ contract tasktrackr {
require(id < count, "Task with given ID does not exist");
emit TaskDeleted(id);
delete list[id];
}

// Complete Section

function getCompletedTasks() public view returns (string[] memory) {
string[] memory completedTasks = new string[](count);
uint256 completedCount = 0;
for (uint256 i = 0; i < count; i++) {
if (list[i].isCompleted) {
completedTasks[completedCount] = list[i].task;
completedCount++;
}
}
assembly {
mstore(completedTasks, completedCount)
}
return completedTasks;
}

//Incomplete Section

function getIncompleteTasks() public view returns (string[] memory) {
string[] memory incompleteTasks = new string[](count);
uint256 incompleteCount = 0;
for (uint256 i = 0; i < count; i++) {
if (!list[i].isCompleted) {
incompleteTasks[incompleteCount] = list[i].task;
incompleteCount++;
}
}
assembly {
mstore(incompleteTasks, incompleteCount)
}
return incompleteTasks;
count--;
}
}

0 comments on commit c7a4fa3

Please sign in to comment.