Skip to content
Snippets Groups Projects
Commit 67be97a8 authored by Tamim Almahdi's avatar Tamim Almahdi
Browse files

Add song call to get song info

parent 104954a8
No related branches found
No related tags found
2 merge requests!23Merging current work on feedMicroservice,!22feedMicroservice now producing list of ratings
...@@ -21,17 +21,34 @@ def getFeed(): ...@@ -21,17 +21,34 @@ def getFeed():
data = { data = {
"userID": userID, "userID": userID,
} }
followers = requests.post('http://localhost:3002/followings/getFollowings', followers = (requests.post('http://localhost:3002/followings/getFollowings',
json=data, json=data,
headers=headers) headers=headers)).json()
followers = followers.json()
print(followers) print(followers)
followersID = [] followersID = []
for i in range (len(followers)): for i in range (len(followers)):
followersID.append(followers[i]['followerID']) followersID.append(followers[i]['userID'])
print(followersID) print(followersID)
ratingsFeed = []
for i in range (len(followersID)):
id = int(followersID[i])
followerRatings = (requests.get(f'http://localhost:5050/all_ratings?userID={id}')).json()
print(followerRatings)
feedInfo = []
for i in range (len(followerRatings)):
song = (requests.get(f'http://localhost:5050/search_id/{followerRatings[i][0]}')).json()
feedInfo.append(song) #song, rating, user infos
print(feedInfo)
ratingsFeed.append(followerRatings)
# for i in range (len(ratingsFeed)):
print(ratingsFeed)
# userID # userID
# get users' followings' ratings # get users' followings' ratings
......
...@@ -52,7 +52,7 @@ router.post("/unfollow", validateToken, async (req, res) => { ...@@ -52,7 +52,7 @@ router.post("/unfollow", validateToken, async (req, res) => {
} }
}); });
router.post("/getFollowings", validateToken, async (req, res) => { router.post("/getFollowers", validateToken, async (req, res) => {
const { userID } = req.body; const { userID } = req.body;
const user = await Users.findOne({ where: { id: userID } }); const user = await Users.findOne({ where: { id: userID } });
if (user != null) { if (user != null) {
...@@ -65,4 +65,17 @@ router.post("/getFollowings", validateToken, async (req, res) => { ...@@ -65,4 +65,17 @@ router.post("/getFollowings", validateToken, async (req, res) => {
} }
}); });
router.post("/getFollowings", validateToken, async (req, res) => {
const { userID } = req.body;
const user = await Users.findOne({ where: { id: userID } });
if (user != null) {
const followers = await Followers.findAll({
where: { followerID: `${user.id}` },
});
res.json(followers);
} else {
res.json({ error: "User or users does not exist" });
}
});
module.exports = router; module.exports = router;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment