- Ensure you have Ruby and Rails installed.
- Install SQLite3 for the database.
- Install Postman for API testing.
-
Clone the Repository
git clone https://github.com/mrmind3312/roulette-api.git cd roulette-api
-
Install Dependencies
bundle install
-
Setup Database Create the database and seed it with initial data.
rails db:create rails db:migrate rails db:seed
-
Generate Devise JWT Secret Key Since the master key is not included in the repository, you need to create credentials.
rails secret
Copy the generated secret string and create the
devise_jwt_secret_key
:EDITOR="code --wait" bin/rails credentials:edit
Add the following entry:
devise_jwt_secret_key: <your_generated_secret>
-
Start the Rails Server
rails server
The API will be accessible at
http://localhost:3000
.
The application uses JWT for authentication. After a successful login, the JWT token is returned in the Authorization
header. This token is required for all subsequent requests.
A Postman collection is provided for testing the API. Import the Roulette API.postman_collection.json
file into Postman to access predefined requests.
-
Login
- URL:
{{URL}}/api/auth/login
- Method: POST
- Body:
{ "user": { "email": "[email protected]", "password": "192f6ce863aed79a" } }
- URL:
-
Postman Test Script This script extracts the JWT token from the
Authorization
header and sets it as an environment variable.// Check if the response contains the Authorization header const authHeader = pm.response.headers.get('Authorization'); if (authHeader) { pm.environment.set('TOKEN', authHeader.split(' ')[1]); } else { console.log('Authorization header not found in the response'); }
Populates the database with initial data.
rails db:seed
If you want to change the services and required times, please check and modify: db/seeds/001_services.rb
. Also, if you want to change users, adjust db/seeds/002_users.rb
.
This section covers the endpoints to manage user availability by week, day, and hour.
-
Create Availability
- URL:
{{URL}}/api/v1/users/:user_id/availabilities
- Method: POST
- Headers:
Authorization: Bearer {{TOKEN}}
- Body:
{ "day": 1, "week": 1, "month": 1, "year": 2024, "available": true, "services_id": null, // This param could be optional "catalog_hours_id": 2 }
- URL:
-
Get Availability
- URL:
{{URL}}/api/availabilities
- Method: GET
- Headers:
Authorization: Bearer {{TOKEN}}
- URL:
-
Update Availability
- URL:
{{URL}}/api/v1/users/:user_id/availabilities/:id
- Method: PUT
- Headers:
Authorization: Bearer {{TOKEN}}
- Body:
{ "day": 1, "week": 1, "month": 1, "year": 2024, "available": false, "services_id": 10, // This param could be optional "catalog_hours_id": 2 }
- URL:
-
Delete Availability
- URL:
{{URL}}/api/v1/users/:user_id/availabilities/:id
- Method: DELETE
- Headers:
Authorization: Bearer {{TOKEN}}
- URL:
The API auto-assigns hours based on the required service hours and the available hours set by the day of the week. The specifics of this process are handled internally by the application logic.
Ensure you have the Postman collection imported and the environment variables (URL
, TOKEN
) set appropriately to interact with the API. This documentation provides the necessary setup and usage instructions to get started with the Roulette API.