This is a weather application that retrieves weather data for cities or locations.
The project uses the following dependencies:
- Spring Boot: A framework for creating Java applications.
- Spring Web: A framework for building web applications.
- Spring Data JPA: A framework for interacting with databases using Java Persistence API (JPA).
- Jakarta Persistence: A standard for object-relational mapping (ORM) in Java.
- Spring Boot DevTools: Tools for development-time convenience.
- Jackson: A library for JSON serialization and deserialization.
- RestTemplate: A class for making HTTP requests.
Retrieves weather data for a specific city.
- URL:
/weather/{city}
- Method: GET
- Path Variable:
{city}
: The name of the city for which weather data is requested.
- Response: Returns the weather data for the specified city.
- Body Format:
{ "id": [Long], "city": [String], "main": { "temp": [Double] } }
- Body Format:
Retrieves weather data for a specific location using latitude and longitude coordinates.
- URL:
/weather
- Method: GET
- Query Parameters:
lat
: The latitude coordinate of the location.lon
: The longitude coordinate of the location.
- Response: Returns the weather data for the specified location.
- Body Format:
{ "id": [Long], "city": [String], "main": { "temp": [Double] } }
- Body Format:
The project follows the MVC (Model-View-Controller) architecture.
The WeatherData
class represents weather data.
- Fields:
id
: [Long] - The unique identifier for the weather data.city
: [String] - The name of the city.main
: [WeatherMain] - The main weather details.
- Methods: Includes constructors, getters, and setters.
The WeatherMain
class represents the main weather details.
- Fields:
temperature
: [Double] - The temperature.
- Methods: Includes constructors, getters, and setters.
The WeatherRepository
class retrieves weather data from an external API.
- Methods:
getWeatherByCity(String city)
: Retrieves weather data for a specific city.getWeatherByLocation(String lat, String lon)
: Retrieves weather data for a specific location.
The WeatherService
class handles the business logic for retrieving weather data.
- Methods:
getWeatherByCity(String city)
: Retrieves weather data for a specific city.getWeatherByLocation(String lat, String lon)
: Retrieves weather data for a specific location.
The WeatherController
class defines the REST API endpoints for retrieving weather data.
- Endpoints:
GET /weather/{city}
: Retrieves weather data by city.GET /weather
: Retrieves weather data by location.
The WeatherApplication
class is the entry point of the application.
- Method:
main()