Skip to content

Commit

Permalink
Merge branch 'main' into linear-progress-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ggsawatyanon authored Oct 28, 2024
2 parents 5e5d006 + dfe54dd commit f35a037
Show file tree
Hide file tree
Showing 30 changed files with 1,133 additions and 98 deletions.
8 changes: 8 additions & 0 deletions backend/scripts/add_buildings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type BuildingData = {
landlordId: number;
address: string;
area: string;
latitude?: number;
longitude?: number;
};

const getAreaType = (areaName: string): 'COLLEGETOWN' | 'WEST' | 'NORTH' | 'DOWNTOWN' | 'OTHER' => {
Expand All @@ -33,6 +35,8 @@ const formatBuilding = ({
landlordId,
address,
area,
latitude = 0,
longitude = 0,
}: BuildingData): ApartmentWithId => ({
id: id.toString(),
name,
Expand All @@ -42,6 +46,10 @@ const formatBuilding = ({
numBeds: 0,
photos: [],
area: getAreaType(area),
latitude,
longitude,
walkTime: 0,
driveTime: 0,
});

const makeBuilding = async (apartmentWithId: ApartmentWithId) => {
Expand Down
72 changes: 48 additions & 24 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,54 @@ app.post('/api/new-review', authenticate, async (req, res) => {
}
});

// API endpoint to edit review by id
app.post('/api/edit-review/:reviewId', authenticate, async (req, res) => {
if (!req.user) {
throw new Error('not authenticated');
}
const { reviewId } = req.params;
try {
const reviewDoc = reviewCollection.doc(reviewId); // specific doc for the id
const reviewData = (await reviewDoc.get()).data();
if (!reviewData?.userId || reviewData.userId !== req.user.uid) {
res.status(401).send('Error: user is not the review owner. not authorized');
return;
}
const updatedReview = req.body as Review;
if (updatedReview.overallRating === 0 || updatedReview.reviewText === '') {
res.status(401).send('Error: missing fields');
return;
}
reviewDoc
.update({ ...updatedReview, date: new Date(updatedReview.date), status: 'PENDING' })
.then(() => {
res.status(201).send(reviewId);
});
} catch (err) {
console.error(err);
res.status(500).send('Error');
}
});

// API endpoint to get a specific review by its specific review ID
app.get('/api/review-by-id/:reviewId', async (req, res) => {
const { reviewId } = req.params; // Extract the review ID from the request parameters
try {
const reviewDoc = await reviewCollection.doc(reviewId).get(); // Get the review document from Firestore
if (!reviewDoc.exists) {
res.status(404).send('Review not found'); // If the document does not exist, return a 404 error
return;
}
const data = reviewDoc.data();
const review = { ...data, date: data?.date.toDate() } as ReviewInternal; // Convert the Firestore Timestamp to a Date object
const reviewWithId = { ...review, id: reviewDoc.id } as ReviewWithId; // Add the document ID to the review data
res.status(200).send(JSON.stringify(reviewWithId)); // Return the review data as a JSON response
} catch (err) {
console.error(err);
res.status(500).send('Error retrieving review'); // Handle any errors that occur during the process
}
});

// API endpoint to get reviews by ID, type and status
app.get('/api/review/:idType/:id/:status', async (req, res) => {
const { idType, id, status } = req.params;
Expand Down Expand Up @@ -441,30 +489,6 @@ app.post('/api/add-like', authenticate, likeHandler(false));

app.post('/api/remove-like', authenticate, likeHandler(true));

// Endpoint to update a review by its document ID
app.put('/api/:reviewId/edit', async (req, res) => {
try {
const { reviewId } = req.params; // Extract the review document ID from the request parameters
const review = req.body as Review; // Get the review data from the request body and cast it to the "Review" type

// Check if the required fields (overallRating and reviewText) are missing or invalid
if (review.overallRating === 0 || review.reviewText === '') {
res.status(401).send('Error: missing fields');
}

const newReview = { ...review, date: new Date(review.date), status: 'PENDING' };
// Update the review document in the database with the provided data
await reviewCollection.doc(reviewId).update(newReview);

// Send a success response with the updated review document ID
res.status(200).send(newReview);
} catch (err) {
// Handle any errors that may occur during the update process
console.error(err);
res.status(400).send('Error');
}
});

// Endpoint to delete a review by its document ID
app.put('/api/delete-review/:reviewId', async (req, res) => {
const { reviewId } = req.params; // Extract the review document ID from the request parameters
Expand Down
4 changes: 4 additions & 0 deletions common/types/db-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export type Apartment = {
readonly numBeds: number | null;
readonly photos: readonly string[]; // can be empty
readonly area: 'COLLEGETOWN' | 'WEST' | 'NORTH' | 'DOWNTOWN' | 'OTHER';
readonly latitude: number;
readonly longitude: number;
readonly walkTime: number;
readonly driveTime: number;
};

export type ApartmentWithId = Apartment & Id;
Expand Down
7 changes: 6 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
"@types/react-dom": "^16.9.8",
"@types/react-router-dom": "^5.1.6",
"@types/uuid": "^8.3.0",
"@vis.gl/react-google-maps": "^0.7.1",
"axios": "^0.21.0",
"date-fns": "^2.19.0",
"font-awesome": "^4.7.0",
"google-map-react": "^2.2.1",
"material-ui-search-bar": "^1.0.0",
"react": "^17.0.1",
"react-dom": "^17.0.1",
Expand Down Expand Up @@ -51,5 +53,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/google-map-react": "^2.1.10"
}
}
}
5 changes: 5 additions & 0 deletions frontend/src/assets/close-map-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions frontend/src/assets/drive-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions frontend/src/assets/expand-button.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions frontend/src/assets/location-pin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions frontend/src/assets/ph_map-pin-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions frontend/src/assets/recenter-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions frontend/src/assets/school-pin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions frontend/src/assets/walk-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/zoom-in-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added frontend/src/assets/zoom-out-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/src/components/Apartment/AptInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type Props = {
readonly contact: string | null;
readonly address: string | null;
readonly buildings: CardData[];
readonly latitude?: number;
readonly longitude?: number;
};

export default function AptInfo({
Expand All @@ -18,6 +20,8 @@ export default function AptInfo({
contact,
address,
buildings,
latitude = 0,
longitude = 0,
}: Props): ReactElement {
return (
<Box border={1} borderColor="grey.300" borderRadius={10}>
Expand Down
Loading

0 comments on commit f35a037

Please sign in to comment.