- Introduction
- Requirements
- Installation
- Database Setup
- Running the Application
- Running Tests
- Useful Commands
This project is a RESTful API built using Ruby on Rails, focused solely on providing back-end functionality with no front-end interface. The API allows full CRUD operations for both Users and Offices, enabling creation, updating, retrieval, and deletion of records.
You can find the postman collection here https://documenter.getpostman.com/view/13192503/2sAXqngQcf#auth-info-8736b024-4486-4927-a9cf-59d6252055ae
-
CRUD for Users and Offices: The API provides endpoints to manage users and offices. Each entity can be created, updated, retrieved, and deleted through RESTful API requests.
-
JWT Authentication: Secure access to the API is managed through JWT (JSON Web Token) authentication. This ensures that only authenticated users can access protected resources. To log in, use the default credentials:
- Email:
[email protected]
- Password:
12345678
- Email:
-
Many-to-Many Relationship:
- Users and Offices are connected via a many-to-many relationship. This means:
- A user can belong to multiple offices.
- An office can have multiple users associated with it.
- The relationship is managed via a join table, allowing flexible assignment of users to offices and vice versa.
- Users and Offices are connected via a many-to-many relationship. This means:
-
Tests cases:
- Users
- Offices
- OfficeUsers
- Tests can be run in the 6. Running Tests topic
- JWT tokens are issued upon login and must be included in the
Authorization
header for accessing protected routes. - Example login credentials are provided for an admin user, but the API allows the creation of additional users through the user management endpoints.
This API is designed to be easily integrated into other services or front-end applications, offering a solid foundation for managing user and office data securely and efficiently.
Before setting up the project, ensure you have the following tools installed on your machine:
- Ruby:
>= 3.3.4
- Rails:
>= 7.2.1
- Bundler:
>= 2.5.18
- sqlite3 (or any other DB you're using)
Follow these steps to set up and run the project locally:
-
Clone the repository:
git clone https://github.com/MarceloZapatta/real-estate-ruby-rails.git cd real-estate-ruby-rails
-
Install dependencies:
Make sure you have Bundler installed, then run:
bundle install
-
Create the database:
Run the following command to create the database:
rails db:create
-
Run migrations:
To set up the database schema, run:
rails db:migrate
-
Seed the database (Optional):
To populate the database with seed data, run:
rails db:seed
Once the dependencies and database are set up, you can run the Rails server with the following command:
rails server
The application will be available at http://localhost:3000.
Default user:
- Email:
[email protected]
- Password:
12345678
To run the test suite, use the following command:
rails test
- Start the server:
rails server
- Run migrations:
rails db:migrate
- Create the database:
rails db:create
- Drop the database:
rails db:drop
- Reset the database:
rails db:reset
- Run seeds:
rails db:seed
- Run tests:
rails test
orrspec
- Console:
rails console