Alperen Dağı Practice App Contribution Report - bounswe/bounswe2023group1 GitHub Wiki

Alperen Dağı

Important Issues and Pull Requests

Links: #186

In selecting the API that best meets the practice app's requirements while aligning with your technical capabilities and budget or usage constraints, WeatherAPI emerges as an excellent choice. WeatherAPI is a comprehensive weather data provider that offers a wide range of endpoints for accessing accurate and up-to-date weather information, forecasts, and historical weather data. By integrating WeatherAPI into our app, I provide users with valuable weather insights, enabling them to plan their activities, make informed decisions, and stay updated on weather conditions

Links: #205

I have created a WeatherService to handle weather-related operations and act as a service. Additionally, I developed a WeatherController to manage HTTP requests and serve as a controller. The WeatherData and Feedback models represent the structured data for weather information and user feedback, respectively. Lastly, the FeedbackRepository is responsible for handling the storage and retrieval of feedback data.

  • WeatherService: The WeatherService class serves as a service component in a server-side application. It encapsulates the business logic related to weather data retrieval and feedback management. It utilizes the OkHttp library to send HTTP requests and the Jackson library for JSON parsing. The WeatherService provides methods for retrieving weather data from the Open Meteo API based on latitude and longitude coordinates. It also includes functionality to save user feedback and retrieve a list of all feedback entries using a FeedbackRepository instance. By implementing the business logic in the WeatherService, it acts as an intermediary between the weather API and the rest of the application, facilitating data retrieval and feedback management.

  • WeatherController as a Controller: The WeatherController class serves as a controller component in a server-side application. It handles incoming HTTP requests related to weather data and interacts with the WeatherService to retrieve the required information. The controller is responsible for handling route mappings, request validation, and invoking appropriate methods from the WeatherService to process the requests. It communicates with the client-side application and returns the requested weather data or feedback responses.

  • WeatherData as a Model: The WeatherData class represents a model that encapsulates weather-related information, such as temperature, wind speed, and wind direction. It provides a structured representation of weather data and can be used to transport this information between different layers of the application.

  • Feedback: The Feedback class represents a model that captures user feedback regarding the weather or the application itself. It typically includes fields such as the user's name, email, feedback message, and any additional data relevant to the feedback.

  • FeedbackRepository as a Repository: The FeedbackRepository class serves as a repository component and handles data persistence for feedback entities. It interacts with the underlying database or data storage to save, retrieve, update, and delete feedback entries.

Links: #207

I write the WeatherPage.jsx and WeatherPage.css files. These functionalities are the core aspects of the WeatherPage component: etching

  • Feedbacks: The fetchFeedbacks function uses axios to send an HTTP GET request to retrieve existing feedback data from the /api/getfeedback endpoint. The fetched feedback data is stored in the feedbacks state variable.

  • Getting Latitude and Longitude: The getLatLon function sends an HTTP GET request to the /api/geocode endpoint, passing the user-entered address as a query parameter. The response contains latitude and longitude values. The latitude and longitude values are used to call the getWeatherData function.

  • Getting Weather Data: The getWeatherData function sends an HTTP GET request to the /api/weather endpoint, passing the latitude and longitude as parameters. The response contains weather data, such as temperature, wind speed, and wind direction. The weather data is stored in the respective state variables.

  • Handling Form Submissions: The handleSubmit function is triggered when the user submits the address form. It prevents the default form submission behavior, calls getLatLon to fetch weather data based on the entered address.

  • Handling Feedback Submissions: The handleFeedbackSubmit function is triggered when the user submits the feedback form. It prevents the default form submission behavior, sends a POST request to the /api/givefeedback endpoint with the feedback data (name, email, message). Upon successful submission, it clears the feedback input fields, fetches the updated feedbacks using fetchFeedbacks.

  • Toggling Feedback Visibility: The toggleFeedbacksVisibility function toggles the visibility of the feedback section by updating the showFeedbacks state variable.

Pull Request that I reviewed : #209 #167 #168 #175 #172 #185 #187 #189 #191 #195 #198 #209

In my reviews, I thoroughly read the code, carefully examining for any conflicts, typos, or changes. If I come across any issues or areas that need improvement, I request the necessary changes to address them appropriately.

Pull Request that I opened : #159 #160 #166 #188 #197 #202

Utilized Third Party URI

Weather API, https://open-meteo.com/

The Open-Meteo API is a weather data service that provides access to a wide range of meteorological information. It offers various endpoints and parameters to retrieve current weather data, forecasts, historical weather data, and other related weather information.

