Rentify API

This project is a Real Estate Property Management aka Rentify API designed to handle property listings, user interactions such as likes and interests, and property searches. This API is built using Hapi.js, PostgreSQL, and JWT for authentication. The goal of the project is to provide a robust backend for managing real estate listings, enabling users to search properties, like them, and express interest.

Table of Contents

Features

  • User authentication using JWT.

  • Search properties based on location, area, number of bedrooms/bathrooms, and price.

  • Like properties and view liked properties.

  • Express interest in properties and receive confirmation via email.

  • View top properties based on user location and likes.

Project Structure

|   .env
|   .env.example
|   .gitignore
|   nodemon.json
|   package-lock.json
|   package.json
|   tree.txt
|   tsconfig.json
|           
+---scripts
|       setupDB.ts
|       
\---src
    |   index.ts
    |   
    +---assets
    |   \---mailTemplates
    |           accountVerification.html
    |           interested.html
    |           
    +---controllers
    |       assetsController.ts
    |       buyerController.ts
    |       openController.ts
    |       sellerController.ts
    |       userController.ts
    |       
    +---helper
    |       env.ts
    |       ipInfo.ts
    |       mailer.ts
    |       mongodb.ts
    |       postgres.ts
    |       randomID.ts
    |       
    +---interfaces
    |       ipInfo.ts
    |       
    +---models
    |       imagesModel.ts
    |       
    \---routes
            assetsRoutes.ts
            buyerRoutes.ts
            openRoutes.ts
            sellerRoutes.ts
            userRoutes.ts

Key Files and Directories

  • controllers/: Contains the API logics.

  • helper/env.ts: Handles environment variables.

  • helper/mailer.ts: Manages sending emails.

  • helper/postgres.ts: Sets up and manages the PostgreSQL client.

  • helper/ipInfo.ts: Retrieves user location based on IP address.

  • tests/: Contains test cases for the API.

Setup Instructions

  1. cd real-estate-api

  2. npm install

  3. JWTSECRET=yourjwtsecretAPIVERSION=v1POSTGRESUSER=yourpostgresuserPOSTGRESPASSWORD=yourpostgrespasswordPOSTGRESDB=yourpostgresdbPOSTGRESHOST=yourpostgreshostPOSTGRESPORT=yourpostgresportEMAILHOST=youremailhostEMAILPORT=youremailportEMAILUSER=youremailuserEMAILPASSWORD=youremail_password

    Create a .env file in the root directory and add the following:

  4. Set up PostgreSQL

    Ensure you have PostgreSQL installed and running. Create a database and update the .env file with your PostgreSQL credentials.

  5. npm run dev

  6. npm test

API Endpoints

Authentication

  • Login: POST /api/v1/auth/login

  • Register: POST /api/v1/auth/register

Property Management

  • Search Properties: GET /api/v1/properties/search

    • Query parameters: location, area, bedrooms, bathrooms, maxPrice, page, limit
  • Get Property Details: GET /api/v1/properties/{propertyId}

  • Get Top Properties: GET /api/v1/properties/top

    • Query parameters: page, limit
  • Like Property: POST /api/v1/properties/{propertyId}/like

    • Authorization: Bearer token
  • Get Liked Properties: GET /api/v1/properties/liked

    • Query parameters: page, limit
    • Authorization: Bearer token
  • Express Interest in Property: POST /api/v1/properties/{propertyId}/interest

    • Authorization: Bearer token
  • Get Interested Properties: GET /api/v1/properties/interested

    • Query parameters: page, limit
    • Authorization: Bearer token

Technologies Used

  • Node.js: JavaScript runtime for building the backend.

  • Hapi.js: Framework for building the API.

  • PostgreSQL: Database for storing property and user data.

  • JWT: JSON Web Tokens for authentication.

  • nodemailer: Sending emails.

  • TypeScript: Superset of JavaScript for type safety.

Contributing

We welcome contributions! Follow these steps:

  1. Fork the repository.

  2. Create a new branch (git checkout -b feature/your-feature).

  3. Commit your changes (git commit -am 'Add your feature').

  4. Push to the branch (git push origin feature/your-feature).

  5. Create a new Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for more information.