new features, bookstack
This commit is contained in:
41
backend/src/controllers/bookstack.controller.ts
Normal file
41
backend/src/controllers/bookstack.controller.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Request, Response } from 'express';
|
||||
import bookstackService from '../services/bookstack.service';
|
||||
import environment from '../config/environment';
|
||||
import logger from '../utils/logger';
|
||||
|
||||
class BookStackController {
|
||||
async getRecent(_req: Request, res: Response): Promise<void> {
|
||||
if (!environment.bookstack.url) {
|
||||
res.status(200).json({ success: true, data: [], configured: false });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const pages = await bookstackService.getRecentPages();
|
||||
res.status(200).json({ success: true, data: pages, configured: true });
|
||||
} catch (error) {
|
||||
logger.error('BookStackController.getRecent error', { error });
|
||||
res.status(500).json({ success: false, message: 'BookStack konnte nicht abgefragt werden' });
|
||||
}
|
||||
}
|
||||
|
||||
async search(req: Request, res: Response): Promise<void> {
|
||||
if (!environment.bookstack.url) {
|
||||
res.status(200).json({ success: true, data: [], configured: false });
|
||||
return;
|
||||
}
|
||||
const query = req.query.query as string | undefined;
|
||||
if (!query || query.trim().length === 0) {
|
||||
res.status(400).json({ success: false, message: 'Suchbegriff fehlt' });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const results = await bookstackService.searchPages(query.trim());
|
||||
res.status(200).json({ success: true, data: results, configured: true });
|
||||
} catch (error) {
|
||||
logger.error('BookStackController.search error', { error });
|
||||
res.status(500).json({ success: false, message: 'BookStack-Suche fehlgeschlagen' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new BookStackController();
|
||||
Reference in New Issue
Block a user