Clone the repo first: git clone https://github.com/teavver/hydro-api && cd hydro-api
docker-compose up
(-d
for detached mode)
-
Create a virtual environment:
python3 -m venv venv
-
Activate the environment:
- On Unix/macOS:
. venv/bin/activate
- On Windows:
.\venv\Scripts\activate
- On Unix/macOS:
-
Install the dependencies:
pip install -r requirements.txt && cd hydro
-
Run database migrations:
python manage.py migrate
-
Run the development server:
python manage.py runserver 0.0.0.0:8000
-
Access the application at
http://localhost:8000
.
- Docker:
- Migrate first:
docker-compose exec web python manage.py migrate
- Running tests:
docker-compose exec web python manage.py test
- Migrate first:
- Local (venv):
python manage.py test
Makemigrations: docker-compose exec web python manage.py makemigrations
Migrate changes: docker-compose exec web python manage.py migrate
Create a User account in order to access the Systems API
{
"username": "string",
"password": "string"
}
{
"username": "string",
"password": "string"
}
Returns the authentication token
in response body on success
{
"id": "uniqueId",
"name": "string",
"created_at": "datetime",
"owner": "userId"
}
The systems API provides endpoints for managing hydroponic systems and their measurements.
All system endpoints require the auth token
.
List all systems owned by an authenticated User or create a new System
[
{
"id": 8,
"measurement_count": 0,
"name": "testSystem2",
"created_at": "2024-06-02T19:22:24.887014Z",
"owner": 8
},
{
"id": 7,
"measurement_count": 0,
"name": "testSystem1",
"created_at": "2024-06-02T19:22:24.886759Z",
"owner": 8
}
]
{
"name": "NameOfNewSystem"
}
Get information about a specific System, update it, or delete it permanently. Deleting a System will delete all Measurements inside it.
{
"id": 7,
"measurement_count": 0,
"name": "testSystem1",
"created_at": "2024-06-02T19:22:24.886759Z",
"owner": 8
}
{
"name": "UpdatedSystemName"
}
{
"id": "uniqueId",
"pH": "float",
"temperature": "float",
"TDS": "float",
"created_at": "datetime",
"system": "systemId"
}
List all measurements for the authenticated user's systems or create a new measurement. Supports filtering and sorting by date, temperature, pH, and TDS.
- Filtering: You can filter measurements by date, temperature, pH, and TDS.
- Sorting: You can sort measurements by created_at, temperature, pH, and TDS.
api/systems/measurements/?created_at=2024-06-01
: Filter by date.api/systems/measurements/?temperature__gte=20
: Filter by temperature greater than or equal to 20.api/systems/measurements/?pH__lte=7
: Filter by pH less than or equal to 7.?ordering=temperature
: Sort by temperature.
[
{
"id": 1,
"system": 7,
"temperature": 22.5,
"pH": 6.8,
"TDS": 500,
"created_at": "2024-06-02T19:22:24.887014Z"
},
{
"id": 2,
"system": 7,
"temperature": 21.0,
"pH": 6.5,
"TDS": 550,
"created_at": "2024-06-02T19:22:24.886759Z"
}
]
{
"system": "systemId",
"temperature": 22.5,
"pH": 6.8,
"TDS": 500
}
Retrieve the 10 latest measurements for a specific hydroponic system owned by the authenticated user.
All list endpoints use page number pagination (10
by default)