With the Open-Meteo API, you can retrieve data such as temperature, wind speed, humidity, precipitation, cloud cover, and more. The API supports global weather data, allowing you to retrieve weather information for locations around the world.

API Endpoints

  • @GetMapping("/weather"):
  • This annotation indicates that the method handles HTTP GET requests to the /weather endpoint. The method expects two request parameters, lat and lon, which are passed as query parameters. Inside the method, the weatherService.getWeather(lat, lon) method is called to retrieve the weather data. If the weather data is successfully obtained, it is returned as a WeatherData object in the response body with an HTTP status of 200 (OK). If there is an IOException while retrieving the weather data, an internal server error response with a status of 500 (INTERNAL_SERVER_ERROR) is returned.
  • @PostMapping("/givefeedback"):
  • This annotation indicates that the method handles HTTP POST requests to the /givefeedback endpoint. The method expects a JSON payload in the request body, which is mapped to a Feedback object. The weatherService.saveFeedback(feedback) method is called to save the feedback in the database. The method returns an HTTP response with a status of 201 (CREATED) to indicate successful feedback submission.
  • @GetMapping("/getfeedback"):
  • This annotation indicates that the method handles HTTP GET requests to the /getfeedback endpoint. The method retrieves all feedback entries from the database using the weatherService.getAllFeedbacks() method. The retrieved feedback entries are returned in the response body as a list of Feedback objects with an HTTP status of 200 (OK).

Unit Tests

  • Testing getWeather() Method:

This test validates the getWeather() method of WeatherService. A mock OkHttpClient and Response are created to simulate the HTTP request and response. The behavior of the mocks is set up using when() and thenReturn() methods from Mockito. The getWeather() method is invoked with specific latitude and longitude values. The test asserts that the returned WeatherData object is not null and has the expected temperature, wind speed, and wind direction.

  • Testing getWeather() Method Exception:

This test verifies the exception handling of the getWeather() method when an IOException occurs. The behavior of the mocks is set up to simulate an unsuccessful HTTP response. The test asserts that invoking getWeather() with specific latitude and longitude values throws an IOException.

  • Testing saveFeedback() Method:

This test verifies the saveFeedback() method of WeatherService. A Feedback object is created. The saveFeedback() method is invoked. The test verifies that the save() method of the feedbackRepository is called once with the Feedback object.

  • Testing getAllFeedbacks() Method:

This test validates the getAllFeedbacks() method of WeatherService. A mock list of Feedback objects is created and set up for the feedbackRepository. The findAll() method of the feedbackRepository is stubbed to return the mock list. The getAllFeedbacks() method is invoked. The test asserts that the returned list of Feedback objects is the same as the mock list and has the expected size.

Sample Calls

Sample Request: 1

Sample Request: 2

Sample Request: 3

Significant Work

During the development process, I undertook significant work on implementing my WeatherAPI project and conducting thorough code reviews. This involved several key activities and responsibilities.

  • WeatherAPI Implementation:

Developed the WeatherAPI, which acts as a service to retrieve weather data from various sources. Implemented functionalities to fetch current weather data, weather forecasts, and historical weather information based on specific locations. Integrated external weather data providers and leveraged their APIs to gather accurate and up-to-date weather data. Created endpoints and request/response structures to handle weather data retrieval and ensure seamless integration with client applications. Implemented error handling and robust data validation mechanisms to enhance the reliability and resilience of the WeatherAPI.

  • Code Review:

Conducted comprehensive code reviews to ensure code quality, adherence to best practices, and maintainability. Reviewed code changes made by team members, carefully examining their implementations and architectural design choices. Focused on identifying and rectifying potential issues such as bugs, performance bottlenecks, security vulnerabilities, and code smells. Provided constructive feedback and suggestions for improvements to enhance the overall codebase quality and maintainability. Collaborated closely with team members, fostering a culture of continuous improvement and knowledge sharing through code reviews.

Challenges

The most challenging aspect for me during the project was establishing the connections between the backend and the database. I encountered a fatal error when attempting to start the PostgreSQL server and connect to port 5432. As a result, I was unable to work on the project locally until our team resolved the Docker-related issues.

Additionally, I initially encountered another problem with the weather API I was using from RapidAPI. Yesterday, the API crashed on their website. I initially thought the issue might be due to something I had done. To investigate, I tried accessing the API endpoint directly from the website, but it also returned a 500 error. This led me to conclude that the issue was not related to my implementation, but rather an error on the provider's side. Consequently, I had to switch to a different weather API to continue working on the project.