Skip to content

Commit 73de4d0

Browse files
committed
Add documentations
1 parent e4d29da commit 73de4d0

File tree

14 files changed

+344
-110
lines changed

14 files changed

+344
-110
lines changed

backend/src/app.ts

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,21 @@ app.get('/api/review/:location/count', async (req, res) => {
239239
res.status(200).send(JSON.stringify({ count: approvedReviewCount }));
240240
});
241241

242-
// API endpoint to get apartments by a list of IDs
242+
/**
243+
* Get Multiple Apartments by IDs – Retrieves multiple apartments by their document IDs.
244+
*
245+
* @remarks
246+
* This endpoint accepts a comma-separated list of apartment IDs and returns the corresponding apartment data.
247+
* Each ID is validated to ensure it exists in the database before returning the data.
248+
*
249+
* @route GET /api/apts/:ids
250+
*
251+
* @input {string} req.params.ids - Comma-separated list of apartment document IDs
252+
*
253+
* @status
254+
* - 200: Successfully retrieved apartment data for all provided IDs
255+
* - 400: Error retrieving apartments or invalid ID provided
256+
*/
243257
app.get('/api/apts/:ids', async (req, res) => {
244258
try {
245259
const { ids } = req.params;
@@ -376,6 +390,21 @@ app.post('/api/set-data', async (req, res) => {
376390
}
377391
});
378392

393+
/**
394+
* Search Apartments and Landlords – Performs a fuzzy search across both apartments and landlords.
395+
*
396+
* @remarks
397+
* This endpoint searches through apartment and landlord names/addresses using fuzzy matching.
398+
* Returns up to 5 combined results, with each result labeled as either LANDLORD or APARTMENT.
399+
*
400+
* @route GET /api/search
401+
*
402+
* @input {string} req.query.q - The search query string to match against names and addresses
403+
*
404+
* @status
405+
* - 200: Successfully retrieved and labeled search results
406+
* - 400: Error occurred while processing the search request
407+
*/
379408
app.get('/api/search', async (req, res) => {
380409
try {
381410
const query = req.query.q as string;
@@ -402,6 +431,21 @@ app.get('/api/search', async (req, res) => {
402431
}
403432
});
404433

434+
/**
435+
* Search Results - Retrieves enriched apartment data based on a text search query.
436+
*
437+
* @remarks
438+
* This endpoint performs a fuzzy search on apartment names and addresses using the provided query string.
439+
* The matching results are enriched with additional data like reviews and ratings before being returned.
440+
*
441+
* @route GET /api/search-results
442+
*
443+
* @input {string} req.query.q - The search query string to match against apartment names and addresses
444+
*
445+
* @status
446+
* - 200: Successfully retrieved and enriched the matching apartment results
447+
* - 400: Error occurred while processing the search request
448+
*/
405449
app.get('/api/search-results', async (req, res) => {
406450
try {
407451
const query = req.query.q as string;
@@ -484,7 +528,7 @@ app.get('/api/search-with-query-and-filters', async (req, res) => {
484528
);
485529
}
486530

487-
// TODO: Fix price filter
531+
// TODO: Right now we disable the price filter because of lack of data
488532
// Apply price range filters
489533
// if (minPrice !== null) {
490534
// filteredResults = filteredResults.filter((apt) => apt.price >= minPrice);
@@ -495,7 +539,7 @@ app.get('/api/search-with-query-and-filters', async (req, res) => {
495539
// }
496540

497541
// Apply bedroom filter
498-
// TODO: Fix amenities filter
542+
// TODO: Right now we disable the bedroom filter because of lack of data
499543
// if (bedrooms !== null && bedrooms > 0) {
500544
// filteredResults = filteredResults.filter(
501545
// (apt) => apt.numBeds !== null && apt.numBeds >= bedrooms
@@ -539,23 +583,21 @@ app.get('/api/search-with-query-and-filters', async (req, res) => {
539583
res.status(400).send('Error');
540584
}
541585
});
542-
543586
/**
544-
* Get Page Data - Retrieves paginated and sorted apartment data.
587+
* Get Paginated Apartment Data Retrieves paginated and sorted apartment listings.
545588
*
546589
* @remarks
547-
* This endpoint fetches apartment data with optional sorting and pagination. For the homepage, it retrieves all apartments
548-
* and sorts them by the specified criteria before applying pagination. For other pages, it applies pagination directly
549-
* from the database query.
590+
* Handles two different pagination strategies based on page type. For homepage, fetches all apartments and sorts them before paginating. For other pages, paginates directly from the database query. Enriches apartment data with reviews and ratings.
550591
*
551592
* @route GET /api/page-data/:page/:size/:sortBy?
552593
*
553-
* @input {string} req.params.page - The page type ('home' or other)
554-
* @input {string} req.params.size - Number of results to return
555-
* @input {string} req.params.sortBy - Optional sorting criteria ('numReviews', 'avgRating', or 'distanceToCampus')
594+
* @input {string} req.params.page - Page type ('home' or other) determining pagination strategy
595+
* @input {string} req.params.size - Number of results to return per page
596+
* @input {string} req.params.sortBy - Optional sorting field ('numReviews', 'avgRating', 'distanceToCampus')
556597
*
557598
* @status
558-
* - 200: Successfully retrieved and processed apartment data
599+
* - 200: Successfully retrieved paginated apartment data
600+
* - 400: Error retrieving or processing apartment data
559601
*/
560602
app.get('/api/page-data/:page/:size/:sortBy?', async (req, res) => {
561603
const { page, size, sortBy = 'numReviews' } = req.params;
@@ -606,6 +648,20 @@ app.get('/api/page-data/:page/:size/:sortBy?', async (req, res) => {
606648
res.status(200).send(returnData);
607649
});
608650

651+
/**
652+
* Get Apartments by Location - Retrieves all apartments from a specific location.
653+
*
654+
* @remarks
655+
* This endpoint fetches apartment data filtered by a single location parameter. The location is case-insensitive
656+
* and will be converted to uppercase before querying. Returns enriched apartment data including reviews and ratings.
657+
*
658+
* @route GET /api/location/:loc
659+
*
660+
* @input {string} req.params.loc - The location to filter apartments by (e.g. "Collegetown")
661+
*
662+
* @status
663+
* - 200: Successfully retrieved apartments for the specified location
664+
*/
609665
app.get('/api/location/:loc', async (req, res) => {
610666
const { loc } = req.params;
611667
const buildingDocs = (await buildingsCollection.where(`area`, '==', loc.toUpperCase()).get())
Lines changed: 22 additions & 0 deletions
Loading

frontend/src/components/Apartment/Marker.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ export type markerProp = {
88
readonly size: number;
99
};
1010

11+
/**
12+
* Marker - A component that renders a map marker image with specified position and size.
13+
*
14+
* @remarks
15+
* This component is used with Google Maps React to display custom markers on the map.
16+
* The marker image is positioned using CSS transforms and supports hover interactions.
17+
*
18+
* @param {string} props.src - The source URL for the marker image
19+
* @param {number} props.lat - The latitude coordinate for marker placement
20+
* @param {number} props.lng - The longitude coordinate for marker placement
21+
* @param {string} props.altText - Alt text description of the marker image
22+
* @param {number} props.size - Height in pixels for the marker image (width is calculated as 75% of height)
23+
*
24+
* @return {JSX.Element} - An img element styled as a map marker
25+
*/
26+
1127
export const Marker = ({ src, altText, size }: markerProp) => (
1228
<img
1329
src={src}

0 commit comments

Comments
 (0)