Tender Blueprint
This Flask file serves as a blueprint for managing tender-related endpoints in an application. Below is a breakdown of the tenders_bp blueprint’s capabilities and functionalities, including route descriptions and their corresponding actions:
Blueprint Setup
- Blueprint Name:
tenders - Prefix:
/tenders - Imported Modules: Uses Flask for the web framework,
json_utilfrombsonfor JSON serialization, custom model and function imports for database interactions and business logic.
Routes and Endpoints
Get Tenders by Country
- Endpoint:
/by-country - Method:
GET - Description: Retrieves tenders filtered by a specific country. Requires a
countryparameter in the query string. Returns an error if thecountryparameter is not provided. This is used on the rifbid landing page.
Get Latest Tenders Near User
- Endpoint:
/latest - Method:
GET - Description: Fetches the latest tenders based on the user’s current location, determined using the user’s IP address and the IPSTACK API. This is used on the rifbid landing page.
Get All Tenders
- Endpoint:
/ - Method:
GET - Description: Returns all tenders, supporting filtering by location, category, date, and search query. Pagination is handled through
pageanditems_per_pageparameters.
Semantic Search Tenders
- Endpoint:
/semantic_search - Method:
GET - Description: Performs a semantic search on tenders based on a given search query and additional filters such as location and category. Checks user’s access rights and tier before allowing the search.
Find Similar Tenders
- Endpoint:
/similar-tenders - Method:
POST - Description: Returns tenders similar to a provided tender description. It uses document embeddings to find tenders with similar content.
CRUD Operations for Tenders
-
Add a Tender
- Endpoint:
/ - Method:
POST - Description: Allows authorized users to add a new tender to the database.
- Endpoint:
-
Update a Tender
- Endpoint:
/<id> - Method:
PUT - Description: Updates an existing tender specified by its ID. Only accessible to authorized users.
- Endpoint:
-
Delete a Tender
- Endpoint:
/<id> - Method:
DELETE - Description: Deletes a tender specified by its ID. Restricted to authorized users.
- Endpoint:
-
Get a Single Tender
- Endpoint:
/<id> - Method:
GET - Description: Retrieves details of a specific tender by its ID. Requires user authentication.
- Endpoint:
Additional Functionalities
- Get Tender Count
- Endpoint:
/count - Method:
GET - Description: Returns the total number of tenders in the database, adjusted by a hardcoded value for demonstration or test purposes.
- Endpoint:
Security and Authentication
- Most routes require user authentication, which is handled by the
get_current_userfunction. This function ensures that only authorized users can access sensitive tender data and perform operations such as adding, updating, or deleting tenders.
This blueprint effectively modularizes the tender management functionalities within the application, making the codebase easier to maintain and scale.