aboutsummaryrefslogtreecommitdiff
path: root/FrontEnd/src/app/http/search.ts
blob: 8ca48fe9f99b9bc3fc32fa54cf7c7c55725f4039 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { apiBaseUrl, axios, extractResponseData } from "./common";
import { HttpTimelineInfo } from "./timeline";
import { HttpUser } from "./user";

export interface IHttpSearchClient {
  searchTimelines(query: string): Promise<HttpTimelineInfo[]>;
  searchUsers(query: string): Promise<HttpUser[]>;
}

export class HttpSearchClient implements IHttpSearchClient {
  searchTimelines(query: string): Promise<HttpTimelineInfo[]> {
    return axios
      .get<HttpTimelineInfo[]>(`${apiBaseUrl}/search/timelines?q=${query}`)
      .then(extractResponseData);
  }

  searchUsers(query: string): Promise<HttpUser[]> {
    return axios
      .get<HttpUser[]>(`${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;
}