- This project provides a Spring Boot API for Air Quality Management, allowing users to fetch real-time and historical air quality data based on request parameters. The API supports logging for request tracking and database integration.
-
Air Quality Management:
- Retrieve real-time air quality data based on latitude, longitude, and date.
- Retrieve historical air pollution data based on city name and date range.
- City Name is mandatory in queries, while the date range is optional. If not provided, the system defaults to the last 7 days.
- Only London, Barcelona, Ankara, Tokyo, and Mumbai are supported for historical data queries.
- The API response includes pollutant categories (CO, SO2, O3, etc.), sorted chronologically in JSON format.
- Example Request:
/api/v1/airquality/history?city=ankara&startDate=16-01-2025&endDate=17-01-2025
- Example Response:
{ "City": "Ankara", "Results": [ { "Date": "16-05-2025", "Categories": [ { "CO": "Satisfactory" }, { "SO2": "Moderate" }, { "O3": "Satisfactory" } ] }, { "Date": "17-05-2025", "Categories": [ { "CO": "Good" }, { "SO2": "Severe" }, { "O3": "Satisfactory" } ] } ] }
- Each query first checks the database. Only missing data will be fetched from the external API, and then stored in the database.
- A log entry is created indicating whether data was retrieved from the database or from the API.
-
Example Workflow:
- Query: `Paris, 05-01-2025 to 10-01-2025` → Data is not in the database, so it is fetched from the API and stored.
- Query: `Ankara, 05-01-2025 to 10-01-2025` → Data is not in the database, so it is fetched from the API and stored.
-
Query: `Paris, 01-01-2025 to 15-01-2025` →
- 01-01-2025 to 04-01-2025 → Fetched from API and stored.
- 05-01-2025 to 10-01-2025 → Fetched from the database.
- 11-01-2025 to 15-01-2025 → Fetched from API and stored.
- Custom Logging Aspect: Logs details of REST controller method calls for database Integration and exceptions.
Endpoints Summary
Method | Url | Description | Request Body | Path Variable | Response |
---|---|---|---|---|---|
POST | /api/v1/airquality | Retrieve air quality data | AirQualityRequest | None | CustomResponse<CustomAirQualityResponse> |
- Java 21
- Spring Boot 3.0
- Restful API
- Mapstruct
- Open Api (Swagger)
- Maven
- Junit5
- Mockito
- Integration Tests
- Docker
- Docker Compose
- CI/CD (Github Actions - Jenkins)
- Postman
- TestContainer
- Postgres
- Prometheus
- Grafana
- Kubernetes
- JaCoCo (Test Report)
- Sonarqube
Import postman collection under postman_collection folder
WEATHER_DB_IP=localhost
WEATHER_DB_PORT=5432
POSTGRES_USER={POSTGRES_USER}
POSTGRES_PASSWORD={POSTGRES_PASSWORD}
OPEN_WEATHER_API_KEY={OPEN_WEATHER_API_KEY}
http://localhost:1100/swagger-ui/index.html
After the command named mvn clean install
completes, the JaCoCo report will be available at:
target/site/jacoco/index.html
Navigate to the target/site/jacoco/
directory.
Open the index.html
file in your browser to view the detailed coverage report.
To build and run the application with Maven
, please follow the directions shown below;
$ cd weatherapianalyis
$ mvn clean install
$ mvn spring-boot:run
The application can be built and run by the Docker
engine. The Dockerfile
has multistage build, so you do not need to build and run separately.
Please follow directions shown below in order to build and run the application with Docker Compose file;
$ cd weatherapianalyis
$ docker-compose up -d
If you change anything in the project and run it on Docker, you can also use this command shown below
$ cd weatherapianalyis
$ docker-compose up --build
To monitor the application, you can use the following tools:
-
Prometheus:
Open in your browser at http://localhost:9090
Prometheus collects and stores application metrics. -
Grafana:
Open in your browser at http://localhost:3000
Grafana provides a dashboard for visualizing the metrics.
Default credentials:- Username:
admin
- Password:
admin
- Username:
-
Define prometheus data source url, use this link shown below
http://prometheus:9090
To build and run the application with Maven
, please follow the directions shown below;
- Start Minikube
$ minikube start
- Open Minikube Dashboard
$ minikube dashboard
- To deploy the application on Kubernetes, apply the Kubernetes configuration file underneath k8s folder
$ kubectl apply -f k8s
- To open Prometheus, click tunnel url link provided by the command shown below to reach out Prometheus
minikube service prometheus-service
- To open Grafana, click tunnel url link provided by the command shown below to reach out Prometheus
minikube service grafana-service
- Define prometheus data source url, use this link shown below
http://prometheus-service.default.svc.cluster.local:9090
- To open Sonarqube, click tunnel url link provided by the command shown below to reach out Sonarqube
minikube service sonarqube
https://hub.docker.com/repository/docker/noyandocker/jenkins-jenkins/general
https://hub.docker.com/repository/docker/noyandocker/weatherapianalysis/general
- Go to
localhost:9000
for Docker and Go there throughminikube service sonarqube
for Kubernetes - Enter username and password as
admin
- Change password
- Click
Create Local Project
- Choose the baseline for this code for the project as
Use the global setting
- Click
Locally
in Analyze Method - Define Token
- Click
Continue
- Copy
sonar.host.url
andsonar.token
(sonar.login
) in theproperties
part inpom.xml
- Run
mvn sonar:sonar
to show code analysis
- Go to
jenkins
folder - Run
docker-compose up -d
- Open Jenkins in the browser via
localhost:8080
- Go to pipeline named
weatherapianalysis
- Run Pipeline
- Show
Pipeline Step
to verify if it succeeded or failed
Click here to show the screenshots of project
Figure 1
Figure 2
Figure 3
Figure 4
Figure 5
Figure 6
Figure 7
Figure 8
Figure 9
Figure 10
Figure 11
Figure 12
Figure 13
Figure 14
Figure 15
Figure 16
Figure 17
Figure 18
Figure 19
Figure 20
Figure 21
Figure 22
Figure 23
Figure 24
Figure 25
Figure 26
Figure 27
Figure 28
Figure 29
Figure 30
Figure 31
Figure 32
Figure 33
Figure 34
Figure 35