Skip to content

Instantly share code, notes, and snippets.

@valterlobo
Last active August 18, 2022 03:09
Show Gist options
  • Save valterlobo/2b952fcc303481fef1162a1700aa3916 to your computer and use it in GitHub Desktop.
Save valterlobo/2b952fcc303481fef1162a1700aa3916 to your computer and use it in GitHub Desktop.
TODO LIST
pragma solidity ^0.8.9;
// import "hardhat/console.sol";
//Todo list do Jhon
contract Todolist {
struct Todo {
string todo;
bool isCompleted;
uint256 todoId;
address owner;
}
uint256 id = 0;
mapping(address => uint256[]) relationOwnerId;
mapping(uint256 => Todo) todos;
function addTodo(string memory _todo) external {
todos[id] = Todo(_todo, false, id, msg.sender);
relationOwnerId[msg.sender].push(id);
id++;
}
function getTodos() external view returns(Todo[] memory) {
uint256[] memory TodosIds = relationOwnerId[msg.sender];
Todo[] memory todosFromAddress = new Todo[](TodosIds.length);
for(uint256 i = 0; i < TodosIds.length; i++) {
todosFromAddress[i]=todos[TodosIds[i]];
}
return todosFromAddress;
}
function completeTodo(uint256 _id) external {
require(relationOwnerId[msg.sender][_id] == _id, "You're not the owner of this Todo");
todos[_id].isCompleted = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment