import { UserVideoRate } from '../../../../../shared/models/videos/user-video-rate.model'
import { VideoRateType } from '../../../../../shared/models/videos/video-rate.type'
import { VideoUpdate } from '../../../../../shared/models/videos/video-update.model'
+import { environment } from '../../../environments/environment'
+import { ComponentPagination } from '../rest/component-pagination.model'
import { RestExtractor } from '../rest/rest-extractor.service'
import { RestService } from '../rest/rest.service'
-import { Search } from '../header/search.model'
import { UserService } from '../users/user.service'
import { SortField } from './sort-field.type'
import { VideoDetails } from './video-details.model'
import { VideoEdit } from './video-edit.model'
-import { VideoPagination } from './video-pagination.model'
import { Video } from './video.model'
@Injectable()
export class VideoService {
- private static BASE_VIDEO_URL = API_URL + '/api/v1/videos/'
+ private static BASE_VIDEO_URL = environment.apiUrl + '/api/v1/videos/'
constructor (
private authHttp: HttpClient,
}
updateVideo (video: VideoEdit) {
- const language = video.language ? video.language : null
+ const language = video.language || null
+ const licence = video.licence || null
+ const category = video.category || null
+ const description = video.description || null
const body: VideoUpdate = {
name: video.name,
- category: video.category,
- licence: video.licence,
+ category,
+ licence,
language,
- description: video.description,
+ description,
privacy: video.privacy,
tags: video.tags,
- nsfw: video.nsfw
+ nsfw: video.nsfw,
+ commentsEnabled: video.commentsEnabled
}
return this.authHttp.put(VideoService.BASE_VIDEO_URL + video.id, body)
.catch(this.restExtractor.handleError)
}
- getMyVideos (videoPagination: VideoPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> {
- const pagination = this.videoPaginationToRestPagination(videoPagination)
+ getMyVideos (videoPagination: ComponentPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> {
+ const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
let params = new HttpParams()
params = this.restService.addRestGetParams(params, pagination, sort)
.catch((res) => this.restExtractor.handleError(res))
}
- getVideos (videoPagination: VideoPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> {
- const pagination = this.videoPaginationToRestPagination(videoPagination)
+ getVideos (videoPagination: ComponentPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> {
+ const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
let params = new HttpParams()
params = this.restService.addRestGetParams(params, pagination, sort)
.catch((res) => this.restExtractor.handleError(res))
}
- searchVideos (search: string, videoPagination: VideoPagination, sort: SortField): Observable<{ videos: Video[], totalVideos: number}> {
+ searchVideos (
+ search: string,
+ videoPagination: ComponentPagination,
+ sort: SortField
+ ): Observable<{ videos: Video[], totalVideos: number}> {
const url = VideoService.BASE_VIDEO_URL + 'search'
- const pagination = this.videoPaginationToRestPagination(videoPagination)
+ const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
let params = new HttpParams()
params = this.restService.addRestGetParams(params, pagination, sort)
loadCompleteDescription (descriptionPath: string) {
return this.authHttp
- .get(API_URL + descriptionPath)
+ .get(environment.apiUrl + descriptionPath)
.map(res => res['description'])
.catch((res) => this.restExtractor.handleError(res))
}
return this.setVideoRate(id, 'dislike')
}
+ unsetVideoLike (id: number) {
+ return this.setVideoRate(id, 'none')
+ }
+
getUserVideoRating (id: number): Observable<UserVideoRate> {
const url = UserService.BASE_USERS_URL + 'me/videos/' + id + '/rating'
.catch(res => this.restExtractor.handleError(res))
}
- private videoPaginationToRestPagination (videoPagination: VideoPagination) {
- const start: number = (videoPagination.currentPage - 1) * videoPagination.itemsPerPage
- const count: number = videoPagination.itemsPerPage
-
- return { start, count }
- }
-
private setVideoRate (id: number, rateType: VideoRateType) {
const url = VideoService.BASE_VIDEO_URL + id + '/rate'
const body: UserVideoRateUpdate = {