aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorPhieF <phoenamandre@gmail.com>2018-06-27 14:24:49 +0200
committerChocobozzz <me@florianbigard.com>2018-06-27 14:24:49 +0200
commit61b909b9bf849516f30dab2bf5977acfbbddc5c6 (patch)
tree8724ecfe2d8f054dde21f9e2acb32902321dfcf5
parentadc236fee3c40bf1fbaa4ad4fc22a7ecb65fb09f (diff)
downloadPeerTube-61b909b9bf849516f30dab2bf5977acfbbddc5c6.tar.gz
PeerTube-61b909b9bf849516f30dab2bf5977acfbbddc5c6.tar.zst
PeerTube-61b909b9bf849516f30dab2bf5977acfbbddc5c6.zip
Filter by category (#720)
* get videos with specific category (api) * update api doc with category * add url parameter to filter by category * fix lint issues
-rw-r--r--client/src/app/shared/video/abstract-video-list.ts3
-rw-r--r--client/src/app/shared/video/video.service.ts11
-rw-r--r--client/src/app/videos/video-list/video-local.component.ts4
-rw-r--r--client/src/app/videos/video-list/video-recently-added.component.ts4
-rw-r--r--client/src/app/videos/video-list/video-trending.component.ts4
-rw-r--r--server/controllers/api/videos/index.ts1
-rw-r--r--server/models/video/video.ts7
-rw-r--r--support/doc/api/openapi.yaml5
8 files changed, 30 insertions, 9 deletions
diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts
index a468d3231..d60536e20 100644
--- a/client/src/app/shared/video/abstract-video-list.ts
+++ b/client/src/app/shared/video/abstract-video-list.ts
@@ -24,6 +24,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
24 totalItems: null 24 totalItems: null
25 } 25 }
26 sort: VideoSortField = '-publishedAt' 26 sort: VideoSortField = '-publishedAt'
27 category?: number
27 defaultSort: VideoSortField = '-publishedAt' 28 defaultSort: VideoSortField = '-publishedAt'
28 syndicationItems = [] 29 syndicationItems = []
29 30
@@ -167,7 +168,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
167 168
168 protected loadRouteParams (routeParams: { [ key: string ]: any }) { 169 protected loadRouteParams (routeParams: { [ key: string ]: any }) {
169 this.sort = routeParams['sort'] as VideoSortField || this.defaultSort 170 this.sort = routeParams['sort'] as VideoSortField || this.defaultSort
170 171 this.category = routeParams['category']
171 if (routeParams['page'] !== undefined) { 172 if (routeParams['page'] !== undefined) {
172 this.pagination.currentPage = parseInt(routeParams['page'], 10) 173 this.pagination.currentPage = parseInt(routeParams['page'], 10)
173 } else { 174 } else {
diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts
index 2da36ff1b..4783adf42 100644
--- a/client/src/app/shared/video/video.service.ts
+++ b/client/src/app/shared/video/video.service.ts
@@ -158,7 +158,8 @@ export class VideoService {
158 getVideos ( 158 getVideos (
159 videoPagination: ComponentPagination, 159 videoPagination: ComponentPagination,
160 sort: VideoSortField, 160 sort: VideoSortField,
161 filter?: VideoFilter 161 filter?: VideoFilter,
162 category?: number
162 ): Observable<{ videos: Video[], totalVideos: number }> { 163 ): Observable<{ videos: Video[], totalVideos: number }> {
163 const pagination = this.restService.componentPaginationToRestPagination(videoPagination) 164 const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
164 165
@@ -169,6 +170,10 @@ export class VideoService {
169 params = params.set('filter', filter) 170 params = params.set('filter', filter)
170 } 171 }
171 172
173 if (category) {
174 params = params.set('category', category + '')
175 }
176
172 return this.authHttp 177 return this.authHttp
173 .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params }) 178 .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
174 .pipe( 179 .pipe(
@@ -202,11 +207,13 @@ export class VideoService {
202 return feeds 207 return feeds
203 } 208 }
204 209
205 getVideoFeedUrls (sort: VideoSortField, filter?: VideoFilter) { 210 getVideoFeedUrls (sort: VideoSortField, filter?: VideoFilter, category?: number) {
206 let params = this.restService.addRestGetParams(new HttpParams(), undefined, sort) 211 let params = this.restService.addRestGetParams(new HttpParams(), undefined, sort)
207 212
208 if (filter) params = params.set('filter', filter) 213 if (filter) params = params.set('filter', filter)
209 214
215 if (category) params = params.set('category', category + '')
216
210 return this.buildBaseFeedUrls(params) 217 return this.buildBaseFeedUrls(params)
211 } 218 }
212 219
diff --git a/client/src/app/videos/video-list/video-local.component.ts b/client/src/app/videos/video-list/video-local.component.ts
index dbe1d937d..de460ea60 100644
--- a/client/src/app/videos/video-list/video-local.component.ts
+++ b/client/src/app/videos/video-list/video-local.component.ts
@@ -50,10 +50,10 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On
50 getVideosObservable (page: number) { 50 getVideosObservable (page: number) {
51 const newPagination = immutableAssign(this.pagination, { currentPage: page }) 51 const newPagination = immutableAssign(this.pagination, { currentPage: page })
52 52
53 return this.videoService.getVideos(newPagination, this.sort, this.filter) 53 return this.videoService.getVideos(newPagination, this.sort, this.filter, this.category)
54 } 54 }
55 55
56 generateSyndicationList () { 56 generateSyndicationList () {
57 this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, this.filter) 57 this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, this.filter, this.category)
58 } 58 }
59} 59}
diff --git a/client/src/app/videos/video-list/video-recently-added.component.ts b/client/src/app/videos/video-list/video-recently-added.component.ts
index 004a49168..75688731d 100644
--- a/client/src/app/videos/video-list/video-recently-added.component.ts
+++ b/client/src/app/videos/video-list/video-recently-added.component.ts
@@ -48,10 +48,10 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On
48 getVideosObservable (page: number) { 48 getVideosObservable (page: number) {
49 const newPagination = immutableAssign(this.pagination, { currentPage: page }) 49 const newPagination = immutableAssign(this.pagination, { currentPage: page })
50 50
51 return this.videoService.getVideos(newPagination, this.sort) 51 return this.videoService.getVideos(newPagination, this.sort, undefined, this.category)
52 } 52 }
53 53
54 generateSyndicationList () { 54 generateSyndicationList () {
55 this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort) 55 this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.category)
56 } 56 }
57} 57}
diff --git a/client/src/app/videos/video-list/video-trending.component.ts b/client/src/app/videos/video-list/video-trending.component.ts
index f2174aa14..3738b95b1 100644
--- a/client/src/app/videos/video-list/video-trending.component.ts
+++ b/client/src/app/videos/video-list/video-trending.component.ts
@@ -47,10 +47,10 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit,
47 47
48 getVideosObservable (page: number) { 48 getVideosObservable (page: number) {
49 const newPagination = immutableAssign(this.pagination, { currentPage: page }) 49 const newPagination = immutableAssign(this.pagination, { currentPage: page })
50 return this.videoService.getVideos(newPagination, this.sort) 50 return this.videoService.getVideos(newPagination, this.sort, undefined, this.category)
51 } 51 }
52 52
53 generateSyndicationList () { 53 generateSyndicationList () {
54 this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort) 54 this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.category)
55 } 55 }
56} 56}
diff --git a/server/controllers/api/videos/index.ts b/server/controllers/api/videos/index.ts
index ca800a9a8..b4ced8c1e 100644
--- a/server/controllers/api/videos/index.ts
+++ b/server/controllers/api/videos/index.ts
@@ -407,6 +407,7 @@ async function listVideos (req: express.Request, res: express.Response, next: ex
407 start: req.query.start, 407 start: req.query.start,
408 count: req.query.count, 408 count: req.query.count,
409 sort: req.query.sort, 409 sort: req.query.sort,
410 category: req.query.category,
410 hideNSFW: isNSFWHidden(res), 411 hideNSFW: isNSFWHidden(res),
411 filter: req.query.filter as VideoFilter, 412 filter: req.query.filter as VideoFilter,
412 withFiles: false 413 withFiles: false
diff --git a/server/models/video/video.ts b/server/models/video/video.ts
index 0041e4d38..0af70cadf 100644
--- a/server/models/video/video.ts
+++ b/server/models/video/video.ts
@@ -106,6 +106,7 @@ export enum ScopeNames {
106 actorId: number, 106 actorId: number,
107 hideNSFW: boolean, 107 hideNSFW: boolean,
108 filter?: VideoFilter, 108 filter?: VideoFilter,
109 category?: number,
109 withFiles?: boolean, 110 withFiles?: boolean,
110 accountId?: number, 111 accountId?: number,
111 videoChannelId?: number 112 videoChannelId?: number
@@ -215,6 +216,10 @@ export enum ScopeNames {
215 query.where['nsfw'] = false 216 query.where['nsfw'] = false
216 } 217 }
217 218
219 if (options.category) {
220 query.where['category'] = options.category
221 }
222
218 if (options.accountId) { 223 if (options.accountId) {
219 accountInclude.where = { 224 accountInclude.where = {
220 id: options.accountId 225 id: options.accountId
@@ -730,6 +735,7 @@ export class VideoModel extends Model<VideoModel> {
730 sort: string, 735 sort: string,
731 hideNSFW: boolean, 736 hideNSFW: boolean,
732 withFiles: boolean, 737 withFiles: boolean,
738 category?: number,
733 filter?: VideoFilter, 739 filter?: VideoFilter,
734 accountId?: number, 740 accountId?: number,
735 videoChannelId?: number 741 videoChannelId?: number
@@ -746,6 +752,7 @@ export class VideoModel extends Model<VideoModel> {
746 ScopeNames.AVAILABLE_FOR_LIST, { 752 ScopeNames.AVAILABLE_FOR_LIST, {
747 actorId: serverActor.id, 753 actorId: serverActor.id,
748 hideNSFW: options.hideNSFW, 754 hideNSFW: options.hideNSFW,
755 category: options.category,
749 filter: options.filter, 756 filter: options.filter,
750 withFiles: options.withFiles, 757 withFiles: options.withFiles,
751 accountId: options.accountId, 758 accountId: options.accountId,
diff --git a/support/doc/api/openapi.yaml b/support/doc/api/openapi.yaml
index 4b7bc23b4..89e510cb4 100644
--- a/support/doc/api/openapi.yaml
+++ b/support/doc/api/openapi.yaml
@@ -529,6 +529,11 @@ paths:
529 produces: 529 produces:
530 - application/json 530 - application/json
531 parameters: 531 parameters:
532 - name: category
533 in: query
534 required: false
535 type: number
536 description: category id of the video
532 - name: start 537 - name: start
533 in: query 538 in: query
534 required: false 539 required: false