]>
Commit | Line | Data |
---|---|---|
df98563e C |
1 | import { Injectable } from '@angular/core' |
2 | import { URLSearchParams } from '@angular/http' | |
de59c48f | 3 | |
df98563e | 4 | import { RestPagination } from './rest-pagination' |
de59c48f C |
5 | |
6 | @Injectable() | |
7 | export class RestService { | |
8 | ||
df98563e C |
9 | buildRestGetParams (pagination?: RestPagination, sort?: string) { |
10 | const params = new URLSearchParams() | |
de59c48f C |
11 | |
12 | if (pagination) { | |
df98563e C |
13 | const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage |
14 | const count: number = pagination.itemsPerPage | |
de59c48f | 15 | |
df98563e C |
16 | params.set('start', start.toString()) |
17 | params.set('count', count.toString()) | |
de59c48f C |
18 | } |
19 | ||
20 | if (sort) { | |
df98563e | 21 | params.set('sort', sort) |
de59c48f C |
22 | } |
23 | ||
df98563e | 24 | return params |
de59c48f C |
25 | } |
26 | ||
27 | } |