websockets implemented

This commit is contained in:
Torsten Schulz
2024-12-04 19:08:26 +01:00
parent d46a51db38
commit 069c97fa90
64 changed files with 2488 additions and 562 deletions

View File

@@ -0,0 +1,69 @@
import friendshipService from '../services/friendshipService.js';
const friendshipController = {
async endFriendship(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { friendUserId } = req.body;
await friendshipService.endFriendship(hashedUserId, friendUserId);
res.status(200).json({ message: 'Friendship ended successfully' });
} catch (error) {
console.error('Error in endFriendship:', error);
res.status(400).json({ error: error.message });
}
},
async acceptFriendship(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { friendUserId } = req.body;
await friendshipService.acceptFriendship(hashedUserId, friendUserId);
res.status(200).json({ message: 'Friendship accepted successfully' });
} catch (error) {
console.error('Error in acceptFriendship:', error);
res.status(400).json({ error: error.message });
}
},
async rejectFriendship(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { friendUserId } = req.body;
await friendshipService.rejectFriendship(hashedUserId, friendUserId);
res.status(200).json({ message: 'Friendship rejected successfully' });
} catch (error) {
console.error('Error in rejectFriendship:', error);
res.status(400).json({ error: error.message });
}
},
async withdrawRequest(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { friendUserId } = req.body;
await friendshipService.withdrawRequest(hashedUserId, friendUserId);
res.status(200).json({ message: 'Friendship request withdrawn successfully' });
} catch (error) {
console.error('Error in withdrawRequest:', error);
res.status(400).json({ error: error.message });
}
},
async getFriendships(req, res) {
try {
const { userid: hashedUserId } = req.headers;
const { acceptedOnly } = req.query;
console.log('Friendships:', acceptedOnly);
const friendships = await friendshipService.getFriendships(hashedUserId, acceptedOnly === 'true');
res.status(200).json(friendships);
} catch (error) {
console.error('Error in getFriendships:', error);
res.status(400).json({ error: error.message });
}
},
};
export default friendshipController;