From 8d03c86c8f2d91994ba890c64f01d4192654d282 Mon Sep 17 00:00:00 2001 From: Piotr Dec Date: Tue, 16 Jul 2024 22:34:22 +0200 Subject: [PATCH] feat: DataProperties --- .gitignore | 3 ++ readme.md | 36 +++++++++++-------- src/main/java/eu/ztsh/lfr/Main.java | 4 +++ .../eu/ztsh/lfr/config/DataProperties.java | 8 +++++ src/main/resources/application.yaml | 2 ++ 5 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 src/main/java/eu/ztsh/lfr/config/DataProperties.java diff --git a/.gitignore b/.gitignore index a471319..f9b4200 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ target/ ### IntelliJ IDEA ### .idea/ *.iml + +# local files +data/ diff --git a/readme.md b/readme.md index 14ca349..b2c770f 100644 --- a/readme.md +++ b/readme.md @@ -1,7 +1,8 @@ # Large file reading challenge Welcome in the recruitment challenge. -Write an application that, at the endpoint specified by you, returns the yearly average temperatures for a given city in the format array of objects with the following fields: year, averageTemperature. +Write an application that, at the endpoint specified by you, returns the yearly average temperatures for a given city in +the format array of objects with the following fields: year, averageTemperature. ## Assumptions @@ -10,33 +11,40 @@ Write an application that, at the endpoint specified by you, returns the yearly - The content of the source file may change during the application's running ## Example source file -[example_file.csv](example_file.csv) +[example_file.csv](example_file.csv) ## Response ### Schema + [response_schema](schema/response.json) ### Example ```json [ - { - "year": "2021", - "averageTemperature": 12.1 - }, - { - "year": "2022", - "averageTemperature": 11.1 - }, - { - "year": "2023", - "averageTemperature": 14.1 - } + { + "year": "2021", + "averageTemperature": 12.1 + }, + { + "year": "2022", + "averageTemperature": 11.1 + }, + { + "year": "2023", + "averageTemperature": 14.1 + } ] ``` +## Configuration + +| property | description | default | +|---------------|--------------------------------|-----------------------| +| data.file-url | path to file with temperatures | data/temperatures.csv | + ## Usage Temperature statistics endpoint: `/api/temperatures/{city}` diff --git a/src/main/java/eu/ztsh/lfr/Main.java b/src/main/java/eu/ztsh/lfr/Main.java index 1f3f728..569eded 100644 --- a/src/main/java/eu/ztsh/lfr/Main.java +++ b/src/main/java/eu/ztsh/lfr/Main.java @@ -2,8 +2,12 @@ package eu.ztsh.lfr; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.properties.ConfigurationPropertiesScan; +import org.springframework.boot.context.properties.EnableConfigurationProperties; @SpringBootApplication +@EnableConfigurationProperties +@ConfigurationPropertiesScan public class Main { public static void main(String[] args) { diff --git a/src/main/java/eu/ztsh/lfr/config/DataProperties.java b/src/main/java/eu/ztsh/lfr/config/DataProperties.java new file mode 100644 index 0000000..152bc52 --- /dev/null +++ b/src/main/java/eu/ztsh/lfr/config/DataProperties.java @@ -0,0 +1,8 @@ +package eu.ztsh.lfr.config; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties("data") +public record DataProperties(String fileUrl) { + +} diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index e69de29..8008f0f 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -0,0 +1,2 @@ +data: + file-url: data/temperatures.csv