forked from Amazon-Back-End-ES-03-25/lab_201
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeController.java
More file actions
40 lines (32 loc) · 1.04 KB
/
TimeController.java
File metadata and controls
40 lines (32 loc) · 1.04 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
package com.example.springdemo.controller;
import com.example.springdemo.model.TimeInfo;
import com.example.springdemo.service.TimeService;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/time")
public class TimeController {
private final TimeService timeService;
public TimeController(TimeService timeService) {
this.timeService = timeService;
}
@GetMapping
public String getCurrentTime() {
return timeService.getCurrentTime().toString();
}
@GetMapping("/date")
public String getCurrentDate() {
return timeService.getCurrentDate().toString();
}
@GetMapping("/day")
public String getCurrentDayOfWeek() {
return timeService.getCurrentDayOfWeek().toString();
}
@GetMapping("/all")
public TimeInfo getAllTimeInfo() {
return new TimeInfo(
timeService.getCurrentTime().toString(),
timeService.getCurrentDate().toString(),
timeService.getCurrentDayOfWeek().toString()
);
}
}