aboutsummaryrefslogtreecommitdiff
path: root/Timeline/ClientApp/src/app/todo-list-page/todo-list.service.ts
blob: ffcbbc6f8fd21b85f0d420cc20e7977093d43f6b (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
37
38
39
40
41
42
43
44
45
46
47
48
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, from } from 'rxjs';
import { switchMap, map, filter } from 'rxjs/operators';

export interface IssueResponseItem {
  number: number;
  title: string;
  state: string;
  html_url: string;
  pull_request?: any;
}

export type IssueResponse = IssueResponseItem[];

export interface TodoItem {
  number: number;
  title: string;
  isClosed: boolean;
  detailUrl: string;
}

@Injectable({
  providedIn: 'root'
})
export class TodoListService {

  readonly baseUrl = 'https://api.github.com/repos/crupest/Timeline';

  constructor(private client: HttpClient) { }

  getWorkItemList(): Observable<TodoItem> {
    return this.client.get<IssueResponse>(`${this.baseUrl}/issues`, {
      params: {
        state: 'all'
      }
    }).pipe(
      switchMap(result => from(result)),
      filter(result => result.pull_request === undefined), // filter out pull requests.
      map(result => <TodoItem>{
        number: result.number,
        title: result.title,
        isClosed: result.state === 'closed',
        detailUrl: result.html_url
      })
    );
  }
}