- Introduction
- Dependencies
- Architecture
- API Endpoints
- Running the Application
- Accessing the API Documentation
- TODO
This project is a REST API for managing operations related to creches, children, caregivers, and enrollments. The API allows for creating, reading, updating, and deleting records in a database.
Make sure to install the following dependencies:
- FastAPI
- Uvicorn
- SQLAlchemy
You can install these dependencies using pip:
pip install "fastapi[standard]" uvicorn sqlalchemy pydantic
The API is organized into several layers:
-
Lower Level: Database
The database stores all information related to crèches, children, caregivers, and enrollments. -
Operations on Database
This layer contains the business logic for interacting with the database, including creating, reading, updating, and deleting records. -
API Router Layer
This layer allows us to choose which type of operations to perform based on the HTTP request. It manages the routes and endpoints of the API.
-
Get All Parents
curl -X GET "http://localhost:8000/parents"
-
Create a Parent
curl -X POST "http://localhost:8000/parents" -H "Content-Type: application/json" -d '{"first_name": "Jane", "last_name": "Doe", "email_address": "[email protected]", "phone_number": "+123456789"}'
-
Get a Parent by ID
curl -X GET "http://localhost:8000/parents/1"
-
Update a Parent
curl -X PUT "http://localhost:8000/parents/1" -H "Content-Type: application/json" -d '{"first_name": "Jane", "last_name": "Smith", "email_address": "[email protected]", "phone_number": "+987654321"}'
-
Delete a Parent by ID
curl -X DELETE "http://localhost:8000/parents/1"
-
Get Children of a Parent
curl -X GET "http://localhost:8000/parents/1/children"
-
Add a Child to a Parent
curl -X POST "http://localhost:8000/parents/1/children" -H "Content-Type: application/json" -d '{"child_id": 1}'
-
Remove a Child from a Parent
curl -X DELETE "http://localhost:8000/parents/1/children/1"
-
Get All Children
curl -X GET "http://localhost:8000/children"
-
Create a Child
curl -X POST "http://localhost:8000/children" -H "Content-Type: application/json" -d '{"first_name": "John", "last_name": "Doe", "date_of_birth": "2020-01-01", "parent_id": 1}'
-
Get a Child by ID
curl -X GET "http://localhost:8000/children/1"
-
Get All Caregivers
curl -X GET "http://localhost:8000/caregivers"
-
Create a Caregiver
curl -X POST "http://localhost:8000/caregivers" -H "Content-Type: application/json" -d '{"first_name": "Jane", "last_name": "Doe", "qualifications": "Bachelor Degree in Early Childhood Education", "years_of_experience": 5, "caregiver_email_address": "[email protected]", "caregiver_phone_number": "+123456789"}'
-
Get a Caregiver by ID
curl -X GET "http://localhost:8000/caregivers/1"
-
Get All Enrollments
curl -X GET "http://localhost:8000/enrollments"
-
Create an Enrollment
curl -X POST "http://localhost:8000/enrollments" -H "Content-Type: application/json" -d '{"start_date": "2024-01-01", "end_date": "2024-01-05", "child_id": 1, "caregiver_id": 1, "creche_id": 1, "parent_id": 1, "price": 100}'
-
Get an Enrollment by ID
curl -X GET "http://localhost:8000/enrollments/1"
-
Delete an Enrollment by ID
curl -X DELETE "http://localhost:8000/enrollments/1"
-
Get Enrollments by Creche and Price
curl -X GET "http://localhost:8000/enrollments/creche/1/price/100"
-
Get All Creches
curl -X GET "http://localhost:8000/creches"
-
Create a Creche
curl -X POST "http://localhost:8000/creches" -H "Content-Type: application/json" -d '{"name": "Creche A", "address": "123 Rue Exemple", "capacity": 30}'
-
Get a Creche by ID
curl -X GET "http://localhost:8000/creches/1"
To run the FastAPI application, use the following command:
uvicorn main:app --reload
- The
--reload
option allows the server to automatically reload when you make changes to the code.
You can access the interactive API documentation provided by FastAPI by navigating to the following URL in your web browser:
http://127.0.0.1:8000/docs
-
Implement Authentication and Authorization
Add user authentication and authorization to secure the API endpoints. -
Add Unit Tests
Write unit tests for all API endpoints and database operations to ensure code reliability and facilitate future changes. -
Frontend Integration
Develop a frontend application that interacts with the API to provide a user-friendly interface for managing crèches, children, caregivers, and enrollments. -
Containerization
Containerizing the application using Docker for easier deployment and scalability.