diff --git a/src/main/java/lv/ctco/springboottemplate/features/statistics/StatisticsController.java b/src/main/java/lv/ctco/springboottemplate/features/statistics/StatisticsController.java new file mode 100644 index 0000000..88ab111 --- /dev/null +++ b/src/main/java/lv/ctco/springboottemplate/features/statistics/StatisticsController.java @@ -0,0 +1,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; + } +} diff --git a/src/main/java/lv/ctco/springboottemplate/features/statistics/StatisticsFormat.java b/src/main/java/lv/ctco/springboottemplate/features/statistics/StatisticsFormat.java new file mode 100644 index 0000000..f7e45b0 --- /dev/null +++ b/src/main/java/lv/ctco/springboottemplate/features/statistics/StatisticsFormat.java @@ -0,0 +1,6 @@ +package lv.ctco.springboottemplate.features.statistics; + +public enum StatisticsFormat { + SUMMARY, + DETAILED +} diff --git a/src/main/java/lv/ctco/springboottemplate/features/statistics/StatisticsService.java b/src/main/java/lv/ctco/springboottemplate/features/statistics/StatisticsService.java new file mode 100644 index 0000000..02bf17b --- /dev/null +++ b/src/main/java/lv/ctco/springboottemplate/features/statistics/StatisticsService.java @@ -0,0 +1,6 @@ +package lv.ctco.springboottemplate.features.statistics; + +import org.springframework.stereotype.Service; + +@Service +public class StatisticsService {}