Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
suyashporedi committed Feb 14, 2020
1 parent 0b6b91a commit 907cb8f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Frontend/src/core/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from "@material-ui/pickers";
import DateFnsUtils from "@date-io/date-fns";
import {sendData} from "../weather/apiWeather";
import {getSingleData} from "../weather/apiWeather"

class Home extends Component {
state = {
user: "",
Expand Down
55 changes: 27 additions & 28 deletions Frontend/src/core/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from "react";
import { isAuthenticated } from "../auth";
import Menu from "../core/Menu";
import { read } from "../user/apiUser";
import {receiveData} from "../weather/apiWeather";

class Session extends Component {
constructor() {
Expand All @@ -15,57 +16,55 @@ class Session extends Component {

componentDidMount() {
const userId = isAuthenticated().user._id;

this.init(userId);
}

init = userId => {
const token = isAuthenticated().token;
read(userId, token).then(data => {
const id = isAuthenticated().user._id;

read(userId).then(data => {
if (data.error) {
this.setState({ redirectToSignin: true });
} else {
this.setState({ user: data });
//this.loadPosts(data._id); // pass userId to loadPosts by this user
}
});

console.log(id);
receiveData(id).then(data => {
if (data.error) {
console.log(data.error);
} else {
this.setState({ session_data: data });
}
});

};


render() {
const { session_data, user } = this.state;
const items = session_data.map((item, key) =>
<ul>
<div>
<h5>Correlation id</h5> <li key={item.key}>{item.correlationId}</li>
<h5>no_of_files</h5><li key={item.key}>{item.no_of_files}</li>
</div>
<br></br>
</ul>
);

return (
<>
<div>
<Menu/>
<div className="container fluid mt-5 ml-5">
<div>
{session_data.map((i) => {
return (
<div key={i}>
<div
className="card bwm-card"
style={{ width: "23rem", marginBottom: "8px" }}
>
<div className="card-block">
<h4 class="card-title text-info">{user._id}</h4>
<br />
<br />
<h5 class="card-subtitle">
{user.name.substring(0, 100)}
</h5>
<p class="card-text">
<br />
</p>
<br />

</div>
</div>
</div>
);
})}
</div>

<div>
{items}
</div>
</div>
</div>
</>
Expand Down
11 changes: 3 additions & 8 deletions Frontend/src/weather/apiWeather.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ export const sendData = (weather,token) => {
.catch(err => console.log(err));
};

export const receiveData = (user,token) => {
console.log(user.name);
export const receiveData = user => {
console.log(user)
// Communicating with the API gateway on localhost:8080
return fetch(`${process.env.REACT_APP_API_URL}/sessionData/{user.name}`, {
return fetch(`${process.env.REACT_APP_API_URL}/sessionData/${user}`, {
method: "Get",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${token}`
},
body: JSON.stringify(user)
})
.then(response => {
return response.json();
Expand Down
2 changes: 1 addition & 1 deletion Usermanagement And API Gateway/Backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mongoose.connect(
mongoose.connection.on('error', err => {
console.log(`DB connection error: ${err.message}`)
});
receiveMsg();
// receiveMsg();
// bring in routes
const authRoutes = require('./routes/auth');
const userRoutes = require('./routes/user');
Expand Down
4 changes: 3 additions & 1 deletion Usermanagement And API Gateway/Backend/routes/apiGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const { sendMsg }=require('../controllers/queue');
});

router.get('/sessionData/:userid',function(req, res){
res.redirect(307,'http://localhost:8300/rest/db/:userid');
var userid = req.params.userid;
console.log(userid);
res.redirect(307,'http://localhost:8300/rest/db/'+userid);
});

module.exports = router;
Expand Down

0 comments on commit 907cb8f

Please sign in to comment.