Filter by category (#720)
authorPhieF <phoenamandre@gmail.com>
Wed, 27 Jun 2018 12:24:49 +0000 (14:24 +0200)
committerChocobozzz <me@florianbigard.com>
Wed, 27 Jun 2018 12:24:49 +0000 (14:24 +0200)
* get videos with specific category (api)

* update api doc with category

* add url parameter to filter by category

* fix lint issues

client/src/app/shared/video/abstract-video-list.ts
client/src/app/shared/video/video.service.ts
client/src/app/videos/video-list/video-local.component.ts
client/src/app/videos/video-list/video-recently-added.component.ts
client/src/app/videos/video-list/video-trending.component.ts
server/controllers/api/videos/index.ts
server/models/video/video.ts
support/doc/api/openapi.yaml

index a468d3231fc97587126d4b4f5f771f60868a2118..d60536e20e5d71728910f4ec328ebdc02d2bf3ee 100644 (file)
@@ -24,6 +24,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
     totalItems: null
   }
   sort: VideoSortField = '-publishedAt'
+  category?: number
   defaultSort: VideoSortField = '-publishedAt'
   syndicationItems = []
 
@@ -167,7 +168,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy {
 
   protected loadRouteParams (routeParams: { [ key: string ]: any }) {
     this.sort = routeParams['sort'] as VideoSortField || this.defaultSort
-
+    this.category = routeParams['category']
     if (routeParams['page'] !== undefined) {
       this.pagination.currentPage = parseInt(routeParams['page'], 10)
     } else {
index 2da36ff1b721fb8f8afa6621262fbd8cec3d4a61..4783adf42bd9524fd2d0d26f074163fde07620ce 100644 (file)
@@ -158,7 +158,8 @@ export class VideoService {
   getVideos (
     videoPagination: ComponentPagination,
     sort: VideoSortField,
-    filter?: VideoFilter
+    filter?: VideoFilter,
+    category?: number
   ): Observable<{ videos: Video[], totalVideos: number }> {
     const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
 
@@ -169,6 +170,10 @@ export class VideoService {
       params = params.set('filter', filter)
     }
 
+    if (category) {
+      params = params.set('category', category + '')
+    }
+
     return this.authHttp
                .get<ResultList<Video>>(VideoService.BASE_VIDEO_URL, { params })
                .pipe(
@@ -202,11 +207,13 @@ export class VideoService {
     return feeds
   }
 
-  getVideoFeedUrls (sort: VideoSortField, filter?: VideoFilter) {
+  getVideoFeedUrls (sort: VideoSortField, filter?: VideoFilter, category?: number) {
     let params = this.restService.addRestGetParams(new HttpParams(), undefined, sort)
 
     if (filter) params = params.set('filter', filter)
 
+    if (category) params = params.set('category', category + '')
+
     return this.buildBaseFeedUrls(params)
   }
 
index dbe1d937d2e4654b328b55dfbfdb9c88a0a1349c..de460ea60eaf1d470265a6202556014e79344b0b 100644 (file)
@@ -50,10 +50,10 @@ export class VideoLocalComponent extends AbstractVideoList implements OnInit, On
   getVideosObservable (page: number) {
     const newPagination = immutableAssign(this.pagination, { currentPage: page })
 
-    return this.videoService.getVideos(newPagination, this.sort, this.filter)
+    return this.videoService.getVideos(newPagination, this.sort, this.filter, this.category)
   }
 
   generateSyndicationList () {
-    this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, this.filter)
+    this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, this.filter, this.category)
   }
 }
index 004a491683b9ac6dfb6e05721392952f4fa06592..75688731dca85deff9cbf8f857509d130de269e1 100644 (file)
@@ -48,10 +48,10 @@ export class VideoRecentlyAddedComponent extends AbstractVideoList implements On
   getVideosObservable (page: number) {
     const newPagination = immutableAssign(this.pagination, { currentPage: page })
 
-    return this.videoService.getVideos(newPagination, this.sort)
+    return this.videoService.getVideos(newPagination, this.sort, undefined, this.category)
   }
 
   generateSyndicationList () {
-    this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort)
+    this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.category)
   }
 }
index f2174aa145cb4daa1a08ada098fd75ad3764c444..3738b95b1f3745802c649a94bc578506811c7e63 100644 (file)
@@ -47,10 +47,10 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit,
 
   getVideosObservable (page: number) {
     const newPagination = immutableAssign(this.pagination, { currentPage: page })
-    return this.videoService.getVideos(newPagination, this.sort)
+    return this.videoService.getVideos(newPagination, this.sort, undefined, this.category)
   }
 
   generateSyndicationList () {
-    this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort)
+    this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.category)
   }
 }
index ca800a9a8bece715915a307b93d0b2845176479f..b4ced8c1e64a9c656922208b3ee331d824085637 100644 (file)
@@ -407,6 +407,7 @@ async function listVideos (req: express.Request, res: express.Response, next: ex
     start: req.query.start,
     count: req.query.count,
     sort: req.query.sort,
+    category: req.query.category,
     hideNSFW: isNSFWHidden(res),
     filter: req.query.filter as VideoFilter,
     withFiles: false
index 0041e4d387a94a6d58a8b9ff12f72659fcb08c96..0af70cadf8b79789088ae99dd22b7c246e8b0630 100644 (file)
@@ -106,6 +106,7 @@ export enum ScopeNames {
     actorId: number,
     hideNSFW: boolean,
     filter?: VideoFilter,
+    category?: number,
     withFiles?: boolean,
     accountId?: number,
     videoChannelId?: number
@@ -215,6 +216,10 @@ export enum ScopeNames {
       query.where['nsfw'] = false
     }
 
+    if (options.category) {
+      query.where['category'] = options.category
+    }
+
     if (options.accountId) {
       accountInclude.where = {
         id: options.accountId
@@ -730,6 +735,7 @@ export class VideoModel extends Model<VideoModel> {
     sort: string,
     hideNSFW: boolean,
     withFiles: boolean,
+    category?: number,
     filter?: VideoFilter,
     accountId?: number,
     videoChannelId?: number
@@ -746,6 +752,7 @@ export class VideoModel extends Model<VideoModel> {
         ScopeNames.AVAILABLE_FOR_LIST, {
           actorId: serverActor.id,
           hideNSFW: options.hideNSFW,
+          category: options.category,
           filter: options.filter,
           withFiles: options.withFiles,
           accountId: options.accountId,
index 4b7bc23b4a2811c07a2a434497a4dd436e3b9098..89e510cb4b88aa81ffaf83a38231ad81c87ed3da 100644 (file)
@@ -529,6 +529,11 @@ paths:
       produces:
         - application/json
       parameters:
+        - name: category
+          in: query
+          required: false
+          type: number
+          description: category id of the video
         - name: start
           in: query
           required: false