This repository is a source code of the Time Off Manager - tutorial published as part of boringSQL.
You can find the individual parts of the tutorial here:
Before you begin, ensure you have the following installed on your system:
- PostgreSQL
- postgREST
git clone https://github.com/yourusername/time-off-manager.git
cd time-off-manager
Create the database
psql template1 -c "CREATE DATABASE time_off_manager"
Create the schema and seed the database
psql time_off_manager <db/001_part1_schema.sql
psql time_off_manager <db/002_part2_api.sql
psql time_off_manager <db/seed.sql
Before you can start the server, please, update the db-uri
in included postgrest.conf
. Once updated simply start the postgREST server
postgrest
Here are some basic cURL commands to interact with the API:
-
Get all users:
curl "http://localhost:3000/users"
-
Add a new user:
curl "http://localhost:3000/rpc/add_user" -X POST \ -d '{ "email": "admin2@example.com", "manager_id": 2 }' \ -H "Content-Type: application/json"
-
Request time off for specific user
curl -X POST "http://localhost:3000/rpc/request_time_off" \ -d '{"user_id": 6, "leave_type": "vacation", "period": "[2024-05-20,2024-05-21]"} ' \ -H "Content-Type: application/json"
-
Approve the time off request
curl -X POST "http://localhost:3000/rpc/update_request" \ -d '{"request_id": 1, "user_id": 2, "new_status": "approved"}' \ -H "Content-Type: application/json"
Contributions are welcome! Please feel free to submit pull requests, create issues, or suggest improvements.
This project is licensed under the MIT License - see the LICENSE file for details.