Balazs_Homework_1/product_reviews_contract.sol

37 lines
1.0 KiB
Solidity

// 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 returns (bool) {
require(_isRatingOk(_rating) == true);
reviews.push(Review(reviewId, _productId, _description, _rating, msg.sender));
reviewId++;
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) {
require(msg.sender == reviews[_reviewId].reviewer);
return true;
}
function _deleteReview(uint _reviewId) private {
require(isOwner(_reviewId) == true);
delete reviews[_reviewId];
}
}