This is a REST API built with Ruby on Rails to manage employee time-off requests (vacations and sick leaves). The API includes authentication, pagination, filters, and the ability to calculate the total vacation days an employee has taken per year.
The frontend repository for this API is this.
The URL in production for this API is https://vacationsapi-production.up.railway.app/.
- Ruby 3.3.5
- Rails 7.2.2
- PostgreSQL
- Clone the repository:
git@github.com:SegundoRP/vacations_api.git
cd vacations_api
- Install dependencies:
bundle install
- Set up the database:
rails db:create
rails db:migrate
- Import initial data from a Google Sheet:
rake db:seed_from_google_sheet
- Start the server:
rails server
- Install dependencies:
bundle install
-
Method: POST
-
URL: /auth
-
Body:
{ "name": "User Name", "email": "user@example.com", "password": "password123", "password_confirmation": "password123" }
-
Method: POST
-
URL: /auth/sign_in
-
Body:
{ "email": "user@example.com", "password": "password123" }
-
Method: POST
-
URL: /auth
-
Body:
{ "name": "User Name", "email": "user@example.com", "password": "password123", "password_confirmation": "password123" }
- Method: DELETE
- URL: /auth/sign_out
- Headers:
- access-token
- client
- uid
-
Method: GET
-
URL: /api/v1/time_off_requests
-
Headers:
- access-token
- client
- uid
-
Optional Parameters:
- filters[status_eq]: Filter by status (approved, rejected).
- filters[request_type_eq]: Filter by request type (vacation, incapacity).
- filters[start_date_gteq]: Filter by start date greater than or equal to.
- filters[start_date_lteq]: Filter by start date less than or equal to.
- page: Page number for pagination.
- per_page: Number of items per page.
-
Method: GET
-
URL: /api/v1/time_off_requests/:id
-
Headers:
- access-token
- client
- uid
-
Method: POST
-
URL: /api/v1/time_off_requests
-
Headers:
- access-token
- client
- uid
-
Body:
{
"start_date": "2023-10-10",
"end_date": "2023-10-15",
"request_type": "vacation",
"status": "approved",
"reason": "Family vacation",
"user_id": 1
}
-
Method: PUT
-
URL: /api/v1/time_off_requests/:id
-
Headers:
- access-token
- client
- uid`
-
Body:
{
"status": "rejected"
}
- Method: DELETE
- URL: /api/v1/time_off_requests/:id
- Headers:
- access-token
- client
- uid
-
Method: GET
-
URL: /api/v1/users/:id/vacation_days
-
Parameters:
- year: The year for which to calculate vacation days.
-
Headers:
- access-token
- client
- uid
-
Body:
{
"user_id": 1,
"name": "User Name",
"year": 2023,
"vacation_days": 10
}
The application includes a service to import data from a Google Sheet and save it to the database. This service can be run with the following command:
rails db:seed_from_google_sheet
- Authentication: devise_token_auth
- Pagination: kaminari
- Filters: ransack
- Data Import: roo
- JSON API Serialization: jsonapi-resources
- CORS: rack-cors
To run the test suite, use the following command:
bundle exec rspec
Get Vacation Days for a User
curl -v \
-H "access-token: <ACCESS_TOKEN>" \
-H "client: <CLIENT>" \
-H "uid: <EMAIL>" \
-H "Content-Type: application/json" \
-X GET http://localhost:3000/api/v1/users/1/vacation_days?year=2023 | jq
List Time-Off Requests
curl -v \
-H "access-token: <ACCESS_TOKEN>" \
-H "client: <CLIENT>" \
-H "uid: <EMAIL>" \
-H "Content-Type: application/json" \
-X GET http://localhost:3000/api/v1/time_off_requests\?fil
52CA
ters%5Bstatus_eq%5D\=0 | jq