From cf5cf09736df9b1f39b6f5de5e5f444fdd93086f Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 12:11:06 +0200 Subject: [PATCH 01/21] docs:init readme --- Readme.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Readme.md diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..5c62d81 --- /dev/null +++ b/Readme.md @@ -0,0 +1 @@ +# Weather app Back-end \ No newline at end of file From 21492b426a0aee11c9823dcd429a5c474c10805b Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 12:14:23 +0200 Subject: [PATCH 02/21] docs: update readme --- Readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 5c62d81..21a2f7c 100644 --- a/Readme.md +++ b/Readme.md @@ -1 +1,3 @@ -# Weather app Back-end \ No newline at end of file +# Weather app Back-end + +## Run with docker From f37a7853b6efc0e07466eb6e763b66a8ec35dcd2 Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 12:29:01 +0200 Subject: [PATCH 03/21] docs: update README --- Readme.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Readme.md b/Readme.md index 21a2f7c..47ecf4f 100644 --- a/Readme.md +++ b/Readme.md @@ -1,3 +1,14 @@ # Weather app Back-end +## How works? +
+DB functions +```javascript +async function findUser(email) +``` +
+ ## Run with docker +```bash +docker build -t backEnd . +``` From c512aafb611a616fcd549158ad2e1657eaf399d1 Mon Sep 17 00:00:00 2001 From: Federico Balducci <114460826+Ott8v@users.noreply.github.com> Date: Wed, 8 May 2024 12:29:49 +0200 Subject: [PATCH 04/21] docs:Update Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 47ecf4f..572687e 100644 --- a/Readme.md +++ b/Readme.md @@ -3,7 +3,7 @@ ## How works?
DB functions -```javascript +```js async function findUser(email) ```
From 700793a1cfefcae5783b6502a07fa0acea04e72c Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 12:30:24 +0200 Subject: [PATCH 05/21] docs: update README --- Readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Readme.md b/Readme.md index 47ecf4f..59838c8 100644 --- a/Readme.md +++ b/Readme.md @@ -3,6 +3,7 @@ ## How works?
DB functions + ```javascript async function findUser(email) ``` From 73b3417dd24e781a0a1c8a02f72b8bdfe6b8f34b Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 14:33:12 +0200 Subject: [PATCH 06/21] docs: update README --- Readme.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Readme.md b/Readme.md index 0e7c917..d48e1ff 100644 --- a/Readme.md +++ b/Readme.md @@ -4,6 +4,9 @@
DB functions +
+User + ### Register user ```javascript async function registerUser(object) @@ -23,6 +26,22 @@ async function findUser(email) ```javascript async function updateUser(update, email) ``` +
+ +
+Weather + +### Add previnsions +```javascript +async function addPrevisions(cityName, countryCode, stateCode, object) +``` + +### Find weather +```javascript +async function findWeather(cityName, countryCode, stateCode, endD = undefined, startD = undefined) +``` + +
From 302bc2f6a3f925ea262374daa4bc84007651309b Mon Sep 17 00:00:00 2001 From: Antonio Moscato Date: Wed, 8 May 2024 16:00:08 +0200 Subject: [PATCH 07/21] feat: remove comment --- API/weather.js | 95 -------------------------------------------------- 1 file changed, 95 deletions(-) diff --git a/API/weather.js b/API/weather.js index c1f4d35..ec2fcd1 100644 --- a/API/weather.js +++ b/API/weather.js @@ -58,101 +58,6 @@ rWeather.get("/:location/:contryCode/:stateCode", async (req, res) => { res.status(200).send(result) }) -//send range date weather -// rWeather.get("/:location/:countryCode/:stateCode/:dateStart/:dateEnd", async (req, res) => { -// //recupero tutti i campi inviati -// let dateS = req.params.dateStart -// let dateE = req.params.dateEnd -// let location = req.params.location.toLocaleLowerCase() -// let countryCode = req.params.countryCode.toUpperCase() -// let stateCode = req.params.stateCode.toUpperCase() - -// console.log(dateS, dateE, location, countryCode, stateCode) - -// //controllo che i campi non siano undefined -// if (dateS == undefined || dateE == undefined || location == undefined) { -// res.status(500).send("i campi inviati non sono validi") -// return -// } - -// let result = undefined - -// await db.connect() - -// //recupero i dati dal db -// result = await db.findWeather(location, countryCode, stateCode, dateE, dateS) -// console.log("Result db length: " + result.length) - -// let tsDifference = (new Date(dateE)).getTime() - (new Date(dateS)).getTime() -// tsDifference = Math.floor(tsDifference / (1000 * 60 * 60 * 24)) - -// //controllo se ho ricevuto qualcosa -// if (result && controlResult(result, [dateS, dateE, tsDifference])) { -// console.log("Invio risultati db") -// res.status(200).send(result) -// return true -// } - -// let allD = [] -// if (result && !controlResult(result, [dateS, dateE, tsDifference])) { -// for (let i = 0; i <= 7; i++) { -// const SDate = new Date(dateS) -// allD.push((new Date(dateS)).getDate() + i) -// } -// result.forEach(element => { -// let number = parseInt(element["date"].substring(3, 5)) - -// if (allD.includes(number)) { - -// const index = allD.indexOf(number); -// if (index > -1) { // only splice array when item is found -// allD.splice(index, 1); // 2nd parameter means remove one item only -// } - -// } -// }) -// console.log(allD) - -// allD.forEach(async element => { -// let newDate = (dateE.substring(0, 7) + "-" + (element.toString().length == 2 ? element : "0" + element)) -// console.log(newDate) -// if (Date.now() > new Date(newDate)) { -// result = await getWeather(location, countryCode, stateCode, newDate) -// } else { -// result = await getWeather(location, countryCode, stateCode, undefined, newDate) -// } -// await db.addPrevisions(location, countryCode, stateCode, result) -// }) -// } - -// if (result && controlResult(result, [dateS, dateE, tsDifference])) { -// console.log("Invio risultati db") -// res.status(200).send(result) -// return true -// } - -// //se non ho ricevuto niente mando la richiesta all API -// result = await getWeather(location, countryCode, stateCode, dateS, dateE) - -// console.log("result API: " + typeof result) - - -// if (!result) { -// res.status(500).send("Location not found") -// return -// } - -// await db.addPrevisions(location, countryCode, stateCode, result) - -// try { -// result = await db.findWeather(location, countryCode, stateCode, dateE, dateS) -// } catch (error) { -// console.log(error) -// } - -// res.status(200).send(result) -// }) - rWeather.get("/:location/:countryCode/:stateCode/:dateStart/:dateEnd", async (req, res) => { let location = req.params.location.toLowerCase() let countryCode = req.params.countryCode.toUpperCase() From 34d875bfef13690da5424244c3bb38b1f3fc7f43 Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 16:17:04 +0200 Subject: [PATCH 08/21] comment --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index faa009b..076a49d 100644 --- a/index.js +++ b/index.js @@ -4,7 +4,7 @@ const express = require('express') const cors = require('cors'); -//definisco la porta per l'API +//definisco la Porta per l'API const port = 3000 //definisco le variabili per express From dab1f22057544dbb8d2ec9be6e0a1ccebe0753a5 Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 17:25:29 +0200 Subject: [PATCH 09/21] fix(WeatherApi/position) --- WeatherApi/position.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WeatherApi/position.js b/WeatherApi/position.js index 44d7579..f328f86 100644 --- a/WeatherApi/position.js +++ b/WeatherApi/position.js @@ -28,7 +28,7 @@ async function getPosition(location, contryCode = undefined, stateCode = undefin let filtered = { "results": [] } - result["results"].forEach(element => { + result["results"]?.forEach(element => { if (element["name"] == location && element["country_code"] == contryCode && element["admin1"]?.toUpperCase() == stateCode) { filtered["results"].push(element) } From 20690c2a6cfe24dec2b105f179bab5b5c4644461 Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 21:42:51 +0200 Subject: [PATCH 10/21] docs: Update README --- Readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Readme.md b/Readme.md index d48e1ff..b6215ed 100644 --- a/Readme.md +++ b/Readme.md @@ -1,4 +1,6 @@ # Weather app Back-end +*** +Back-end of [Weather app Front-end](https://github.com/Web-Rats/FrontEnd) ## How it works?
From 720c57b0ef4701d78287ca77524ca57f30a1a381 Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 22:13:09 +0200 Subject: [PATCH 11/21] docs: update README --- Readme.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index b6215ed..5fac3f7 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,6 @@ # Weather app Back-end *** -Back-end of [Weather app Front-end](https://github.com/Web-Rats/FrontEnd) +Back-end of [Weather app Front-end](https://github.com/Web-Rats/FrontEnd). Contains method for database(mongo) operations, validation of user and weather operations. ## How it works?
@@ -13,23 +13,29 @@ Back-end of [Weather app Front-end](https://github.com/Web-Rats/FrontEnd) ```javascript async function registerUser(object) ``` +Take as parameter the object user and save it in database. ### Delete user ```javascript async function deleteUser(email) ``` +Take as parameter the email of the user for deleting user from database. ### Find User ```javascript async function findUser(email) ``` +Take as parameter the email of the user for finding it in the database. +When it finds the user it will return the object 'user'. ### Update user ```javascript async function updateUser(update, email) ``` -
+Take as parameters an object 'update', that contains the key to update, and the email for finding the user. +When the update is succeful it returns the update object 'user'. +
Weather From fcf58c06fef4797282009ac52278ec51715ffc9f Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 22:30:35 +0200 Subject: [PATCH 12/21] docs: add structure for db functions User and Previsions --- Readme.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Readme.md b/Readme.md index 5fac3f7..a57d72c 100644 --- a/Readme.md +++ b/Readme.md @@ -8,6 +8,17 @@ Back-end of [Weather app Front-end](https://github.com/Web-Rats/FrontEnd). Conta
User +``` +├───dbApi + │ + └───Methods + │ + └───User + ├─delete.js + ├─find.js + ├─register.js + └─update.js +``` ### Register user ```javascript @@ -38,6 +49,17 @@ When the update is succeful it returns the update object 'user'.
Weather +``` +├───dbApi + │ + └───Methods + │ + └───Prevision + ├───addDaily.js + ├───addHourly.js + ├───addPrevisions.js + └───findWeather.js +``` ### Add previnsions ```javascript From 61aaf85b635f9758ce62f041c8f4f361695b07d9 Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 22:31:26 +0200 Subject: [PATCH 13/21] docs: update Readme --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index a57d72c..3a648ef 100644 --- a/Readme.md +++ b/Readme.md @@ -8,7 +8,7 @@ Back-end of [Weather app Front-end](https://github.com/Web-Rats/FrontEnd). Conta
User -``` +```bash ├───dbApi │ └───Methods @@ -49,7 +49,7 @@ When the update is succeful it returns the update object 'user'.
Weather -``` +```bash ├───dbApi │ └───Methods From f103af14ee98fbdc1aadf059eebfc449d0f1bd3a Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 22:32:20 +0200 Subject: [PATCH 14/21] docs: fix structure folder in Readme --- Readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Readme.md b/Readme.md index 3a648ef..077fb4e 100644 --- a/Readme.md +++ b/Readme.md @@ -8,6 +8,7 @@ Back-end of [Weather app Front-end](https://github.com/Web-Rats/FrontEnd). Conta
User + ```bash ├───dbApi │ @@ -49,6 +50,7 @@ When the update is succeful it returns the update object 'user'.
Weather + ```bash ├───dbApi │ From fefeb93da3a64e22901feee3ec4bca2c63cb41db Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 23:01:02 +0200 Subject: [PATCH 15/21] docs: add docker instruction readme --- Readme.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 077fb4e..604cf87 100644 --- a/Readme.md +++ b/Readme.md @@ -79,6 +79,23 @@ async function findWeather(cityName, countryCode, stateCode, endD = undefined, s
## Run with docker +Remove in the >Dockerfile the '#' before ENV, then insert your creditial for the database connection: +```text +#remove '#' +ENV USER yourUser +ENV PSWD yourPassword +``` + +After that, in the root directory, create the image with the following command: +```bash +docker build -t nameYouWant:latest . +``` + +In the end run the image with the following command: +```bash +docker run nameYouWant:latest . +``` +If you want to run in detatch: ```bash -docker build -t backEnd . +docker run -d nameYouWant:latest . ``` From 9c2abfe0d69e5ddd2c8ccb4abc2e94c76b2d737b Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 23:02:12 +0200 Subject: [PATCH 16/21] docs: update Readme --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 604cf87..fc0c12d 100644 --- a/Readme.md +++ b/Readme.md @@ -95,7 +95,7 @@ In the end run the image with the following command: ```bash docker run nameYouWant:latest . ``` -If you want to run in detatch: +If you want to run it detatch: ```bash docker run -d nameYouWant:latest . ``` From c825a49213eaab708e3bfb93041d33addd4950c4 Mon Sep 17 00:00:00 2001 From: Federico Balducci <114460826+Ott8v@users.noreply.github.com> Date: Wed, 8 May 2024 23:03:16 +0200 Subject: [PATCH 17/21] Update Readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index fc0c12d..6873365 100644 --- a/Readme.md +++ b/Readme.md @@ -79,7 +79,7 @@ async function findWeather(cityName, countryCode, stateCode, endD = undefined, s
## Run with docker -Remove in the >Dockerfile the '#' before ENV, then insert your creditial for the database connection: +Remove in the Dockerfile the '#' before ENV, then insert your creditial for the database connection: ```text #remove '#' ENV USER yourUser From 03664fe95856217164508943ae6fc7bd1d1dd4de Mon Sep 17 00:00:00 2001 From: Federico Balducci <114460826+Ott8v@users.noreply.github.com> Date: Wed, 8 May 2024 23:14:32 +0200 Subject: [PATCH 18/21] Update Readme.md --- Readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index 6873365..d7d0ff2 100644 --- a/Readme.md +++ b/Readme.md @@ -86,16 +86,16 @@ ENV USER yourUser ENV PSWD yourPassword ``` -After that, in the root directory, create the image with the following command: +After that, in the root directory, create the image with the command: ```bash -docker build -t nameYouWant:latest . +docker build -t nameImage:latest ``` -In the end run the image with the following command: +In the end run the image with the command: ```bash -docker run nameYouWant:latest . +docker run --name containerName nameImage:latest ``` If you want to run it detatch: ```bash -docker run -d nameYouWant:latest . +docker run -d --name containerName nameImage:latest ``` From bc56a88615bdfcf2e03f2054f33a276ffae5207c Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 23:31:48 +0200 Subject: [PATCH 19/21] docs: update readme --- Readme.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Readme.md b/Readme.md index d7d0ff2..ae8db62 100644 --- a/Readme.md +++ b/Readme.md @@ -2,6 +2,11 @@ *** Back-end of [Weather app Front-end](https://github.com/Web-Rats/FrontEnd). Contains method for database(mongo) operations, validation of user and weather operations. +## Install and run localy +1. Clone **https://github.com/Web-Rats/BackEnd.git** +2. Install dependencies using **npm install**. +3. Start with **node index.js** or for develop mode **npm run api**. + ## How it works?
DB functions From 42b22b864cc3b19e62fdbe05fc4530a1976c4e6f Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 23:36:15 +0200 Subject: [PATCH 20/21] docs: update readme --- Readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index ae8db62..30a164d 100644 --- a/Readme.md +++ b/Readme.md @@ -3,9 +3,9 @@ Back-end of [Weather app Front-end](https://github.com/Web-Rats/FrontEnd). Contains method for database(mongo) operations, validation of user and weather operations. ## Install and run localy -1. Clone **https://github.com/Web-Rats/BackEnd.git** -2. Install dependencies using **npm install**. -3. Start with **node index.js** or for develop mode **npm run api**. +1. Clone ``https://github.com/Web-Rats/BackEnd.git``. +2. Install dependencies using ``npm install``. +3. Start with ``node index.js`` or for develop mode ``npm run api``. ## How it works?
From 244f39362e5e344ea3db14f2426ee0c1f72c129e Mon Sep 17 00:00:00 2001 From: Federico Balducci Date: Wed, 8 May 2024 23:40:11 +0200 Subject: [PATCH 21/21] docs: update readme --- Readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 30a164d..206fe1a 100644 --- a/Readme.md +++ b/Readme.md @@ -5,7 +5,8 @@ Back-end of [Weather app Front-end](https://github.com/Web-Rats/FrontEnd). Conta ## Install and run localy 1. Clone ``https://github.com/Web-Rats/BackEnd.git``. 2. Install dependencies using ``npm install``. -3. Start with ``node index.js`` or for develop mode ``npm run api``. +3. Create an ``.env`` file in root directoty (insert your credential for accessing database), with ``USER="yourUser"`` and ``PSWD="yourPassword"`` +4. Start with ``node index.js`` or for develop mode ``npm run api``. ## How it works?