diff options
Diffstat (limited to 'client/app/videos/shared/video.service.ts')
-rw-r--r-- | client/app/videos/shared/video.service.ts | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/client/app/videos/shared/video.service.ts b/client/app/videos/shared/video.service.ts index b6e0800a0..7b6519f00 100644 --- a/client/app/videos/shared/video.service.ts +++ b/client/app/videos/shared/video.service.ts | |||
@@ -12,7 +12,16 @@ import { Video } from './video.model'; | |||
12 | export class VideoService { | 12 | export class VideoService { |
13 | private static BASE_VIDEO_URL = '/api/v1/videos/'; | 13 | private static BASE_VIDEO_URL = '/api/v1/videos/'; |
14 | 14 | ||
15 | constructor(private http: Http, private authService: AuthService) {} | 15 | constructor( |
16 | private authService: AuthService, | ||
17 | private http: Http | ||
18 | ) {} | ||
19 | |||
20 | getVideo(id: string) { | ||
21 | return this.http.get(VideoService.BASE_VIDEO_URL + id) | ||
22 | .map(res => <Video> res.json()) | ||
23 | .catch(this.handleError); | ||
24 | } | ||
16 | 25 | ||
17 | getVideos(pagination: Pagination, sort: SortField) { | 26 | getVideos(pagination: Pagination, sort: SortField) { |
18 | const params = this.createPaginationParams(pagination); | 27 | const params = this.createPaginationParams(pagination); |
@@ -25,12 +34,6 @@ export class VideoService { | |||
25 | .catch(this.handleError); | 34 | .catch(this.handleError); |
26 | } | 35 | } |
27 | 36 | ||
28 | getVideo(id: string) { | ||
29 | return this.http.get(VideoService.BASE_VIDEO_URL + id) | ||
30 | .map(res => <Video> res.json()) | ||
31 | .catch(this.handleError); | ||
32 | } | ||
33 | |||
34 | removeVideo(id: string) { | 37 | removeVideo(id: string) { |
35 | const options = this.authService.getAuthRequestOptions(); | 38 | const options = this.authService.getAuthRequestOptions(); |
36 | return this.http.delete(VideoService.BASE_VIDEO_URL + id, options) | 39 | return this.http.delete(VideoService.BASE_VIDEO_URL + id, options) |
@@ -50,6 +53,17 @@ export class VideoService { | |||
50 | .catch(this.handleError); | 53 | .catch(this.handleError); |
51 | } | 54 | } |
52 | 55 | ||
56 | private createPaginationParams(pagination: Pagination) { | ||
57 | const params = new URLSearchParams(); | ||
58 | const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage; | ||
59 | const count: number = pagination.itemsPerPage; | ||
60 | |||
61 | params.set('start', start.toString()); | ||
62 | params.set('count', count.toString()); | ||
63 | |||
64 | return params; | ||
65 | } | ||
66 | |||
53 | private extractVideos(body: any) { | 67 | private extractVideos(body: any) { |
54 | const videos_json = body.data; | 68 | const videos_json = body.data; |
55 | const totalVideos = body.total; | 69 | const totalVideos = body.total; |
@@ -65,15 +79,4 @@ export class VideoService { | |||
65 | console.error(error); | 79 | console.error(error); |
66 | return Observable.throw(error.json().error || 'Server error'); | 80 | return Observable.throw(error.json().error || 'Server error'); |
67 | } | 81 | } |
68 | |||
69 | private createPaginationParams(pagination: Pagination) { | ||
70 | const params = new URLSearchParams(); | ||
71 | const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage; | ||
72 | const count: number = pagination.itemsPerPage; | ||
73 | |||
74 | params.set('start', start.toString()); | ||
75 | params.set('count', count.toString()); | ||
76 | |||
77 | return params; | ||
78 | } | ||
79 | } | 82 | } |