aboutsummaryrefslogtreecommitdiff
path: root/src/background/controllers/CompletionController.ts
blob: 313f38b22d54db838670b2295ced9a88f106a45c (plain) (blame)
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
import {
  ConsoleGetCompletionTypesResponse,
  ConsoleRequestBookmarksResponse, ConsoleRequestHistoryResponse, ConsoleRequestSearchEnginesResponse
} from "../../shared/messages";
import { injectable } from "tsyringe";
import CompletionUseCase from "../completion/CompletionUseCase";

@injectable()
export default class CompletionController {
  constructor(
    private completionUseCase: CompletionUseCase,
  ) {
  }

  async getCompletionTypes(): Promise<ConsoleGetCompletionTypesResponse> {
    return this.completionUseCase.getCompletionTypes();
  }

  async requestSearchEngines(query: string): Promise<ConsoleRequestSearchEnginesResponse> {
    const items = await this.completionUseCase.requestSearchEngines(query);
    return items.map(name => ({ title: name }));
  }

  async requestBookmarks(query: string): Promise<ConsoleRequestBookmarksResponse> {
    return this.completionUseCase.requestBookmarks(query);
  }

  async requestHistory(query: string): Promise<ConsoleRequestHistoryResponse> {
    return this.completionUseCase.requestHistory(query);
  }
}