-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update listings when new search filter is applied
refs #49
- Loading branch information
1 parent
5cfd24c
commit 376d801
Showing
8 changed files
with
105 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { fetchMatchedListings } from "@/app/listings/actions"; | ||
|
||
export async function GET(request: Request) { | ||
// TODO: Read search filters from request, try HTTP headers? | ||
const listings = await fetchMatchedListings(); | ||
return Response.json({ listings }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
Listing, | ||
ListingSort, | ||
ListingsSearchFilters, | ||
ListingsSearchFiltersRequest, | ||
} from "./types"; | ||
|
||
export function countListingsToSkip(currentPage: number, countPerPage: number) { | ||
return (currentPage - 1) * countPerPage; | ||
} | ||
|
||
export function makeSearchFiltersRequest( | ||
original: ListingsSearchFilters | ||
): ListingsSearchFiltersRequest { | ||
return { | ||
price: { | ||
min: original.price.min.value, | ||
max: original.price.max.value, | ||
}, | ||
beds: original.beds.value, | ||
baths: original.baths.value, | ||
area: { | ||
min: original.area.min.value, | ||
max: original.area.max.value, | ||
}, | ||
}; | ||
} | ||
|
||
type ListingSortCompareFunction = (a: Listing, b: Listing) => number; | ||
|
||
export class ListingSortCompareFunctions { | ||
static #NEWEST: ListingSortCompareFunction = (a, b) => { | ||
if (a.createdDate < b.createdDate) { | ||
return 1; | ||
} | ||
|
||
if (a.createdDate === b.createdDate) { | ||
return 0; | ||
} | ||
|
||
return -1; | ||
}; | ||
|
||
static #PRICE_DESC: ListingSortCompareFunction = (a, b) => { | ||
return b.price.value - a.price.value; | ||
}; | ||
|
||
static #PRICE_ASC: ListingSortCompareFunction = (a, b) => { | ||
return a.price.value - b.price.value; | ||
}; | ||
|
||
static choose(sort: ListingSort): ListingSortCompareFunction { | ||
switch (sort) { | ||
case ListingSort.NEWEST: | ||
return ListingSortCompareFunctions.#NEWEST; | ||
break; | ||
case ListingSort.PRICE_DESC: | ||
return ListingSortCompareFunctions.#PRICE_DESC; | ||
break; | ||
case ListingSort.PRICE_ASC: | ||
return ListingSortCompareFunctions.#PRICE_ASC; | ||
break; | ||
default: | ||
return ListingSortCompareFunctions.#NEWEST; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters