Skip to content

The property buying and selling application built with Tornado Python Framework.

Notifications You must be signed in to change notification settings

yalinmuslem/Property-Trading-Application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Property Trading Application

The property buying and selling application built with Tornado Python Framework.This application has 3 main modules:

πŸ—οΈ Application architecture

1. Listing Service (services/listing_service.py)

  • Stores all the information about properties that are available to rent and buy

2. User Service (services/user_service.py)

  • Stores information about all the users in the system

3. Public API Layer (api/)

  • Set of APIs that are exposed to the web/public

πŸ“ Project structure

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

πŸš€ Way of running

1. Install Dependencies

pip install -r requirements.txt

2. Setup Environment

# Copy file environment
copy .env.example .env

# Edit file .env sesuai konfigurasi Anda

3. Setup Database

Make sure Mongodb has been installed and running:

# Default MongoDB connection: mongodb://localhost:27017/property_trading_app

4. Run the application

cd property_app
python main.py

The application will run on: http://localhost:8080

πŸ“š API Documentation

User Endpoints

  • 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,
    }
}

Property Endpoints

  • 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,
    }
}

Public User Endpoints

  • 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,
    }
}

Property Endpoints

  • 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,
    }
}

πŸ—„οΈ Database Schema

Users Collection

{
  _id: ObjectId,
  id: 1,
  name: "Suresh Subramaniam",
  created_at: 1475820997000000,
  updated_at: 1475820997000000,
}

Properties Collection

{
  _id: ObjectId,
  user_id: 1,
  listing_type: "rent",
  price: 6000,
  created_at: 1475820997000000,
  updated_at: 1475820997000000,
}

πŸ”§ Configuration

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 MongoDB
  • MONGO_PORT: Port MongoDB
  • MONGO_DB_NAME: namaDatabase

πŸ§ͺ Testing

For fire testing, you can use tools such as:

  • Postman
  • curl
  • HTTPie
  • Insomnia

πŸ‘¨β€πŸ’» Developer

Made by ** Yalinulloh ** for excercise Tornado Python Framework.


Happy Coding! πŸš€

About

The property buying and selling application built with Tornado Python Framework.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published