Refactoring the backend

This commit is contained in:
jiangrui
2025-03-10 18:33:47 +08:00
parent 755a424530
commit a78ea7e5bd
36 changed files with 974 additions and 474 deletions

View File

@@ -1,21 +1,25 @@
import { Request, Response } from "express";
import Searcher from "../services/Searcher";
import { sendSuccess, sendError } from "../utils/response";
import { injectable, inject } from "inversify";
import { TYPES } from "../core/types";
import { Searcher } from "../services/Searcher";
import { BaseController } from "./BaseController";
import { sendSuccess } from "../utils/response";
@injectable()
export class ResourceController extends BaseController {
constructor(@inject(TYPES.Searcher) private searcher: Searcher) {
super();
}
export const resourceController = {
async search(req: Request, res: Response): Promise<void> {
try {
const { keyword, channelId = "", lastMessageId = "" } = req.query; // Remove `: string` from here
const result = await Searcher.searchAll(
await this.handleRequest(req, res, async () => {
const { keyword, channelId = "", lastMessageId = "" } = req.query;
const result = await this.searcher.searchAll(
keyword as string,
channelId as string,
lastMessageId as string
);
sendSuccess(res, result);
} catch (error) {
sendError(res, {
message: (error as Error).message || "搜索资源失败",
});
}
},
};
});
}
}