UVicMartletplace / martletplace

Recreating FB Marketplace for Students - UVic SENG499 Capstone Project
1 stars 0 forks source link

Gavin/50 implement return search results api #146

Closed GDeane closed 1 week ago

GDeane commented 3 weeks ago

Description

This is a PR showing the return search results API and its corresponding tests.

It Includes:

  1. 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.
  2. Pydantic BaseModels

  3. 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

  1. 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)

  2. Updating the user_searches table for search history purposes

Closes #50

How to Test

To run automatic tests:

  1. Checkout this branch
  2. In a terminal, navigate to the martletplace directory and run docker-compose up --build
  3. Wait a minute for the data layer (particularly elasticsearch) to get ready for input
  4. In a terminal, run docker exec -it martletplace_search bash
  5. In the bash terminal, run pytest src/test_server.py

Checklist

Additional Notes

  1. 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 image

  2. 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

GDeane commented 1 week ago

I still need to update based on the API spec requirement to also return the total number of search hits for pagination display reasons.