-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathWeatherController.java
More file actions
43 lines (35 loc) · 1.21 KB
/
WeatherController.java
File metadata and controls
43 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.example.demo.controller;
import com.example.demo.service.WeatherService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/weather")
public class WeatherController {
private final WeatherService weatherService;
public WeatherController(WeatherService weatherService) {
this.weatherService = weatherService;
}
@GetMapping("/temperature")
public int getTemperature() {
return weatherService.getTemperature();
}
@GetMapping("/condition")
public String getCondition() {
return weatherService.getCondition();
}
@GetMapping("/wind")
public int getWindSpeed() {
return weatherService.getWindSpeed();
}
@GetMapping("/all")
public Map<String, Object> getAll() {
Map<String, Object> map = new HashMap<>();
map.put("temperature", weatherService.getTemperature());
map.put("condition", weatherService.getCondition());
map.put("windSpeed", weatherService.getWindSpeed());
return map;
}
}