// SPDX-License-Identifier: MIT
pragma solidity ^0.8.3;
contract Storage {
struct People {
uint256 personId;
string vorname;
string nachname;
uint256 birthdate;
}
struct Decision {
string decision;
string wantdonate;
string dontwantdonate;
}
People[] public people;
mapping(string => Decision) internal vornameToDonation;
mapping(string => mapping(string => Decision)) internal nachnameToDonation;
mapping(uint256 => mapping(string => mapping(string => Decision)))
public birthdayToDonation;
address public owner;
constructor() {
owner = msg.sender;
}
modifier onlyOwner() {
if (msg.sender != owner) {
revert("NotOwnerError");
}
_;
}
uint256 public peopleCount = 0;
function addPerson(
uint256 _birthdate,
string memory _vorname,
string memory _nachname,
string memory _decision,
string memory _wantdonate,
string memory _dontwantdonate
) public onlyOwner {
people.push(People(peopleCount, _vorname, _nachname, _birthdate));
birthdayToDonation[_birthdate][_nachname][_vorname] = Decision(
_decision,
_wantdonate,
_dontwantdonate
);
peopleCount++;
}
function readDonation(
uint256 _birthdate,
string memory _vorname,
string memory _nachname
) public view onlyOwner returns (Decision memory) {
Decision memory readOnly = vornameToDonation[type(Storage).name];
return readOnly;
}
function removePerson(uint256 index) external onlyOwner {
//if (index >= people.length) return revert('Person does not exist!');
if (index == people[index].personId) delete people[index];
peopleCount--;
}
}
With my function readDonation i want to look for people i added with my function addPeople. I used this extra function because i want to make sure that only the owner of the contract can look for people. But i found no possibility to tip in the first name, last name and the birthdate and then get the answer for donation, wantdonate and dontwantdonate. Also i want to look for this with the mapping. Can somebody give me an idea or approach for make this happen?