This is a PR showing the return search results API and its corresponding tests.
It Includes:
All of these Request Payload Parameters implemented, supported, and tested:
authorization (string, required): The user token for authentication.
query (string, required): The search query text.
minPrice (number, optional): Minimum price.
maxPrice (number, optional): Maximum price.
status (enum, optional): Filter by status - one of [SOLD, AVAILABLE] - default to AVAILABLE.
searchType (enum, optional): Filter by users or listings - one of [USERS, LISTINGS] - default to LISTINGS.
latitude : (float, required): The latitude to search within 5 km of
longitude: (float, required): The longitude to search within 5 km of
sort (enum, optional): Sorting criteria - one of [RELEVANCE, PRICE_ASC, PRICE_DESC, LISTED_TIME_ASC, LISTED_TIME_DESC, DISTANCE_ASC, DISTANCE_DESC] (defaults to relevance).
page (integer, optional): Page number for pagination.
limit (integer, optional): Number of results per page.
Pydantic BaseModels
Integration tests using a test-index which is initialized before each test and destroyed after each test. All tests use the elasticsearch endpoint.
It DOES NOT INCLUDE
Dealing with the authorization cookie (@MNThomson) was going to set that up on Tuesday if it wasn't done by then. For now there is no use for the userID (that will be needed for dealing with search history)
Updating the user_searches table for search history purposes
Closes #50
How to Test
To run automatic tests:
Checkout this branch
In a terminal, navigate to the martletplace directory and run docker-compose up --build
Wait a minute for the data layer (particularly elasticsearch) to get ready for input
In a terminal, run docker exec -it martletplace_search bash
In the bash terminal, run pytest src/test_server.py
Checklist
[X] The code includes tests if relevant
[x] I have actually self-reviewed my changes and done QA
Additional Notes
As seen in test_server.py, it is important that the location (latitude and longitude) is set up as a geo_point for elasticsearch to work. It is also important that the parameters passed are named "lat" and "lon" as opposed to "latitude" and "longitude" (this is relevant to @emilasuska for implementing the reindexing methods)
I am unsure about some of the error codes that are used. The reason I have used code 422 (Unprocessable Content) a lot is because FastAPI uses it a lot for its built-in error handling. Please call me out for anything that should be changed though
Description
This is a PR showing the return search results API and its corresponding tests.
It Includes:
All of these Request Payload Parameters implemented, supported, and tested:
Pydantic BaseModels
Integration tests using a test-index which is initialized before each test and destroyed after each test. All tests use the elasticsearch endpoint.
It DOES NOT INCLUDE
Dealing with the authorization cookie (@MNThomson) was going to set that up on Tuesday if it wasn't done by then. For now there is no use for the userID (that will be needed for dealing with search history)
Updating the user_searches table for search history purposes
Closes #50
How to Test
To run automatic tests:
docker-compose up --build
docker exec -it martletplace_search bash
pytest src/test_server.py
Checklist
Additional Notes
As seen in test_server.py, it is important that the location (latitude and longitude) is set up as a geo_point for elasticsearch to work. It is also important that the parameters passed are named "lat" and "lon" as opposed to "latitude" and "longitude" (this is relevant to @emilasuska for implementing the reindexing methods)
![image](https://github.com/UVicMartletplace/martletplace/assets/90437591/9c88dbed-2e08-464e-87a0-79bc8f06db5e)
I am unsure about some of the error codes that are used. The reason I have used code 422 (Unprocessable Content) a lot is because FastAPI uses it a lot for its built-in error handling. Please call me out for anything that should be changed though