1
0
Fork 0

Add search by original publication date

This commit is contained in:
Andrés Maldonado 2018-11-27 18:57:02 +01:00 committed by Chocobozzz
parent 7f8f8bdb4a
commit 31d065cc50
No known key found for this signature in database
GPG key ID: 583A612D890159BE
7 changed files with 163 additions and 2 deletions

View file

@ -4,6 +4,9 @@ export class AdvancedSearch {
startDate: string // ISO 8601 startDate: string // ISO 8601
endDate: string // ISO 8601 endDate: string // ISO 8601
originallyPublishedStartDate: string // ISO 8601
originallyPublishedEndDate: string // ISO 8601
nsfw: NSFWQuery nsfw: NSFWQuery
categoryOneOf: string categoryOneOf: string
@ -23,6 +26,8 @@ export class AdvancedSearch {
constructor (options?: { constructor (options?: {
startDate?: string startDate?: string
endDate?: string endDate?: string
originallyPublishedStartDate?: string
originallyPublishedEndDate?: string
nsfw?: NSFWQuery nsfw?: NSFWQuery
categoryOneOf?: string categoryOneOf?: string
licenceOneOf?: string licenceOneOf?: string
@ -37,6 +42,9 @@ export class AdvancedSearch {
this.startDate = options.startDate || undefined this.startDate = options.startDate || undefined
this.endDate = options.endDate || undefined this.endDate = options.endDate || undefined
this.originallyPublishedStartDate = options.originallyPublishedStartDate || undefined
this.originallyPublishedEndDate = options.originallyPublishedEndDate || undefined
this.nsfw = options.nsfw || undefined this.nsfw = options.nsfw || undefined
this.categoryOneOf = options.categoryOneOf || undefined this.categoryOneOf = options.categoryOneOf || undefined
this.licenceOneOf = options.licenceOneOf || undefined this.licenceOneOf = options.licenceOneOf || undefined
@ -66,6 +74,8 @@ export class AdvancedSearch {
reset () { reset () {
this.startDate = undefined this.startDate = undefined
this.endDate = undefined this.endDate = undefined
this.originallyPublishedStartDate = undefined
this.originallyPublishedEndDate = undefined
this.nsfw = undefined this.nsfw = undefined
this.categoryOneOf = undefined this.categoryOneOf = undefined
this.licenceOneOf = undefined this.licenceOneOf = undefined
@ -82,6 +92,8 @@ export class AdvancedSearch {
return { return {
startDate: this.startDate, startDate: this.startDate,
endDate: this.endDate, endDate: this.endDate,
originallyPublishedStartDate: this.originallyPublishedStartDate,
originallyPublishedEndDate: this.originallyPublishedEndDate,
nsfw: this.nsfw, nsfw: this.nsfw,
categoryOneOf: this.categoryOneOf, categoryOneOf: this.categoryOneOf,
licenceOneOf: this.licenceOneOf, licenceOneOf: this.licenceOneOf,
@ -98,6 +110,8 @@ export class AdvancedSearch {
return { return {
startDate: this.startDate, startDate: this.startDate,
endDate: this.endDate, endDate: this.endDate,
originallyPublishedStartDate: this.originallyPublishedStartDate,
originallyPublishedEndDate: this.originallyPublishedEndDate,
nsfw: this.nsfw, nsfw: this.nsfw,
categoryOneOf: this.intoArray(this.categoryOneOf), categoryOneOf: this.intoArray(this.categoryOneOf),
licenceOneOf: this.intoArray(this.licenceOneOf), licenceOneOf: this.intoArray(this.licenceOneOf),

View file

@ -20,6 +20,27 @@
</div> </div>
</div> </div>
<div class="form-group">
<label i18n for="original-publication-after">Original publication year</label>
<div class="row">
<div class="col-sm-6">
<input
type="text" id="original-publication-after" name="original-publication-after"
i18n-placeholder placeholder="After..."
[(ngModel)]="originallyPublishedStartYear"
>
</div>
<div class="col-sm-6">
<input
type="text" id="original-publication-before" name="original-publication-before"
i18n-placeholder placeholder="Before..."
[(ngModel)]="originallyPublishedEndYear"
>
</div>
</div>
</div>
<div class="form-group"> <div class="form-group">
<div i18n class="radio-label">Duration</div> <div i18n class="radio-label">Duration</div>

View file

@ -25,6 +25,9 @@ export class SearchFiltersComponent implements OnInit {
publishedDateRange: string publishedDateRange: string
durationRange: string durationRange: string
originallyPublishedStartYear: string
originallyPublishedEndYear: string
constructor ( constructor (
private i18n: I18n, private i18n: I18n,
private serverService: ServerService private serverService: ServerService
@ -86,15 +89,27 @@ export class SearchFiltersComponent implements OnInit {
this.loadFromDurationRange() this.loadFromDurationRange()
this.loadFromPublishedRange() this.loadFromPublishedRange()
this.loadOriginallyPublishedAtYears()
} }
formUpdated () { formUpdated () {
this.updateModelFromDurationRange() this.updateModelFromDurationRange()
this.updateModelFromPublishedRange() this.updateModelFromPublishedRange()
this.updateModelFromOriginallyPublishedAtYears()
this.filtered.emit(this.advancedSearch) this.filtered.emit(this.advancedSearch)
} }
private loadOriginallyPublishedAtYears () {
this.originallyPublishedStartYear = this.advancedSearch.originallyPublishedStartDate
? new Date(this.advancedSearch.originallyPublishedStartDate).getFullYear().toString()
: null
this.originallyPublishedEndYear = this.advancedSearch.originallyPublishedEndDate
? new Date(this.advancedSearch.originallyPublishedEndDate).getFullYear().toString()
: null
}
private loadFromDurationRange () { private loadFromDurationRange () {
if (this.advancedSearch.durationMin || this.advancedSearch.durationMax) { if (this.advancedSearch.durationMin || this.advancedSearch.durationMax) {
const fourMinutes = 60 * 4 const fourMinutes = 60 * 4
@ -127,6 +142,32 @@ export class SearchFiltersComponent implements OnInit {
} }
} }
private updateModelFromOriginallyPublishedAtYears () {
const baseDate = new Date()
baseDate.setHours(0, 0, 0, 0)
baseDate.setMonth(0, 1)
if (this.originallyPublishedStartYear) {
const year = parseInt(this.originallyPublishedStartYear, 10)
const start = new Date(baseDate)
start.setFullYear(year)
this.advancedSearch.originallyPublishedStartDate = start.toISOString()
} else {
this.advancedSearch.originallyPublishedStartDate = null
}
if (this.originallyPublishedEndYear) {
const year = parseInt(this.originallyPublishedEndYear, 10)
const end = new Date(baseDate)
end.setFullYear(year)
this.advancedSearch.originallyPublishedEndDate = end.toISOString()
} else {
this.advancedSearch.originallyPublishedEndDate = null
}
}
private updateModelFromDurationRange () { private updateModelFromDurationRange () {
if (!this.durationRange) return if (!this.durationRange) return
@ -174,4 +215,5 @@ export class SearchFiltersComponent implements OnInit {
this.advancedSearch.startDate = date.toISOString() this.advancedSearch.startDate = date.toISOString()
} }
} }

View file

@ -1174,6 +1174,8 @@ export class VideoModel extends Model<VideoModel> {
sort?: string sort?: string
startDate?: string // ISO 8601 startDate?: string // ISO 8601
endDate?: string // ISO 8601 endDate?: string // ISO 8601
originallyPublishedStartDate?: string
originallyPublishedEndDate?: string
nsfw?: boolean nsfw?: boolean
categoryOneOf?: number[] categoryOneOf?: number[]
licenceOneOf?: number[] licenceOneOf?: number[]
@ -1196,6 +1198,15 @@ export class VideoModel extends Model<VideoModel> {
whereAnd.push({ publishedAt: publishedAtRange }) whereAnd.push({ publishedAt: publishedAtRange })
} }
if (options.originallyPublishedStartDate || options.originallyPublishedEndDate) {
const originallyPublishedAtRange = {}
if (options.originallyPublishedStartDate) originallyPublishedAtRange[ Sequelize.Op.gte ] = options.originallyPublishedStartDate
if (options.originallyPublishedEndDate) originallyPublishedAtRange[ Sequelize.Op.lte ] = options.originallyPublishedEndDate
whereAnd.push({ originallyPublishedAt: originallyPublishedAtRange })
}
if (options.durationMin || options.durationMax) { if (options.durationMin || options.durationMax) {
const durationRange = {} const durationRange = {}

View file

@ -113,6 +113,12 @@ describe('Test videos API validator', function () {
const customQuery2 = immutableAssign(query, { endDate: 'hello' }) const customQuery2 = immutableAssign(query, { endDate: 'hello' })
await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 }) await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: 400 })
const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' })
await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: 400 })
const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' })
await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: 400 })
}) })
}) })

View file

@ -60,7 +60,10 @@ describe('Test a videos search', function () {
const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2 '] }) const attributes6 = immutableAssign(attributes1, { name: attributes1.name + ' - 6', tags: [ 't1', 't2 '] })
await uploadVideo(server.url, server.accessToken, attributes6) await uploadVideo(server.url, server.accessToken, attributes6)
const attributes7 = immutableAssign(attributes1, { name: attributes1.name + ' - 7' }) const attributes7 = immutableAssign(attributes1, {
name: attributes1.name + ' - 7',
originallyPublishedAt: '2019-02-12T09:58:08.286Z'
})
await uploadVideo(server.url, server.accessToken, attributes7) await uploadVideo(server.url, server.accessToken, attributes7)
const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 }) const attributes8 = immutableAssign(attributes1, { name: attributes1.name + ' - 8', licence: 4 })
@ -343,6 +346,67 @@ describe('Test a videos search', function () {
expect(videos[0].name).to.equal('1111 2222 3333') expect(videos[0].name).to.equal('1111 2222 3333')
}) })
it('Should search on originally published date', async function () {
const baseQuery = {
search: '1111 2222 3333',
languageOneOf: [ 'pl', 'fr' ],
durationMax: 4,
nsfw: 'false' as 'false',
licenceOneOf: [ 1, 4 ]
}
{
const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-02-11T09:58:08.286Z' })
const res = await advancedVideosSearch(server.url, query)
expect(res.body.total).to.equal(1)
expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
}
{
const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-03-11T09:58:08.286Z' })
const res = await advancedVideosSearch(server.url, query)
expect(res.body.total).to.equal(1)
expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
}
{
const query = immutableAssign(baseQuery, { originallyPublishedEndDate: '2019-01-11T09:58:08.286Z' })
const res = await advancedVideosSearch(server.url, query)
expect(res.body.total).to.equal(0)
}
{
const query = immutableAssign(baseQuery, { originallyPublishedStartDate: '2019-03-11T09:58:08.286Z' })
const res = await advancedVideosSearch(server.url, query)
expect(res.body.total).to.equal(0)
}
{
const query = immutableAssign(baseQuery, {
originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
originallyPublishedEndDate: '2019-01-10T09:58:08.286Z'
})
const res = await advancedVideosSearch(server.url, query)
expect(res.body.total).to.equal(0)
}
{
const query = immutableAssign(baseQuery, {
originallyPublishedStartDate: '2019-01-11T09:58:08.286Z',
originallyPublishedEndDate: '2019-04-11T09:58:08.286Z'
})
const res = await advancedVideosSearch(server.url, query)
expect(res.body.total).to.equal(1)
expect(res.body.data[0].name).to.equal('1111 2222 3333 - 7')
}
})
after(async function () { after(async function () {
killallServers([ server ]) killallServers([ server ])

View file

@ -11,6 +11,9 @@ export interface VideosSearchQuery {
startDate?: string // ISO 8601 startDate?: string // ISO 8601
endDate?: string // ISO 8601 endDate?: string // ISO 8601
originallyPublishedStartDate?: string // ISO 8601
originallyPublishedEndDate?: string // ISO 8601
nsfw?: NSFWQuery nsfw?: NSFWQuery
categoryOneOf?: number[] categoryOneOf?: number[]