aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/shared
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-03-08 21:35:43 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-03-08 21:35:43 +0100
commitd38b82810638b9f664c9016fac2684454c273a77 (patch)
tree9465c367e5033675309efca4d66790c6fdd5230d /client/src/app/videos/shared
parent8f9064432122cba0f518a24ac4378357dadec589 (diff)
downloadPeerTube-d38b82810638b9f664c9016fac2684454c273a77.tar.gz
PeerTube-d38b82810638b9f664c9016fac2684454c273a77.tar.zst
PeerTube-d38b82810638b9f664c9016fac2684454c273a77.zip
Add like/dislike system for videos
Diffstat (limited to 'client/src/app/videos/shared')
-rw-r--r--client/src/app/videos/shared/index.ts1
-rw-r--r--client/src/app/videos/shared/rate-type.type.ts1
-rw-r--r--client/src/app/videos/shared/sort-field.type.ts6
-rw-r--r--client/src/app/videos/shared/video.model.ts8
-rw-r--r--client/src/app/videos/shared/video.service.ts43
5 files changed, 51 insertions, 8 deletions
diff --git a/client/src/app/videos/shared/index.ts b/client/src/app/videos/shared/index.ts
index 67d16ead1..beaa528c0 100644
--- a/client/src/app/videos/shared/index.ts
+++ b/client/src/app/videos/shared/index.ts
@@ -1,4 +1,5 @@
1export * from './loader'; 1export * from './loader';
2export * from './sort-field.type'; 2export * from './sort-field.type';
3export * from './rate-type.type';
3export * from './video.model'; 4export * from './video.model';
4export * from './video.service'; 5export * from './video.service';
diff --git a/client/src/app/videos/shared/rate-type.type.ts b/client/src/app/videos/shared/rate-type.type.ts
new file mode 100644
index 000000000..88034d1ff
--- /dev/null
+++ b/client/src/app/videos/shared/rate-type.type.ts
@@ -0,0 +1 @@
export type RateType = 'like' | 'dislike';
diff --git a/client/src/app/videos/shared/sort-field.type.ts b/client/src/app/videos/shared/sort-field.type.ts
index 74908e344..7bda3112a 100644
--- a/client/src/app/videos/shared/sort-field.type.ts
+++ b/client/src/app/videos/shared/sort-field.type.ts
@@ -1,3 +1,3 @@
1export type SortField = "name" | "-name" 1export type SortField = 'name' | '-name'
2 | "duration" | "-duration" 2 | 'duration' | '-duration'
3 | "createdAt" | "-createdAt"; 3 | 'createdAt' | '-createdAt';
diff --git a/client/src/app/videos/shared/video.model.ts b/client/src/app/videos/shared/video.model.ts
index 8e676708b..3eef936eb 100644
--- a/client/src/app/videos/shared/video.model.ts
+++ b/client/src/app/videos/shared/video.model.ts
@@ -12,6 +12,8 @@ export class Video {
12 tags: string[]; 12 tags: string[];
13 thumbnailPath: string; 13 thumbnailPath: string;
14 views: number; 14 views: number;
15 likes: number;
16 dislikes: number;
15 17
16 private static createByString(author: string, podHost: string) { 18 private static createByString(author: string, podHost: string) {
17 return author + '@' + podHost; 19 return author + '@' + podHost;
@@ -38,7 +40,9 @@ export class Video {
38 podHost: string, 40 podHost: string,
39 tags: string[], 41 tags: string[],
40 thumbnailPath: string, 42 thumbnailPath: string,
41 views: number 43 views: number,
44 likes: number,
45 dislikes: number,
42 }) { 46 }) {
43 this.author = hash.author; 47 this.author = hash.author;
44 this.createdAt = new Date(hash.createdAt); 48 this.createdAt = new Date(hash.createdAt);
@@ -52,6 +56,8 @@ export class Video {
52 this.tags = hash.tags; 56 this.tags = hash.tags;
53 this.thumbnailPath = hash.thumbnailPath; 57 this.thumbnailPath = hash.thumbnailPath;
54 this.views = hash.views; 58 this.views = hash.views;
59 this.likes = hash.likes;
60 this.dislikes = hash.dislikes;
55 61
56 this.by = Video.createByString(hash.author, hash.podHost); 62 this.by = Video.createByString(hash.author, hash.podHost);
57 } 63 }
diff --git a/client/src/app/videos/shared/video.service.ts b/client/src/app/videos/shared/video.service.ts
index 7094d9a34..8bb5a2933 100644
--- a/client/src/app/videos/shared/video.service.ts
+++ b/client/src/app/videos/shared/video.service.ts
@@ -6,8 +6,16 @@ import 'rxjs/add/operator/map';
6 6
7import { Search } from '../../shared'; 7import { Search } from '../../shared';
8import { SortField } from './sort-field.type'; 8import { SortField } from './sort-field.type';
9import { RateType } from './rate-type.type';
9import { AuthService } from '../../core'; 10import { AuthService } from '../../core';
10import { AuthHttp, RestExtractor, RestPagination, RestService, ResultList } from '../../shared'; 11import {
12 AuthHttp,
13 RestExtractor,
14 RestPagination,
15 RestService,
16 ResultList,
17 UserService
18} from '../../shared';
11import { Video } from './video.model'; 19import { Video } from './video.model';
12 20
13@Injectable() 21@Injectable()
@@ -56,14 +64,41 @@ export class VideoService {
56 } 64 }
57 65
58 reportVideo(id: string, reason: string) { 66 reportVideo(id: string, reason: string) {
67 const url = VideoService.BASE_VIDEO_URL + id + '/abuse';
59 const body = { 68 const body = {
60 reason 69 reason
61 }; 70 };
62 const url = VideoService.BASE_VIDEO_URL + id + '/abuse';
63 71
64 return this.authHttp.post(url, body) 72 return this.authHttp.post(url, body)
65 .map(this.restExtractor.extractDataBool) 73 .map(this.restExtractor.extractDataBool)
66 .catch((res) => this.restExtractor.handleError(res)); 74 .catch((res) => this.restExtractor.handleError(res));
75 }
76
77 setVideoLike(id: string) {
78 return this.setVideoRate(id, 'like');
79 }
80
81 setVideoDislike(id: string) {
82 return this.setVideoRate(id, 'dislike');
83 }
84
85 getUserVideoRating(id: string) {
86 const url = UserService.BASE_USERS_URL + '/me/videos/' + id + '/rating';
87
88 return this.authHttp.get(url)
89 .map(this.restExtractor.extractDataGet)
90 .catch((res) => this.restExtractor.handleError(res));
91 }
92
93 private setVideoRate(id: string, rateType: RateType) {
94 const url = VideoService.BASE_VIDEO_URL + id + '/rate';
95 const body = {
96 rating: rateType
97 };
98
99 return this.authHttp.put(url, body)
100 .map(this.restExtractor.extractDataBool)
101 .catch((res) => this.restExtractor.handleError(res));
67 } 102 }
68 103
69 private extractVideos(result: ResultList) { 104 private extractVideos(result: ResultList) {