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;