Skip to content

Commit f116b68

Browse files
committed
Added missing code
1 parent a4eba7a commit f116b68

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/ViewProduct.vue

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515
<div v-if="product.reviews.length > 0">
1616
<div v-for="review in product.reviews">
17-
<strong>{{ review.reviewer }}</strong> (rating: {{ review.rating }})
17+
<strong>{{ review.reviewer }}</strong> (rating: {{ review.rating }}) -
18+
<a href="#" @click.prevent="deleteReview(review)">delete</a>
1819
<p>{{ review.text }}</p>
1920
</div>
2021
</div>
@@ -65,10 +66,14 @@
6566
text: '',
6667
rating: 0,
6768
reviewer: ''
68-
}
69+
},
70+
reviewResource: null
6971
};
7072
},
7173
created() {
74+
let url = 'http://localhost:3000/products/{productId}/reviews/{reviewId}';
75+
this.reviewResource = this.$resource(url);
76+
7277
this.getProduct(this.productId)
7378
.then(product => this.product = product);
7479
},
@@ -101,6 +106,19 @@
101106
response => response.json(),
102107
response => alert("Could not add review!")
103108
).then(newReview => this.product.reviews.push(newReview));
109+
},
110+
deleteReview(review) {
111+
this.reviewResource.delete({
112+
productId: this.product.id,
113+
reviewId: review.id
114+
}).then(
115+
response => {
116+
// Just be lazy and fetch product again
117+
this.getProduct(this.product.id)
118+
.then(product => this.product = product);
119+
},
120+
response => alert("Could not delete review!")
121+
);
104122
}
105123
}
106124
}

0 commit comments

Comments
 (0)