-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from HungrySlugs-CSE115A/search_rework
made search like the rest of the website & changed to axios
- Loading branch information
Showing
4 changed files
with
431 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,28 @@ | ||
import axios from "axios"; | ||
|
||
import { Location } from "@/interfaces/Location"; | ||
import { FrontEndReviews } from "@/interfaces/Review"; | ||
|
||
const backend = "http://localhost:8000"; | ||
|
||
export async function fetchLocations(): Promise<Location[]> { | ||
const res = await fetch("http://localhost:8000/api/locations", { | ||
method: "GET", | ||
next: { | ||
revalidate: 1800, // every 30 minutes | ||
}, | ||
mode: "cors", | ||
headers: { | ||
"Access-Control-Allow-Origin": "*", | ||
}, | ||
}); | ||
const data: { locations: Location[] } = await res.json(); | ||
return data.locations; | ||
const res = await axios.get(`${backend}/api/locations`); | ||
return res.data.locations; | ||
} | ||
|
||
export async function fetchFoodReviewsBulk(data: { | ||
food_names: string[]; | ||
user_id: string | null; | ||
}): Promise<FrontEndReviews> { | ||
const res = await fetch("http://localhost:8000/api/get_ratings_bulk/", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Access-Control-Allow-Origin": "*", | ||
}, | ||
body: JSON.stringify(data), | ||
next: { | ||
revalidate: 5, // every 5 seconds | ||
}, | ||
mode: "cors", | ||
}); | ||
const response_json = await res.json(); | ||
return response_json; | ||
const res = await axios.post(`${backend}/api/get_ratings_bulk/`, data); | ||
return res.data; | ||
} | ||
|
||
export async function updateReview(data: { | ||
food_name: string; | ||
user_id: string; | ||
food_rating: number; | ||
}): Promise<{ average: number | null }> { | ||
const res = await fetch("http://localhost:8000/api/rating_update/", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Access-Control-Allow-Origin": "*", | ||
}, | ||
body: JSON.stringify(data), | ||
mode: "cors", | ||
}); | ||
const response_json = await res.json(); | ||
return response_json; | ||
const res = await axios.post(`${backend}/api/rating_update/`, data); | ||
return res.data; | ||
} |
Oops, something went wrong.