Skip to content

made search like the rest of the website & changed to axios #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading