The property buying and selling application built with Tornado Python Framework.This application has 3 main modules:
- Stores all the information about properties that are available to rent and buy
- Stores information about all the users in the system
- Set of APIs that are exposed to the web/public
property_app/
βββ main.py # Entry point aplikasi
βββ config/
β βββ settings.py # Application configuration
βββ models/
β βββ property.py # Property Model and Schema
β βββ user.py # User model and schema
βββ services/
β βββ listing_service.py # Business logic for property
β βββ user_service.py # Business logic for users
βββ api/
β βββ base_handler.py # Base handler with utilities
β βββ user_handlers.py # API Handlers for User
β βββ property_handlers.py # API Handlers for Property
β βββ routes.py # Routing configuration
βββ utils/
β βββ database.py # databaseConnectionManager
βββ .env.example # Template environment variables
pip install -r requirements.txt# Copy file environment
copy .env.example .env
# Edit file .env sesuai konfigurasi AndaMake sure Mongodb has been installed and running:
# Default MongoDB connection: mongodb://localhost:27017/property_trading_appcd property_app
python main.pyThe application will run on: http://localhost:8080
GET /users- Returns all the users available in the db (sorted in descending order of creation date).
URL: GET /users
Parameters:
page_num = int # Default = 1
page_size = int # Default = 10
Response:
{
"result": true,
"users": [
{
"id": 1,
"name": "Suresh Subramaniam",
"created_at": 1475820997000000,
"updated_at": 1475820997000000,
}
]
}GET /users/1- Retrieve a user by ID
URL: GET /users/{id}
Response:
{
"result": true,
"user": {
"id": 1,
"name": "Suresh Subramaniam",
"created_at": 1475820997000000,
"updated_at": 1475820997000000,
}
}POST /users- Create user
URL: POST /users
Content-Type: application/x-www-form-urlencoded
Parameters: (All parameters are required)
name = str
Response:
{
"result": true,
"user": {
"id": 1,
"name": "Suresh Subramaniam",
"created_at": 1475820997000000,
"updated_at": 1475820997000000,
}
}GET /listings- Returns all the listings available in the db (sorted in descending order of creation date). Callers can use page_num and page_size to paginate through all the listings available. Optionally, you can specify a user_id to only retrieve listings created by that user.
URL: GET /listings
Parameters:
page_num = int # Default = 1
page_size = int # Default = 10
user_id = str # Optional. Will only return listings by this user if specified
Response:
{
"result": true,
"listings": [
{
"id": 1,
"user_id": 1,
"listing_type": "rent",
"price": 6000,
"created_at": 1475820997000000,
"updated_at": 1475820997000000,
}
]
}POST /listings- Create listing
URL: POST /listings
Content-Type: application/x-www-form-urlencoded
Parameters: (All parameters are required)
user_id = int
listing_type = str
price = int
Response:
{
"result": true,
"listing": {
"id": 1,
"user_id": 1,
"listing_type": "rent",
"price": 6000,
"created_at": 1475820997000000,
"updated_at": 1475820997000000,
}
}GET /public-api/users- Get all the listings available in the system (sorted in descending order of creation date). Callers can use page_num and page_size to paginate through all the listings available. Optionally, you can specify a user_id to only retrieve listings created by that user.
URL: GET /public-api/listings
Parameters:
page_num = int # Default = 1
page_size = int # Default = 10
user_id = str # Optional
{
"result": true,
"listings": [
{
"id": 1,
"listing_type": "rent",
"price": 6000,
"created_at": 1475820997000000,
"updated_at": 1475820997000000,
"user": {
"id": 1,
"name": "Suresh Subramaniam",
"created_at": 1475820997000000,
"updated_at": 1475820997000000,
},
}
]
}POST /public-api/users- Create user
URL: POST /public-api/users
Content-Type: application/json
Request body: (JSON body)
{
"name": "Lorel Ipsum"
}Response:
{
"user": {
"id": 1,
"name": "Lorel Ipsum",
"created_at": 1475820997000000,
"updated_at": 1475820997000000,
}
}GET /public-api/listings- Get all the listings available in the system (sorted in descending order of creation date). Callers can use page_num and page_size to paginate through all the listings available. Optionally, you can specify a user_id to only retrieve listings created by that user.
URL: GET /public-api/listings
Parameters:
page_num = int # Default = 1
page_size = int # Default = 10
user_id = str # Optional
{
"result": true,
"listings": [
{
"id": 1,
"listing_type": "rent",
"price": 6000,
"created_at": 1475820997000000,
"updated_at": 1475820997000000,
"user": {
"id": 1,
"name": "Suresh Subramaniam",
"created_at": 1475820997000000,
"updated_at": 1475820997000000,
},
}
]
}POST /public-api/listings- Create listing
URL: POST /public-api/listings
Content-Type: application/json
Request body: (JSON body)
{
"user_id": 1,
"listing_type": "rent",
"price": 6000
}Response:
{
"listing": {
"id": 143,
"user_id": 1,
"listing_type": "rent",
"price": 6000,
"created_at": 1475820997000000,
"updated_at": 1475820997000000,
}
}{
_id: ObjectId,
id: 1,
name: "Suresh Subramaniam",
created_at: 1475820997000000,
updated_at: 1475820997000000,
}{
_id: ObjectId,
user_id: 1,
listing_type: "rent",
price: 6000,
created_at: 1475820997000000,
updated_at: 1475820997000000,
}All configurations can be adjusted through the Environment Variables or Files .env:
PORT: Port server (default: 8080)DEBUG: Mode debug (default: False)MONGO_HOST: Host MongoDBMONGO_PORT: Port MongoDBMONGO_DB_NAME: namaDatabase
For fire testing, you can use tools such as:
- Postman
- curl
- HTTPie
- Insomnia
Made by ** Yalinulloh ** for excercise Tornado Python Framework.
Happy Coding! π