Erster Aufbau Forum
This commit is contained in:
64
backend/controllers/forumController.js
Normal file
64
backend/controllers/forumController.js
Normal file
@@ -0,0 +1,64 @@
|
||||
import forumService from '../services/forumService.js';
|
||||
|
||||
const forumController = {
|
||||
async createForum(req, res) {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const { name, permissions } = req.body;
|
||||
const forum = await forumService.createForum(userId, name, permissions);
|
||||
res.status(201).json(forum);
|
||||
} catch (error) {
|
||||
console.error('Error in createForum:', error);
|
||||
res.status(400).json({ error: error.message });
|
||||
}
|
||||
},
|
||||
|
||||
async deleteForum(req, res) {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const { forumId } = req.params;
|
||||
await forumService.deleteForum(userId, forumId);
|
||||
res.status(200).json({ message: 'Forum deleted successfully' });
|
||||
} catch (error) {
|
||||
console.error('Error in deleteForum:', error);
|
||||
res.status(400).json({ error: error.message });
|
||||
}
|
||||
},
|
||||
|
||||
async getAllForums(req, res) {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const forums = await forumService.getAllForums(userId);
|
||||
res.status(200).json(forums);
|
||||
} catch (error) {
|
||||
console.error('Error in getAllForums:', error);
|
||||
res.status(400).json({ error: error.message });
|
||||
}
|
||||
},
|
||||
|
||||
async getForum(req, res) {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const { forumId, page } = req.params;
|
||||
const forum = await forumService.getForum(userId, forumId, page);
|
||||
res.status(200).json(forum);
|
||||
} catch (error) {
|
||||
console.error('Error in getForum:', error);
|
||||
res.status(400).json({ error: error.message });
|
||||
}
|
||||
},
|
||||
|
||||
async createTopic(req, res) {
|
||||
try {
|
||||
const { userid: userId } = req.headers;
|
||||
const { forumId, title, content } = req.body;
|
||||
const result = await forumService.createTopic(userId, forumId, title, content);
|
||||
res.status(201).json(result);
|
||||
} catch (error) {
|
||||
console.error('Error in createTopic:', error);
|
||||
res.status(400).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default forumController;
|
||||
@@ -254,9 +254,9 @@ class SocialNetworkController {
|
||||
|
||||
async updateDiaryEntry(req, res) {
|
||||
try {
|
||||
const { diaryId } = req.params;
|
||||
const { diaryEntryId } = req.params;
|
||||
const { userId, text } = req.body;
|
||||
const updatedEntry = await this.socialNetworkService.updateDiaryEntry(diaryId, userId, text);
|
||||
const updatedEntry = await this.socialNetworkService.updateDiaryEntry(diaryEntryId, userId, text);
|
||||
res.status(200).json(updatedEntry);
|
||||
} catch (error) {
|
||||
console.error('Error in updateDiaryEntry:', error);
|
||||
@@ -266,9 +266,9 @@ class SocialNetworkController {
|
||||
|
||||
async deleteDiaryEntry(req, res) {
|
||||
try {
|
||||
const { diaryId } = req.params;
|
||||
const { entryId } = req.params;
|
||||
const { userId } = req.body;
|
||||
const result = await this.socialNetworkService.deleteDiaryEntry(diaryId, userId);
|
||||
const result = await this.socialNetworkService.deleteDiaryEntry(entryId, userId);
|
||||
res.status(200).json({ message: 'Entry deleted successfully', result });
|
||||
} catch (error) {
|
||||
console.error('Error in deleteDiaryEntry:', error);
|
||||
@@ -278,8 +278,9 @@ class SocialNetworkController {
|
||||
|
||||
async getDiaryEntries(req, res) {
|
||||
try {
|
||||
const { userId } = req.params;
|
||||
const entries = await this.socialNetworkService.getDiaryEntries(userId);
|
||||
const { userid: userId} = req.headers;
|
||||
const { page } = req.params;
|
||||
const entries = await this.socialNetworkService.getDiaryEntries(userId, page);
|
||||
res.status(200).json(entries);
|
||||
} catch (error) {
|
||||
console.error('Error in getDiaryEntries:', error);
|
||||
|
||||
Reference in New Issue
Block a user