Skip to content

Commit

Permalink
The weather has been included in this push and branch
Browse files Browse the repository at this point in the history
  • Loading branch information
20041540MichaelKelly committed Mar 17, 2021
1 parent 831571d commit 3974aae
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 38 deletions.
57 changes: 25 additions & 32 deletions app/controllers/poi.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,10 @@ const POI = {
poiList: {
handler: async function (request, h) {
const pois = await Poidb.find().sort("categories").populate("person").lean();
let weather = null;
const weatherRequest = `http://api.openweathermap.org/data/2.5/weather?q=${pois.location}&appid=${apiKey}`;
try {
const response = await axios.get(weatherRequest);
if (response.status == 200) {
weather = response.data
}
} catch (error) {
console.log(error);
}

return h.view("poiList", {
title: "POI of Islands",
pois: pois,
// weather: weather
pois: pois
});
},
},
Expand Down Expand Up @@ -70,19 +60,26 @@ const POI = {
const id = request.auth.credentials.id;
const user = await User.findById(id);
console.log(id);
let weathers = null;

if (Object.keys(file).length > 0) {
await writeFile('./public/temp.img', file);
const ans = await cloudinary.uploader.upload('./public/temp.img');

const weatherRequest = `http://api.openweathermap.org/data/2.5/weather?q=${data.location}&appid=${apiKey}`;
const response = await axios.get(weatherRequest);
if (response.status == 200) {
weathers = response.data
console.log(weathers);
}
console.log(weathers);
const newPoi = new Poidb({
name: data.name,
description: data.description,
location: data.location,
imagefile: ans.secure_url,
person: user._id,
categories: data.categories,
// weather: weather.weather[0].description
weather: weathers.weather[0].description,
});
await newPoi.save();
console.log(newPoi);
Expand Down Expand Up @@ -186,7 +183,7 @@ const POI = {
});
//const noOf = no.countDocuments({firstName:"Michael"});
console.log(noOf);
console.log(noOfPoi)
console.log(noOfPoi);
return h.view("adminHome", { title: "Admin Home", userss: userss.firstName, noOf: noOf, noOfPoi: noOfPoi });
},
},
Expand Down Expand Up @@ -217,24 +214,20 @@ const POI = {
// }
}
},


handler: async function getWeather() {
let weather = {};
const response = await axios.get(weatherRequest)
if (response.status == 200) {
weather = response.data
readWeather: {
handler: async function(location) {
let weather = null;
const weatherRequest = `http://api.openweathermap.org/data/2.5/weather?q=${location}&appid=${apiKey}`;
try {
const response = await axios.get(weatherRequest);
if (response.status == 200) {
weather = response.data
}
} catch (error) {
console.log(error);
}
return weather;
}

const report = {
feelsLike : Math.round(weather.main.feels_like -273.15),
clouds : weather.weather[0].description,
windSpeed: weather.wind.speed,
windDirection: weather.wind.deg,
visibility: weather.visibility/1000,
humidity : weather.main.humidity
};
// renderWeather(report)
}
};

Expand Down
1 change: 1 addition & 0 deletions app/models/poi-db.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const poiSchema = new Schema({
location: String,
imagefile: String,
categories: String,
weather: String,
person: {
type: Schema.Types.ObjectId,
ref: 'User',
Expand Down
3 changes: 1 addition & 2 deletions app/views/adminHome.hbs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="uk-flex uk-flex-center uk-flex-middle uk-grid-small" uk-grid>
{{> title-card title="Places of Interests AdMIN Home" subTitle="Welcome to ADMIN Home"}}
{{> title-card title="Places of Interests Admin Home" subTitle="Welcome to ADMIN Home"}}
{{> admin-menu }}
</div>

Expand All @@ -11,7 +11,6 @@
<div class="uk-position-large uk-position uk-overlay uk-overlay-default">
<h1 class="uk-heading-small">Hi {{userss}}</h1>
<a href="/userList"><i class="fas fa-male fa-3x"> {{noOf}}</i></a> <a href="/poiList"><i class="fas fa-list-alt fa-3x"> {{noOfPoi}}</i></a>

</div>
</div>
</div>
4 changes: 4 additions & 0 deletions app/views/adminPoiList.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="uk-flex uk-flex-center uk-flex-middle uk-grid-small" uk-grid>
{{> title-card title="POI List og Users" subTitle="POI's List"}}
{{> admin-menu }}
</div>
2 changes: 1 addition & 1 deletion app/views/partials/admin-menu.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<a href="/adminHome" class="uk-card uk-card-small uk-card-hover uk-padding-small">
<i class="fas fa-plus-square fa-3x" style="color:rgb(153, 196, 74)" title="Admin" pos="bottom" uk-tooltip></i>
</a>
<a href="/poiList" class="uk-card uk-card-small uk-card-hover uk-padding-small">
<a href="/adminPoiList" class="uk-card uk-card-small uk-card-hover uk-padding-small">
<i class="fas fa-th-list fa-3x" style="color:rgb(63, 122, 139)" title="List of Poi" pos="bottom" uk-tooltip></i>
</a>
<a href="/userList" class="uk-card uk-card-small uk-card-hover uk-padding-small">
Expand Down
8 changes: 5 additions & 3 deletions app/views/partials/poi-list.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="uk-margin uk-width-2xlarge uk-margin-auto uk-card uk-card-default uk-card-body uk-box-shadow-large">
<div class="uk-margin uk-width-5xlarge uk-margin-auto uk-card uk-card-default uk-card-body uk-box-shadow-large">
<table class="uk-table">
<caption>
Places of Interest
Expand All @@ -17,17 +17,19 @@
<tr>
<td> {{name}} </td>
<td> {{description}} </td>
<td> {{location}} </td>
<td> {{weather}}</td>
<td> <img src="{{imagefile}}"></td>
<td> {{categories}}</td>
<td> {{person.firstName}} {{person.lastName}}</td>
<td>
<form action="/delete/{{_id}}" method="POST" >
<button class="uk-button uk-button-danger">Delete</button>
<button class="uk-button uk-button-danger"><i class="fas fa-trash-alt"></i></button>
</form>
</td>
<td>
<form action="/edit/{{_id}}" method="GET" >
<button class="uk-button uk-button-primary">Edit</button>
<button class="uk-button uk-button-primary"><i class="fas fa-edit"></i></button>
</form>
</td>
</tr>
Expand Down

0 comments on commit 3974aae

Please sign in to comment.