Problem statement
Connect the temperature converters to a REST API using bean selection and constructor injection.
Requirements
The GET /convert endpoint and both convert methods are already provided. Your task is to register the converters as beans and inject them into the controller.
CelsiusConverter
- Register this class as the default converter, so a TemperatureConverter injected with no qualifier selects it
- Its provided convert method returns the input unchanged, since the input is already Celsius
FahrenheitConverter
- Register this class as a converter selectable by the qualifier fahrenheit
- Its provided convert method returns celsius * 9 / 5 + 32
TemperatureController
- Inject the default converter and the fahrenheit-qualified converter through the constructor
- Once both are injected, the provided GET /convert endpoint uses the default converter for celsius (or no unit) and the fahrenheit converter for fahrenheit
Sample Requests & Responses
GET /convert?value=100&unit=fahrenheit
Response (200 OK):
{
"unit": "fahrenheit",
"value": 212.0
}
GET /convert?value=37&unit=fahrenheit
Response (200 OK):
{
"unit": "fahrenheit",
"value": 98.6
}
GET /convert?value=100
Response (200 OK):
{
"unit": "celsius",
"value": 100.0
}
GET /convert?value=25&unit=celsius
Response (200 OK):
{
"unit": "celsius",
"value": 25.0
}
GET /convert?value=100&unit=kelvin
Response (400 Bad Request):
{
"error": "Unsupported unit: kelvin"
}
