Problem statement
Add an optional species filter to the endpoint that lists bird sightings.
Requirements
The Sighting entity, the SightingService and the POST /sightings endpoint are already provided. Your task is to write the GET /sightings endpoint in SightingController.
SightingService
- findAll() returns every sighting
- findBySpecies(species) returns the sightings whose species equals the given name exactly
SightingController
GET /sightings
- Read an optional species query parameter
- When species is not sent, return 200 OK with every sighting
- When species is sent, return 200 OK with only the sightings of that species
- When no sighting has that species, return 200 OK with an empty array, not an error
Sample Requests & Responses
POST /sightings
Request:
{
"species": "Robin",
"location": "Willow Creek"
}
Response (201 Created):
{
"species": "Robin",
"location": "Willow Creek",
"id": 1
}
GET /sightings
Response (200 OK):
[
{
"species": "Robin",
"location": "Willow Creek",
"id": 1
},
{
"species": "Barn Owl",
"location": "Old Mill",
"id": 2
},
{
"species": "Robin",
"location": "Cedar Park",
"id": 3
}
]
GET /sightings?species=Robin
Response (200 OK):
[
{
"species": "Robin",
"location": "Willow Creek",
"id": 1
},
{
"species": "Robin",
"location": "Cedar Park",
"id": 3
}
]
GET /sightings?species=Heron
Response (200 OK):
[]
