-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathTimeController.java
More file actions
46 lines (34 loc) · 1.16 KB
/
TimeController.java
File metadata and controls
46 lines (34 loc) · 1.16 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
44
45
46
package com.IronHack.Lab2.Controller;
import com.IronHack.Lab2.Service.TimeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@RestController
@RequestMapping("/time")
public class TimeController {
private final TimeService timeService;
public TimeController(final TimeService timeService) {
this.timeService = timeService;
}
@GetMapping("/time")
public String getTime() {
return "Current time :" + timeService.getCurrentTime();
}
@GetMapping("/date")
public String getDate() {
return "Current date :" + timeService.getCurrentDate();
}
@GetMapping("/day")
public String getDay() {
return "Day of the week:" + timeService.getCurrentDate();
}
@GetMapping("/all")
public Map<String, String> getAllTimeInfo() {
return Map.of(
"Time", timeService.getCurrentTime(),
"Date", timeService.getCurrentDate(),
"Day of week", timeService.getCurrentDayOfWeek()
);
}
}