Balazs_Homework_1/product_reviews_contract.sol

42 lines
1.2 KiB
Solidity
Raw Normal View History

2022-02-14 09:07:27 +00:00
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.0;
contract productReviews {
struct Review {
uint reviewId;
uint productId;
string description;
uint rating;
address reviewer;
}
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));
}
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;
}
}
function isOwner(uint _reviewId) public view returns (bool) {
if(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');
}
}