diff --git a/src/backend/database/database_prod.db b/src/backend/database/database_prod.db index b1597ddb0..286110826 100644 Binary files a/src/backend/database/database_prod.db and b/src/backend/database/database_prod.db differ diff --git a/src/backend/pages/mainpage.py b/src/backend/pages/mainpage.py index fe76caf68..5eef52010 100644 --- a/src/backend/pages/mainpage.py +++ b/src/backend/pages/mainpage.py @@ -220,7 +220,7 @@ def write_apartment_review( ) -> List[Review]: """Write a new review for apartment""" user_id = self.write_apartment_review.cursor.execute( - "SELECT user_id FROM Users WHERE username = ?", (username,) + "SELECT user_id FROM Users WHERE username = ? OR email = ?", (username, username) ).fetchone()[0] today = date.today().strftime("%Y-%m-%d") self.write_apartment_review.cursor.execute( diff --git a/src/frontend/src/components/SingleCard.tsx b/src/frontend/src/components/SingleCard.tsx index e6ac0f8b6..d319da809 100644 --- a/src/frontend/src/components/SingleCard.tsx +++ b/src/frontend/src/components/SingleCard.tsx @@ -14,7 +14,7 @@ interface SingleCardProps { address: string; price_min: number; price_max: number; - votes: number; + rating: number; onSelect: (apt: AptType) => void; } @@ -24,7 +24,7 @@ const SingleCard = ({ address, price_min, price_max, - votes, + rating, onSelect, }: SingleCardProps) => ( @@ -32,7 +32,7 @@ const SingleCard = ({ {/* A clickable card with info about an apartment */} - onSelect({ id, name, address, price_min, price_max, votes }) + onSelect({ id, name, address, price_min, price_max, rating }) } > diff --git a/src/frontend/src/components/Types.tsx b/src/frontend/src/components/Types.tsx index ef76273d0..3d7373b8e 100644 --- a/src/frontend/src/components/Types.tsx +++ b/src/frontend/src/components/Types.tsx @@ -16,7 +16,7 @@ export type AptType = { address: string; price_min: number; price_max: number; - votes: number; + rating: number; }; export type UserType = { diff --git a/src/frontend/src/components/mainpageleft/getApts.tsx b/src/frontend/src/components/mainpageleft/getApts.tsx index ee7192224..927766e95 100644 --- a/src/frontend/src/components/mainpageleft/getApts.tsx +++ b/src/frontend/src/components/mainpageleft/getApts.tsx @@ -44,7 +44,7 @@ function getApartments(priceSort: string, ratingSort: string, id: number) { address: res.data[i].address, price_min: res.data[i].price_min, price_max: res.data[i].price_max, - votes: res.data[i].votes, + rating: res.data[i].rating, }); } } diff --git a/src/frontend/src/components/mainpageright/AddReview.tsx b/src/frontend/src/components/mainpageright/AddReview.tsx index d5728898e..4fb5f2246 100644 --- a/src/frontend/src/components/mainpageright/AddReview.tsx +++ b/src/frontend/src/components/mainpageright/AddReview.tsx @@ -15,17 +15,18 @@ import { interface Props { apt: AptType | undefined; setReviews: Dispatch>; + username: string; } const baseURL = 'http://127.0.0.1:5000/main'; -export default function AddReview({ apt, setReviews }: Props) { +export default function AddReview({ apt, setReviews, username }: Props) { const [text, setText] = useState(''); const [vote, setVote] = useState(0); const addReviewHandler = async (text: string, vote: number) => { // post review on submit const result = await axios.post(`${baseURL}`, { apt_id: apt?.id, - username: 'Zongxian', + username: username, comment: text, vote: vote, }); diff --git a/src/frontend/src/components/mainpageright/AptInfo.tsx b/src/frontend/src/components/mainpageright/AptInfo.tsx index fc8af0fd2..e0131a033 100644 --- a/src/frontend/src/components/mainpageright/AptInfo.tsx +++ b/src/frontend/src/components/mainpageright/AptInfo.tsx @@ -23,9 +23,7 @@ export function AptInfo({ apt }: IAptInfoProps) { - - Rating: ${apt?.votes || 0} - + Rating: {apt?.rating} diff --git a/src/frontend/src/components/user/getReviewedApts.tsx b/src/frontend/src/components/user/getReviewedApts.tsx index fc77df730..6955efa3c 100644 --- a/src/frontend/src/components/user/getReviewedApts.tsx +++ b/src/frontend/src/components/user/getReviewedApts.tsx @@ -41,7 +41,7 @@ export default function getReviewedApts(id: number) { address: res.data[i].address, price_min: res.data[i].price_min, price_max: res.data[i].price_max, - votes: res.data[i].votes, + rating: res.data[i].rating, }); } } diff --git a/src/frontend/src/pages/MainPage.tsx b/src/frontend/src/pages/MainPage.tsx index 7731521c9..36dbfb3a2 100644 --- a/src/frontend/src/pages/MainPage.tsx +++ b/src/frontend/src/pages/MainPage.tsx @@ -23,6 +23,7 @@ function MainPage() { const { apartments } = getApartments('0', '0', -1); const [to, setTo] = useState(apartments[0]); const [logged, setLogged] = useState(false); + const [username, setUsername] = useState(''); function checkLoggedIn() { axios({ url: 'http://127.0.0.1:5000/api/whoami', @@ -31,6 +32,7 @@ function MainPage() { .then((response) => { console.log(response); setLogged(true); + setUsername(response.data); }) .catch((error) => { if (error.response) { @@ -131,7 +133,11 @@ function MainPage() { setTo(apt)} /> - + diff --git a/src/frontend/src/sections/MainPageRightSection.tsx b/src/frontend/src/sections/MainPageRightSection.tsx index 6748554e0..2061dcaff 100644 --- a/src/frontend/src/sections/MainPageRightSection.tsx +++ b/src/frontend/src/sections/MainPageRightSection.tsx @@ -11,8 +11,9 @@ const baseURL = 'http://127.0.0.1:5000/main'; interface apt { apt: AptType | undefined; // in case of null logged: boolean; + username: string; } -function RightSection({ apt, logged }: apt) { +function RightSection({ apt, logged, username }: apt) { const [reviews, setReviews] = useState([]); const [pics, setPics] = useState([ 'https://www.salonlfc.com/wp-content/uploads/2018/01/image-not-found-scaled.png', @@ -63,7 +64,13 @@ function RightSection({ apt, logged }: apt) { sx={{ borderBottomWidth: 3, bgcolor: 'secondary.dark' }} /> )} - {logged === true && } + {logged === true && ( + + )}