/real-estate-api

Real Estate API without using any framework.

Primary LanguagePythonMIT LicenseMIT

Real Estate API

This project contains 2 microservices, the first is built without using any framework and the second is conceptual.

The main idea is having a tool for users who want to search sold and available properties. Also, they can use different filters like status, year and city. In adittion to this, users can like their favorite properties in order to have an internal ranking.

1. Search microservice

Technologies

The used technologies were:

Execution

App in development mode

First of all, you need to have a working environment:

$ python3.10 -m venv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ source .env.dev

Later, you can run the app:

$ python main.py

App in production mode with Docker Compose

$ docker build -t stivenramireza/real-estate-api:latest .
$ docker push stivenramireza/real-estate-api:latest
$ docker-compose up -d
$ docker logs -f real_estate_api

App in production mode with Docker Swarm and Traefik

$ docker build -t stivenramireza/real-estate-api:latest .
$ docker push stivenramireza/real-estate-api:latest
$ docker stack deploy -c stack.yml production --with-registry-auth
$ docker service logs -f production_real-estate-api

The execution of the API in production mode was recorded in a Loom video that you can check in this link:

https://www.loom.com/share/f049c101bb8846fe84b3df0e943b4357

Testing

Unit tests

In this case some units tests were created in order to check the property service is running successfully.

$ python -m unittest tests/**/*.py --verbose

2. "Like" microservice

This microservice allows users like a specific property after their register in the database.

Entity Relationship diagram

The database model would extend in this way because we can ensure that a user can have multiple liked properties. For that reason is necessary establish the user_id and property_id foreign keys related to the auth_user (registered users) and property (properties) tables respectively.

In addition to this, a new field active will be added that can be important for data analytics cause we could have a register of the user who liked a property and later unliked it. In this case we need to establish a business strategy, if applicable, where we can validate when users stopped being interested the property and how we could recommend similar properties or they adjust the new necessity of the customers.

The SQL sentence in order to extend this model:

CREATE TABLE liked_properties ( 
    id INT NOT NULL AUTO_INCREMENT, 
    user_id INT NOT NULL, 
    property_id INT NOT NULL, 
    active BIT,
    create_date DATETIME DEFAULT CURRENT_TIMESTAMP,
    update_date DATETIME DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (id), 
    FOREIGN KEY (user_id) REFERENCES auth_user(id), 
    FOREIGN KEY (property_id) REFERENCES property(id) 
);