Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TaskContract.sol #502

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions Level1/Check-it/backend/contracts/TaskContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,31 @@ external{

}

function getMyTasks() external view returns(Task[] memory) {
Task[] memory temporary= new Task[](tasks.length);
uint counter=0;

for (uint i=0; i<tasks.length; i++) {
if (taskToOwner[i]== msg.sender && tasks[i].isDeleted==false) {
temporary[counter]= tasks[i];
counter++;
}
function getMyTasks() external view returns (Task[] memory) {
Task[] memory temporary = new Task[](tasks.length);
uint counter = 0;

for (uint i = 0; i < tasks.length; i++) {
if (taskToOwner[i] == msg.sender && !tasks[i].isDeleted) {
// Check if the counter is less than the temporary array's length
if (counter < temporary.length) {
temporary[counter] = tasks[i];
} else {
// If the counter exceeds the temporary array's length, exit the loop
break;
}
counter++;
}
}
Task[] memory result= new Task[](counter);
for (uint i=0; i<counter; i++) {
result[i] = temporary[i];

// Create the result array with the actual size (counter)
Task[] memory result = new Task[](counter);
for (uint i = 0; i < counter; i++) {
result[i] = temporary[i];
}
return result;
}
}


function deleteTask(uint taskId, bool isDeleted) external {
if (taskToOwner[taskId]== msg.sender) {
Expand All @@ -52,4 +61,4 @@ external{