Skip to content

Commit

Permalink
Fix add review comment and display total votes
Browse files Browse the repository at this point in the history
  • Loading branch information
MinhPhan8803 committed Nov 30, 2022
1 parent 455de9c commit c55fac3
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 15 deletions.
Binary file modified src/backend/database/database_prod.db
Binary file not shown.
2 changes: 1 addition & 1 deletion src/backend/pages/mainpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/frontend/src/components/SingleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface SingleCardProps {
address: string;
price_min: number;
price_max: number;
votes: number;
rating: number;
onSelect: (apt: AptType) => void;
}

Expand All @@ -24,15 +24,15 @@ const SingleCard = ({
address,
price_min,
price_max,
votes,
rating,
onSelect,
}: SingleCardProps) => (
<React.Fragment>
<Card>
{/* A clickable card with info about an apartment */}
<CardActionArea
onClick={() =>
onSelect({ id, name, address, price_min, price_max, votes })
onSelect({ id, name, address, price_min, price_max, rating })
}
>
<CardContent style={{ height: '175px' }}>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/Types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type AptType = {
address: string;
price_min: number;
price_max: number;
votes: number;
rating: number;
};

export type UserType = {
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/mainpageleft/getApts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/frontend/src/components/mainpageright/AddReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ import {
interface Props {
apt: AptType | undefined;
setReviews: Dispatch<SetStateAction<ReviewType[]>>;
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<string>('');
const [vote, setVote] = useState<number>(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,
});
Expand Down
4 changes: 1 addition & 3 deletions src/frontend/src/components/mainpageright/AptInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ export function AptInfo({ apt }: IAptInfoProps) {
</Typography>
</Box>
<Box display="flex" justifyContent="center">
<Typography variant="h6">
Rating: ${apt?.votes || 0}
</Typography>
<Typography variant="h6">Rating: {apt?.rating}</Typography>
</Box>
</Stack>
</Paper>
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/user/getReviewedApts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/frontend/src/pages/MainPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function MainPage() {
const { apartments } = getApartments('0', '0', -1);
const [to, setTo] = useState<AptType>(apartments[0]);
const [logged, setLogged] = useState(false);
const [username, setUsername] = useState('');
function checkLoggedIn() {
axios({
url: 'http://127.0.0.1:5000/api/whoami',
Expand All @@ -31,6 +32,7 @@ function MainPage() {
.then((response) => {
console.log(response);
setLogged(true);
setUsername(response.data);
})
.catch((error) => {
if (error.response) {
Expand Down Expand Up @@ -131,7 +133,11 @@ function MainPage() {
<Populate onSelect={(apt) => setTo(apt)} />
</Grid>
<Grid item xs style={{ maxHeight: '100%', overflow: 'auto' }}>
<RightSection apt={to || apartments[0]} logged={logged} />
<RightSection
apt={to || apartments[0]}
logged={logged}
username={username}
/>
</Grid>
</Grid>
</Stack>
Expand Down
11 changes: 9 additions & 2 deletions src/frontend/src/sections/MainPageRightSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<ReviewType[]>([]);
const [pics, setPics] = useState<string[]>([
'https://www.salonlfc.com/wp-content/uploads/2018/01/image-not-found-scaled.png',
Expand Down Expand Up @@ -63,7 +64,13 @@ function RightSection({ apt, logged }: apt) {
sx={{ borderBottomWidth: 3, bgcolor: 'secondary.dark' }}
/>
)}
{logged === true && <AddReview apt={apt} setReviews={setReviews} />}
{logged === true && (
<AddReview
apt={apt}
setReviews={setReviews}
username={username}
/>
)}
<Divider sx={{ borderBottomWidth: 3, bgcolor: 'secondary.dark' }} />
<ReviewsList reviews={reviews} />
</Stack>
Expand Down

3 comments on commit c55fac3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCover
app.py1450100%
config.py10100%
decorators.py270100%
dataholders
   apt.py90100%
   mainpage_get.py150100%
   review.py70100%
   user.py80100%
pages
   login.py290100%
   mainpage.py1000100%
   userpage.py530100%
TOTAL3940100%

Tests Skipped Failures Errors Time
49 0 💤 0 ❌ 0 🔥 0.769s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCover
app.py1450100%
config.py10100%
decorators.py270100%
dataholders
   apt.py90100%
   mainpage_get.py150100%
   review.py70100%
   user.py80100%
pages
   login.py290100%
   mainpage.py1000100%
   userpage.py530100%
TOTAL3940100%

Tests Skipped Failures Errors Time
49 0 💤 0 ❌ 0 🔥 1.118s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCover
app.py1450100%
config.py10100%
decorators.py270100%
dataholders
   apt.py90100%
   mainpage_get.py150100%
   review.py70100%
   user.py80100%
pages
   login.py290100%
   mainpage.py1000100%
   userpage.py530100%
TOTAL3940100%

Tests Skipped Failures Errors Time
49 0 💤 0 ❌ 0 🔥 1.469s ⏱️

Please sign in to comment.