Fixing if statements to use require instead and correcting return statements

master
flamboush 2022-02-25 15:48:28 +01:00
parent 02c278543e
commit a879447830
1 changed files with 11 additions and 16 deletions

View File

@ -13,30 +13,25 @@ contract productReviews {
uint public reviewId = 1;
Review[] public reviews;
function addReview(uint _productId, string memory _description, uint _rating) external {
if(_isRatingOk(_rating)) {
reviews.push(Review(reviewId, _productId, _description, _rating, msg.sender));
}
function addReview(uint _productId, string memory _description, uint _rating) external returns (bool) {
require(_isRatingOk(_rating) == true);
reviews.push(Review(reviewId, _productId, _description, _rating, msg.sender));
reviewId++;
revert('Rating invalid');
return true;
}
function _isRatingOk(uint _rating) internal pure returns (bool) { // azt allitja, hogy folosleges a returns deklaralasa, ha nincs elnevezve, viszont ha kitorlom, panaszkodik a return parameterek szama miatt...
if(_rating < 6 && _rating > 0) {
return true;
}
function _isRatingOk(uint _rating) internal pure returns (bool) {
require(_rating < 6 && _rating > 0);
return true;
}
function isOwner(uint _reviewId) public view returns (bool) {
if(msg.sender == reviews[_reviewId].reviewer) {
return true;
}
require(msg.sender == reviews[_reviewId].reviewer);
return true;
}
function _deleteReview(uint _reviewId) private {
if(isOwner(_reviewId) == true) {
delete reviews[_reviewId];
}
revert('User is not review owner');
require(isOwner(_reviewId) == true);
delete reviews[_reviewId];
}
}