Fixing if statements to use require instead and correcting return statements
parent
02c278543e
commit
a879447830
|
@ -13,30 +13,25 @@ contract productReviews {
|
||||||
uint public reviewId = 1;
|
uint public reviewId = 1;
|
||||||
Review[] public reviews;
|
Review[] public reviews;
|
||||||
|
|
||||||
function addReview(uint _productId, string memory _description, uint _rating) external {
|
function addReview(uint _productId, string memory _description, uint _rating) external returns (bool) {
|
||||||
if(_isRatingOk(_rating)) {
|
require(_isRatingOk(_rating) == true);
|
||||||
reviews.push(Review(reviewId, _productId, _description, _rating, msg.sender));
|
reviews.push(Review(reviewId, _productId, _description, _rating, msg.sender));
|
||||||
}
|
|
||||||
reviewId++;
|
reviewId++;
|
||||||
revert('Rating invalid');
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
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) {
|
function isOwner(uint _reviewId) public view returns (bool) {
|
||||||
if(msg.sender == reviews[_reviewId].reviewer) {
|
require(msg.sender == reviews[_reviewId].reviewer);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function _deleteReview(uint _reviewId) private {
|
function _deleteReview(uint _reviewId) private {
|
||||||
if(isOwner(_reviewId) == true) {
|
require(isOwner(_reviewId) == true);
|
||||||
delete reviews[_reviewId];
|
delete reviews[_reviewId];
|
||||||
}
|
}
|
||||||
revert('User is not review owner');
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue