Friendship management added

This commit is contained in:
Torsten Schulz
2024-10-27 13:14:05 +01:00
parent f74a16e58e
commit 7f8709516d
13 changed files with 406 additions and 31 deletions

View File

@@ -23,6 +23,9 @@ class SocialNetworkController {
this.updateDiaryEntry = this.updateDiaryEntry.bind(this);
this.deleteDiaryEntry = this.deleteDiaryEntry.bind(this);
this.getDiaryEntries = this.getDiaryEntries.bind(this);
this.addFriend = this.addFriend.bind(this);
this.removeFriend = this.removeFriend.bind(this);
this.acceptFriendship = this.acceptFriendship.bind(this);
}
async userSearch(req, res) {
@@ -278,7 +281,7 @@ class SocialNetworkController {
async getDiaryEntries(req, res) {
try {
const { userid: userId} = req.headers;
const { userid: userId } = req.headers;
const { page } = req.params;
const entries = await this.socialNetworkService.getDiaryEntries(userId, page);
res.status(200).json(entries);
@@ -287,6 +290,42 @@ class SocialNetworkController {
res.status(500).json({ error: error.message });
}
}
async addFriend(req, res) {
try {
const { userid: hashedUserid } = req.headers;
const { friendUserid } = req.body;
await this.socialNetworkService.addFriend(hashedUserid, friendUserid);
res.status(201).json({ message: 'added' });
} catch (error) {
console.error('Error in addFriend:', error);
res.status(500).json({ error: error.message });
}
}
async removeFriend(req, res) {
try {
const { userid: hashedUserid } = req.headers;
const { friendUserid } = req.params;
await this.socialNetworkService.removeFriend(hashedUserid, friendUserid);
res.status(200).json({ message: 'removed' });
} catch (error) {
console.error('Error in removeFriend:', error);
res.status(500).json({ error: error.message });
}
}
async acceptFriendship(req, res) {
try {
const { userid: hashedUserid } = req.headers;
const { friendUserid } = req.params;
await this.socialNetworkService.acceptFriendship(hashedUserid, friendUserid);
res.status(200).json({ message: 'accepted' });
} catch (error) {
console.error('Error in acceptFriendship:', error);
res.status(500).json({ error: error.message });
}
}
}
export default SocialNetworkController;