Giter Club home page Giter Club logo

weather-mng's Introduction

This project uses the www.visualcrossing.com website to fetch data about weather. I used spring boot 2.7, docker-compose, Ehcache for in-memory caching, and Prometheus for metrics. Because you mentioned that the ecosystem could be microservice, I created a modular spring boot application containing weather-mng and weather-mng-spec modules. The spec module is a lightweight module that contains everything that someday we may want to share between microservices as a dependency, so when we want to call this servvice, we can use a contract, and we don't have to import the whole project. I created some simple metrics about how our customers call our APIs and how they usually want to interact with this API by city or coordinates. Also, my resources have time metrics. Also, I implemented in-memory caching using the EhCache library in order to reduce response time and not call API every time for duplicate requests. Each request cache for 5 minutes. In order to have Prometheus and MongoDB up and running, I created a docker-compose so the new developer only needs to have docker and run docker-compose up -d so we don't have to install database or dependencies. You can run the project using cd weather-mng & mvn spring-boot:run; it uses an 8080 port. Swagger is also available at http://localhost:8080/api/swagger-ui/index.html. In my implementation, I used a combination of strategy patterns and factory patterns with the use of spring IoC containers. you see the WeatherSearchFactory class that is responsible for choosing implementation based on the users' input. This class returns an implementation that implements WeatherSearchStrategy with two methods. One is the search method, and the other one returns searchType, which is an enum with two values, coordinate and city. This implementation uses best practices and does not violate the SOLID pattern. New implementations can implement the WeatherSearchStrategy interface and let spring container does the magic. In order to fetch data, I have only 1 API, search. this API is an abstract API that accepts client input and returns data as they want exclusively. Using the below curl, you can send requests and test applications.

curl --request POST \
  --url http://localhost:8080/api/weather/search \
  --header 'Content-Type: application/json' \
  --cookie JSESSIONID=F0C312A1576DD6051945826C0C441640 \
  --data '{
    "searchType": "CITY", // required
    "timeCriteria": {
       "from": 1684609893000, // required
       "to": 1685126036000 // required
    },
    "cityName": "Los Angeles,"// required when you want to search by cityName
    "coordinate": { // required when you want to search by coordinates
       "latitude": 51,
       "longitude": 35
    }
}

I wrote 4 unit tests for application that tested critical functionalities.

weather-mng's People

Contributors

mahbodsn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.