From 47587812b809fee2a95c76266d9d0e42fc4ac1ca Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 15 Jun 2021 14:14:28 +0800 Subject: ... --- FrontEnd/src/http/search.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 FrontEnd/src/http/search.ts (limited to 'FrontEnd/src/http/search.ts') diff --git a/FrontEnd/src/http/search.ts b/FrontEnd/src/http/search.ts new file mode 100644 index 00000000..8ca48fe9 --- /dev/null +++ b/FrontEnd/src/http/search.ts @@ -0,0 +1,36 @@ +import { apiBaseUrl, axios, extractResponseData } from "./common"; +import { HttpTimelineInfo } from "./timeline"; +import { HttpUser } from "./user"; + +export interface IHttpSearchClient { + searchTimelines(query: string): Promise; + searchUsers(query: string): Promise; +} + +export class HttpSearchClient implements IHttpSearchClient { + searchTimelines(query: string): Promise { + return axios + .get(`${apiBaseUrl}/search/timelines?q=${query}`) + .then(extractResponseData); + } + + searchUsers(query: string): Promise { + return axios + .get(`${apiBaseUrl}/search/users?q=${query}`) + .then(extractResponseData); + } +} + +let client: IHttpSearchClient = new HttpSearchClient(); + +export function getHttpSearchClient(): IHttpSearchClient { + return client; +} + +export function setHttpSearchClient( + newClient: IHttpSearchClient +): IHttpSearchClient { + const old = client; + client = newClient; + return old; +} -- cgit v1.2.3