Harun Reşid Ergen Practice App Contribution Report - bounswe/bounswe2023group1 GitHub Wiki

Harun Reşid Ergen

Important Issues and Pull Requests

  • Research an API for the Practice App.
    Issue #154

  • Integrate API with Spring Boot.
    Issue #155 Pull Requests #165, #167, #168

  • Develop Frontend for Google Geocoding API Page.
    Issue #156 Pull Requests #165, #167

  • Add Practice Application Deliverables to Wiki.
    Issue #216

  • Write a POST method for Geocoding API.
    Issue #222 Pull Requests #223

  • Write Unit Tests for GeocodeController
    Issue #231 Pull Requests #228

Utilized Third Party URI

Google Geocoding API, https://developers.google.com/maps/documentation/geocoding/overview

The Geocoding API is a powerful service that allows you to convert addresses into geographic coordinates (latitude and longitude) and vice versa. It enables you to retrieve precise location data, such as the street address, city, state, country, postal code, and more.

With the Geocoding API, you can send an HTTP request and receive the geolocation information in either JSON or XML format. This API provides flexible geocoding capabilities, allowing you to perform various tasks, including geocoding addresses, reverse geocoding (converting coordinates into an address), and batch geocoding for processing multiple addresses simultaneously.

API Endpoints

  • GET /geocode: This endpoint accepts a "address" parameter in the request and returns the geolocation data (latitude, longitude, and address) for the provided address. If successful, the API responds with a JSON object containing the geolocation information. In case of any errors, appropriate error messages are returned.

  • GET /reverse_geocode: This endpoint takes "latitude" and "longitude" parameters in the request and performs reverse geocoding to obtain the corresponding address for the given coordinates. Similar to the /geocode endpoint, it returns a JSON object with the address details if the reverse geocoding is successful. Otherwise, it provides error messages indicating the failure.

  • POST /geocode: This endpoint allows users to save geocode data by sending a POST request with a JSON payload containing the geocode data. The geocode data is then processed and saved by the GeocodeService. Upon successful saving, the API responds with a success message. If there are any errors during the saving process, appropriate error messages are returned.

Unit Tests

GET request to the /geocode endpoint with the address parameter set to "New York", and verifies that the response contains the expected latitude, longitude, and address values.

@Test
    public void testGeocode() throws Exception {
        when(geocodeService.geocodeAddress("New York")).thenReturn(geocodeData);

        mockMvc.perform(get("/geocode")
                .param("address", "New York"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("latitude").value(40.7128))
                .andExpect(jsonPath("longitude").value(-74.0060))
                .andExpect(jsonPath("address").value("New York"));
    }

GET request to the /reverse_geocode endpoint with the latitude and longitude parameters set to 40.7128 and -74.0060 respectively, and verifies that the response contains the expected latitude, longitude, and address values.

@Test
    public void testReverseGeocode() throws Exception {
        when(geocodeService.reverseGeocodeCoordinates(40.7128, -74.0060)).thenReturn(geocodeData);

        mockMvc.perform(get("/reverse_geocode")
                .param("latitude", "40.7128")
                .param("longitude", "-74.0060"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("latitude").value(40.7128))
                .andExpect(jsonPath("longitude").value(-74.0060))
                .andExpect(jsonPath("address").value("New York"));
    }

POST request to the /geocode endpoint with a JSON payload representing geocode data, and verifies that the response contains the expected success message. It helps ensure that the saving functionality of the GeocodeController is working correctly.

@Test
    public void testSaveGeocodeData() throws Exception {
        when(geocodeService.saveGeocodeData(any(GeocodeData.class))).thenReturn(geocodeData);

        mockMvc.perform(post("/geocode")
                .contentType(MediaType.APPLICATION_JSON)
                .content("{\"latitude\":40.7128,\"longitude\":-74.0060,\"address\":\"New York\"}"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("message").value("Geocode data saved successfully"));
    }

Sample Calls

Sample Request: 1

Request: GET http://localhost:4000/geocode?address="1600%20Amphitheatre%20Parkway,%20Mountain%20View,%20CA"

JSON:
json1

Header:
header1

Sample Request: 2

Request: GET http://localhost:4000/reverse_geocode?latitude=40.23&longitude=37.25

JSON:
json2

Header:
header2

Challenges

During the implementation, I faced several challenges. Since I was new to frameworks like Spring Boot and version control systems like Git, there was a learning curve involved. Understanding the framework's architecture and conventions took some time. Collaborating with my team members on the codebase sometimes led to merge conflicts, which required careful resolution. Debugging and troubleshooting issues also required my attention to detail. Balancing the learning process with project deadlines was a challenge, but I remained determined and committed to learning. Despite these challenges, I was able to overcome them and make significant contributions to the project.