websockets implemented
This commit is contained in:
@@ -26,12 +26,14 @@ class SocialNetworkController {
|
||||
this.addFriend = this.addFriend.bind(this);
|
||||
this.removeFriend = this.removeFriend.bind(this);
|
||||
this.acceptFriendship = this.acceptFriendship.bind(this);
|
||||
this.getLoggedInFriends = this.getLoggedInFriends.bind(this);
|
||||
}
|
||||
|
||||
async userSearch(req, res) {
|
||||
try {
|
||||
const { userid: hashedUserId } = req.headers;
|
||||
const { username, ageFrom, ageTo, genders } = req.body;
|
||||
const users = await this.socialNetworkService.searchUsers({ username, ageFrom, ageTo, genders });
|
||||
const users = await this.socialNetworkService.searchUsers({ hashedUserId, username, ageFrom, ageTo, genders });
|
||||
res.status(200).json(users);
|
||||
} catch (error) {
|
||||
console.error('Error in userSearch:', error);
|
||||
@@ -295,6 +297,7 @@ class SocialNetworkController {
|
||||
try {
|
||||
const { userid: hashedUserid } = req.headers;
|
||||
const { friendUserid } = req.body;
|
||||
console.log('--------', friendUserid, hashedUserid);
|
||||
await this.socialNetworkService.addFriend(hashedUserid, friendUserid);
|
||||
res.status(201).json({ message: 'added' });
|
||||
} catch (error) {
|
||||
@@ -326,6 +329,20 @@ class SocialNetworkController {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async getLoggedInFriends(req, res) {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
if (!userId) {
|
||||
return res.status(400).json({ error: 'Missing user ID' });
|
||||
}
|
||||
const loggedInFriends = await this.socialNetworkService.getLoggedInFriends(userId);
|
||||
res.status(200).json(loggedInFriends);
|
||||
} catch (error) {
|
||||
console.error('Error in getLoggedInFriends:', error);
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default SocialNetworkController;
|
||||
|
||||
Reference in New Issue
Block a user