-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStatisticsController.java
More file actions
59 lines (51 loc) · 2.38 KB
/
StatisticsController.java
File metadata and controls
59 lines (51 loc) · 2.38 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
47
48
49
50
51
52
53
54
55
56
57
58
59
package lv.ctco.springboottemplate.features.statistics;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.time.LocalDate;
@RestController
@RequestMapping("/api/statistics")
@Tag(name = "Statistics Controller", description = "Statistics endpoints")
public class StatisticsController {
private final StatisticsService statisticsService;
public StatisticsController(StatisticsService statisticsService) {
this.statisticsService = statisticsService;
}
@GetMapping
@Operation(summary = "Get Insights About Todo Items")
public Boolean getInsightsAboutTodoItems(
@RequestParam() @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @io.swagger.v3.oas.annotations.Parameter(
description = "2025-01-01",
schema = @io.swagger.v3.oas.annotations.media.Schema(type = "string", pattern = "\\d{4}-\\d{2}-\\d{2}", example = "2025-01-01")
) LocalDate from,
@RequestParam() @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) @io.swagger.v3.oas.annotations.Parameter(
description = "2025-01-31",
schema = @io.swagger.v3.oas.annotations.media.Schema(type = "string", pattern = "\\d{4}-\\d{2}-\\d{2}", example = "2025-01-31")
) LocalDate to,
@RequestParam(required = true) StatisticsFormat format
) {
if (from == null || to == null) {
throw new org.springframework.web.server.ResponseStatusException(
org.springframework.http.HttpStatus.BAD_REQUEST,
"At least one of the required parameters 'from' or 'to' is missing"
);
}
if (from.isAfter(to)) {
throw new org.springframework.web.server.ResponseStatusException(
org.springframework.http.HttpStatus.BAD_REQUEST,
"Parameter 'from' must be before or equal to 'to'"
);
}
if (!java.util.EnumSet.allOf(StatisticsFormat.class).contains(format)) {
throw new org.springframework.web.server.ResponseStatusException(
org.springframework.http.HttpStatus.BAD_REQUEST,
"Parameter 'format' must be one of " + java.util.Arrays.toString(StatisticsFormat.values())
);
}
return true;
}
}