Skip to content

Commit

Permalink
Merge pull request #122 from HungrySlugs-CSE115A/search_rework
Browse files Browse the repository at this point in the history
made search like the rest of the website & changed to axios
  • Loading branch information
IanHollow authored May 31, 2024
2 parents 45f0911 + 38a72bb commit d0124ed
Show file tree
Hide file tree
Showing 4 changed files with 431 additions and 374 deletions.
45 changes: 8 additions & 37 deletions app/db.ts
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;
}
Loading

0 comments on commit d0124ed

Please sign in to comment.