Code Monkey home page Code Monkey logo

weatherchallenge's Introduction

Author: Enrico Piccini

Repo: https://github.com/enricosoft/weatherchallenge


[STEP1]

Requirements:

  • An IDE like Visual Studio 2022
  • .NET 6 sdk
  • personal "WeatherApi.com" Api key

How to run the project:

  • Open "WeatherChallengeCli.sln" file using Visual Studio 2022
  • Inside "Config.json" file of the two projects, set your own "weatherapi.com" api key
  • Build the solution (it will restore NuGet packages)
  • Click on visual studio's start button

[STEP2]

  1. Api to set the weather forecast for a specific city and dates. The data are saved into Musement Db.
    The request payload and the response are in JSON format.

POST /api/v3/cities/{id}/weatherforecast

Request Payload:

{
	"forecasts": [
		{
			"date": "2022-09-17",
			"forecast": "Rainy"
		},
		{
			"date": "2022-09-18",
			"forecast": "Sunny"
		}
	]
}

Response types:

CASE SUCCESS:

{
	"success": true,
	"error_message": ""
}

CASE FAIL:

{
	"success": false,
	"error_message": "this is the description of the error"
}

Behaviour:

  • City "id" is validated
  • Validate the correct format the dates
  • Save into db the forecasts
  • If everything is ok (no exceptions), answer as Success payload, otherwise Fail payload.


  1. Api to get the weather forecast for a specific city within a range of dates.
    The request payload and the response are in JSON format.
    N.B.: the data are retrieved from Musement db, not from weatherapi.com api.

GET /api/v3/cities/{id}/weatherforecast

Request Payload:

{
	"from_date": "2022-09-17",
	"to_date": "2022-09-19"
}

Response types:

CASE SUCCESS:

{
	"success": true,
	"error_message": "",
	"data": {
		"city_id": "14",
		"city_name": "Milan",
		"forecasts": [
			{
				"date": "2022-09-17",
				"forecast": "Rainy"
			},
			{
				"date": "2022-09-18",
				"forecast": "Sunny"
			},
			{
				"date": "2022-09-19",
				"forecast": null
			}
		]
	}
}

CASE FAIL:

{
	"success": false,
	"error_message": "this is the description of the error",
	"data": null
}

Behaviour:

  • City "id" is validated
  • Validate the date range (for instance: the "to_date" must be equal or greater that "from_date", date are in valid format)
  • Query the Db to get the forecast for the specified dates.
  • If forecast for a specific date was not been saved into db, the "forecast" value will be null.
  • If everything is ok (no exceptions), answer as Success payload, otherwise Fail payload.



[OPTIONAL: docker development environment]

Requirements:

  • Docker installed on your local machine
  • Visual Studio Code

How to open and run the project in a container:

  • Open Docker app on your local machine
  • Open the project root folder using VS Code
  • At this point VS Code should open a pop-up that asks you to "Reopen in Container". Click that button and VS Code will create the dev env for you.
  • Set your own "weatherapi.com" api key in the two "Config.json" files
  • Open a terminal in VS Code and run the following commands:

    cd WeatherChallengeCli
    dotnet restore
    dotnet run

weatherchallenge's People

Contributors

enricosoft avatar epiccinionit 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.