Problem statement
Build a REST API for managing plant watering schedules with full CRUD backed by a database.
Requirements
PlantController
Implement the five REST endpoints. Each endpoint must be reachable at exactly the verb and path listed below.
GET /plants
- Return 200 OK with the list of all stored plants
- Return 200 OK with an empty array when the store has no plants
GET /plants/{id}
- Accept id as a path parameter
- Return 200 OK with the plant for an existing id
- Return 404 Not Found when no plant has the given id, never a 200 with an empty body. The error message is "Plant not found with id: " followed by the requested id
POST /plants
- Accept a JSON body with name and wateringIntervalDays and validate it
- If name is missing, empty, or whitespace-only, return 400 Bad Request with error message: "Name must not be blank"
- If wateringIntervalDays is missing, return 400 Bad Request with error message: "Watering interval is required"
- If wateringIntervalDays is less than 1, return 400 Bad Request with error message: "Watering interval must be at least 1"; an interval of exactly 1 is valid
- A rejected request must not add anything to the store
- On a valid body, save the plant and return 201 Created with the created plant, including its generated id
PUT /plants/{id}
- Accept id as a path parameter and a JSON body with name and wateringIntervalDays; validate the body with the same rules and error messages as POST /plants, including that an interval of exactly 1 is valid
- Apply a full update: replace both stored fields with the values from the body and return 200 OK with the updated plant
- The update modifies the existing row in place: the plant keeps its id, and the total number of stored plants stays the same
- Only the addressed plant changes; every other plant keeps its stored values
- Return 404 Not Found for an unknown id, with the same error message format as GET /plants/{id}, and change nothing
- A rejected body leaves the stored plant unchanged
DELETE /plants/{id}
- Delete the plant with the given id and return 204 No Content with an empty body
- Exactly one row is removed; the rest of the store stays intact
- After a successful delete, a GET /plants/{id} for that id returns 404 Not Found
- Return 404 Not Found for an unknown id, with the same error message format as GET /plants/{id}, and remove nothing
Sample Requests & Responses
Expand to view details on sample requests and responses.
POST /plants
Request:
{
"name": "Monstera",
"wateringIntervalDays": 7
}
Response (201 Created):
{
"id": 1,
"name": "Monstera",
"wateringIntervalDays": 7
}
GET /plants
Response (200 OK):
[
{
"id": 1,
"name": "Monstera",
"wateringIntervalDays": 7
},
{
"id": 2,
"name": "Snake Plant",
"wateringIntervalDays": 14
}
]
GET /plants/1
Response (200 OK):
{
"id": 1,
"name": "Monstera",
"wateringIntervalDays": 7
}
POST /plants
Request:
{
"name": "",
"wateringIntervalDays": 3
}
Response (400 Bad Request):
{
"error": "Name must not be blank",
"timestamp": "2026-07-30T10:15:21.218088",
"path": "/plants"
}
POST /plants
Request:
{
"name": "Basil",
"wateringIntervalDays": 0
}
Response (400 Bad Request):
{
"error": "Watering interval must be at least 1",
"timestamp": "2026-07-30T10:15:21.233656",
"path": "/plants"
}
PUT /plants/1
Request:
{
"name": "Monstera Deliciosa",
"wateringIntervalDays": 5
}
Response (200 OK):
{
"id": 1,
"name": "Monstera Deliciosa",
"wateringIntervalDays": 5
}
PUT /plants/999
Request:
{
"name": "Fern",
"wateringIntervalDays": 4
}
Response (404 Not Found):
{
"error": "Plant not found with id: 999",
"timestamp": "2026-07-30T10:15:21.287068",
"path": "/plants/999"
}
DELETE /plants/2
Response (204 No Content): empty body
GET /plants/2
Response (404 Not Found):
{
"error": "Plant not found with id: 2",
"timestamp": "2026-07-30T10:15:21.326790",
"path": "/plants/2"
}
