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;
|
||||
Reference in New Issue
Block a user