Upload homework

master
flamboush 2022-02-14 10:07:27 +01:00
parent 784c7393e3
commit 02c278543e
1 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,42 @@
// 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');
}
}