11import { ref } from "vue" ;
22import { getCookie } from "../utils/cookies" ;
3+ import { apiFetch } from "../utils/api" ;
34
45export function useReviews ( ) {
56 const loading = ref ( false ) ;
@@ -8,7 +9,9 @@ export function useReviews() {
89 const fetchUserReview = async ( courseId ) => {
910 if ( ! courseId ) return null ;
1011 try {
11- const response = await fetch ( `/api/course/${ courseId } /my-review/` ) ;
12+ const response = await apiFetch (
13+ `/api/courses/${ courseId } /reviews/?author=me` ,
14+ ) ;
1215 if ( response . ok ) {
1316 const data = await response . json ( ) ;
1417 return Array . isArray ( data ) ? data [ 0 ] : data ;
@@ -29,7 +32,7 @@ export function useReviews() {
2932
3033 const submitReview = async ( courseId , newReview ) => {
3134 try {
32- const response = await fetch ( `/api/course /${ courseId } /` , {
35+ const response = await apiFetch ( `/api/courses /${ courseId } /reviews /` , {
3336 method : "POST" ,
3437 headers : {
3538 "Content-Type" : "application/json" ,
@@ -48,17 +51,17 @@ export function useReviews() {
4851 }
4952 } ;
5053
51- const deleteReview = async ( courseId ) => {
54+ const deleteReview = async ( reviewId ) => {
5255 try {
53- const response = await fetch ( `/api/course /${ courseId } /review /` , {
56+ const response = await apiFetch ( `/api/reviews /${ reviewId } /` , {
5457 method : "DELETE" ,
5558 headers : { "X-CSRFToken" : getCookie ( "csrftoken" ) } ,
5659 } ) ;
57- if ( ! response . ok ) {
60+ if ( ! response . ok && response . status !== 204 ) {
5861 const errorData = await response . json ( ) . catch ( ( ) => null ) ;
5962 throw new Error ( errorData ?. detail || "Failed to delete review" ) ;
6063 }
61- return await response . json ( ) ;
64+ return true ;
6265 } catch ( e ) {
6366 console . error ( "useReviews: deleteReview error" , e ) ;
6467 throw e ;
@@ -67,7 +70,7 @@ export function useReviews() {
6770
6871 const vote = async ( courseId , value , forLayup ) => {
6972 try {
70- const response = await fetch ( `/api/course /${ courseId } /vote/` , {
73+ const response = await apiFetch ( `/api/courses /${ courseId } /vote/` , {
7174 method : "POST" ,
7275 headers : {
7376 "Content-Type" : "application/json" ,
@@ -85,7 +88,7 @@ export function useReviews() {
8588
8689 const voteOnReview = async ( reviewId , isKudos ) => {
8790 try {
88- const response = await fetch ( `/api/review /${ reviewId } /vote/` , {
91+ const response = await apiFetch ( `/api/reviews /${ reviewId } /vote/` , {
8992 method : "POST" ,
9093 headers : {
9194 "Content-Type" : "application/json" ,
0 commit comments