Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/diarpicu2022-commits/backend-AgroPulse/llms.txt

Use this file to discover all available pages before exploring further.

The Greenhouses API is the central resource in AgroPulse. Each greenhouse represents a physical growing environment monitored by IoT sensors. You can create and manage greenhouse records, update their metadata (name, location, GPS coordinates, photo), and control which users are assigned to each greenhouse. Write operations on a greenhouse require that the caller is either the greenhouse owner or an administrator — identified via request headers.
Ownership restriction: PUT /api/greenhouses/{id} and DELETE /api/greenhouses/{id} check the X-User-Id request header against the greenhouse’s ownerId. Users who are neither the owner nor an admin (identified by the X-Admin-Email header matching the AGROPULSE_ADMIN_EMAIL environment variable) receive a 403 Forbidden response.
Returns all greenhouses stored in the system.Response
greenhouses
array
Array of greenhouse objects.
curl http://localhost:8080/api/greenhouses
{
  "greenhouses": [
    {
      "id": 1,
      "name": "Invernadero Norte",
      "location": "Sector A",
      "description": "Producción de tomate cherry",
      "ownerId": 3,
      "active": true,
      "latitude": 40.4168,
      "longitude": -3.7038,
      "photoUrl": "https://example.com/photos/gh1.jpg",
      "createdAt": "2024-03-01T08:00:00"
    }
  ]
}
Creates a new greenhouse record.Request body
name
string
required
Display name of the greenhouse. Maximum 100 characters.
location
string
Human-readable location (e.g. city, zone, or address).
description
string
Free-text description of the greenhouse and its purpose.
ownerId
integer
ID of the user who will own this greenhouse.
active
boolean
Whether the greenhouse is active. Defaults to true when omitted.
latitude
number
GPS latitude coordinate.
longitude
number
GPS longitude coordinate.
photoUrl
string
URL pointing to a photo of the greenhouse. Maximum 500 characters.
Response — the created greenhouse object (same shape as the list item above).
curl -X POST http://localhost:8080/api/greenhouses \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Invernadero Sur",
    "location": "Sector B",
    "description": "Pepinos y lechugas",
    "ownerId": 3,
    "latitude": 40.4100,
    "longitude": -3.7100
  }'
{
  "id": 2,
  "name": "Invernadero Sur",
  "location": "Sector B",
  "description": "Pepinos y lechugas",
  "ownerId": 3,
  "active": true,
  "latitude": 40.41,
  "longitude": -3.71,
  "photoUrl": null,
  "createdAt": "2024-03-10T09:30:00"
}
Returns a single greenhouse by its numeric ID.Path parameters
id
integer
required
The greenhouse ID.
Returns 404 Not Found when no greenhouse with that ID exists.
curl http://localhost:8080/api/greenhouses/1
{
  "id": 1,
  "name": "Invernadero Norte",
  "location": "Sector A",
  "description": "Producción de tomate cherry",
  "ownerId": 3,
  "active": true,
  "latitude": 40.4168,
  "longitude": -3.7038,
  "photoUrl": "https://example.com/photos/gh1.jpg",
  "createdAt": "2024-03-01T08:00:00"
}
Updates one or more fields of an existing greenhouse. Only the fields present in the request body are changed; omitted fields are left as-is.
Requires the X-User-Id header to match the greenhouse’s ownerId, or the X-Admin-Email header to match the configured admin email. Returns 403 otherwise.
Path parameters
id
integer
required
The greenhouse ID to update.
Request body (all fields optional)
name
string
Updated name.
location
string
Updated location string.
description
string
Updated description.
ownerId
integer
Transfer ownership to another user ID.
active
boolean
Set active status.
latitude
number
Updated GPS latitude.
longitude
number
Updated GPS longitude.
photoUrl
string
Updated photo URL.
Response — the updated greenhouse object.
curl -X PUT http://localhost:8080/api/greenhouses/1 \
  -H "Content-Type: application/json" \
  -H "X-User-Id: 3" \
  -d '{
    "description": "Tomate cherry y pimiento",
    "active": true
  }'
{
  "id": 1,
  "name": "Invernadero Norte",
  "location": "Sector A",
  "description": "Tomate cherry y pimiento",
  "ownerId": 3,
  "active": true,
  "latitude": 40.4168,
  "longitude": -3.7038,
  "photoUrl": "https://example.com/photos/gh1.jpg",
  "createdAt": "2024-03-01T08:00:00"
}
Permanently deletes a greenhouse record.
Requires the X-User-Id header to match the greenhouse’s ownerId, or the X-Admin-Email header to match the configured admin email. Returns 403 otherwise.
Path parameters
id
integer
required
The greenhouse ID to delete.
Returns 404 Not Found if the greenhouse does not exist.
curl -X DELETE http://localhost:8080/api/greenhouses/2 \
  -H "X-User-Id: 3"
{
  "deleted": true
}
Returns all users that have been assigned to the greenhouse via the user_greenhouse junction table.Path parameters
id
integer
required
The greenhouse ID.
Response
users
array
Array of user objects. Returns an empty array if no assignments exist or if the junction table is unavailable.
curl http://localhost:8080/api/greenhouses/1/users
{
  "users": [
    {
      "id": 3,
      "username": "jdoe",
      "full_name": "Jane Doe",
      "email": "jane@example.com",
      "phone": "+34 600 000 000",
      "avatar": null,
      "role": "USER",
      "active": true,
      "created_at": "2024-01-15T10:00:00"
    }
  ]
}
Assigns a user to the greenhouse. The operation is idempotent — assigning an already-assigned user has no effect.Path parameters
id
integer
required
The greenhouse ID.
Request body
userId
integer
required
ID of the user to assign to this greenhouse.
curl -X POST http://localhost:8080/api/greenhouses/1/users \
  -H "Content-Type: application/json" \
  -d '{"userId": 5}'
{
  "assigned": true
}
Removes a user’s assignment from the greenhouse.Path parameters
id
integer
required
The greenhouse ID.
userId
integer
required
The ID of the user to remove.
curl -X DELETE http://localhost:8080/api/greenhouses/1/users/5
{
  "removed": true
}

Build docs developers (and LLMs) love