Skip to content

Commit fd36964

Browse files
author
Leszek Wiesner
authored
Merge pull request #356 from Lezek123/channelsApiFixes
API: Fix /channels and add /channels/unverified
2 parents 7ba98ef + a358370 commit fd36964

File tree

3 files changed

+75
-7
lines changed

3 files changed

+75
-7
lines changed

src/repository/channel.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,17 +299,19 @@ export class ChannelsRepository implements IRepository<YtChannel> {
299299
})
300300
}
301301

302-
async query(init: ConditionInitializer, f: (q: Query<AnyItem>) => Query<AnyItem>) {
302+
async query(init: ConditionInitializer, f: (q: Query<AnyItem>) => Query<AnyItem>, limit?: number) {
303303
return this.withLock(async () => {
304304
let lastKey = undefined
305305
const results = []
306306
do {
307-
// FIXME: Is this the reason why /channels returns ALL channels?
308307
let queriedBatch: QueryResponse<AnyItem> = await f(this.model.query(init))
309308
.startAt(lastKey as any)
310309
.exec()
311310
let batchResult = queriedBatch.map((b) => mapTo<YtChannel>(b))
312311
results.push(...batchResult)
312+
if (limit && results.length >= limit) {
313+
return results.slice(0, limit)
314+
}
313315
lastKey = queriedBatch.lastKey
314316
} while (lastKey)
315317
return results
@@ -396,12 +398,26 @@ export class ChannelsService {
396398
}
397399

398400
/**
399-
* @param count Number of record to retrieve
400-
* @returns List of `n` recent verified channels
401+
* @param limit Max. number of records to retrieve
402+
* @returns List of up to `limit` recent, VERIFIED channels
403+
*/
404+
async getRecent(limit: number): Promise<YtChannel[]> {
405+
return this.channelsRepository.query(
406+
{ phantomKey: 'phantomData' },
407+
(q) => q.sort('descending').using('phantomKey-createdAt-index'),
408+
limit
409+
)
410+
}
411+
412+
/**
413+
* @param limit Max. number of records to retrieve
414+
* @returns List of up to `limit` recent, UNVERIFIED channels
401415
*/
402-
async getRecent(count: number): Promise<YtChannel[]> {
403-
return this.channelsRepository.query({ phantomKey: 'phantomData' }, (q) =>
404-
q.sort('descending').limit(count).using('phantomKey-createdAt-index')
416+
async getUnverified(limit?: number): Promise<YtChannel[]> {
417+
return this.channelsRepository.query(
418+
{ phantomKey: 'phantomData', yppStatus: 'Unverified' },
419+
(q) => q.sort('descending').using('phantomKey-createdAt-index'),
420+
limit
405421
)
406422
}
407423

src/services/httpApi/api-spec.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,29 @@
9090
]
9191
}
9292
},
93+
"/channels/unverified": {
94+
"get": {
95+
"operationId": "ChannelsController_getUnverifiedChannels",
96+
"summary": "",
97+
"description": "Retrieves channels waiting for verification",
98+
"parameters": [],
99+
"responses": {
100+
"default": {
101+
"description": "",
102+
"content": {
103+
"application/json": {
104+
"schema": {
105+
"$ref": "#/components/schemas/ChannelDto"
106+
}
107+
}
108+
}
109+
}
110+
},
111+
"tags": [
112+
"channels"
113+
]
114+
}
115+
},
93116
"/channels/{joystreamChannelId}": {
94117
"get": {
95118
"operationId": "ChannelsController_get",
@@ -898,6 +921,21 @@
898921
"OptedOut"
899922
]
900923
},
924+
"preOptOutStatus": {
925+
"type": "string",
926+
"enum": [
927+
"Unverified",
928+
"Verified::Bronze",
929+
"Verified::Silver",
930+
"Verified::Gold",
931+
"Verified::Diamond",
932+
"Suspended::CopyrightBreach",
933+
"Suspended::MisleadingContent",
934+
"Suspended::ProgramTermsExploit",
935+
"Suspended::UnsupportedTopic",
936+
"OptedOut"
937+
]
938+
},
901939
"joystreamChannelId": {
902940
"type": "number"
903941
},
@@ -930,6 +968,7 @@
930968
"description",
931969
"shouldBeIngested",
932970
"yppStatus",
971+
"preOptOutStatus",
933972
"joystreamChannelId",
934973
"referrerChannelId",
935974
"videoCategoryId",

src/services/httpApi/controllers/channels.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,19 @@ export class ChannelsController {
152152
}
153153
}
154154

155+
@Get("/unverified")
156+
@ApiResponse({ type: ChannelDto })
157+
@ApiOperation({ description: 'Retrieves channels waiting for verification' })
158+
async getUnverifiedChannels() {
159+
try {
160+
const channels = await this.dynamodbService.channels.getUnverified()
161+
return channels.map((channel) => new ChannelDto(channel))
162+
} catch (error) {
163+
const message = error instanceof Error ? error.message : error
164+
throw new ServiceUnavailableException(message)
165+
}
166+
}
167+
155168
@Get(':joystreamChannelId')
156169
@ApiResponse({ type: ChannelDto })
157170
@ApiOperation({ description: 'Retrieves channel by joystreamChannelId' })

0 commit comments

Comments
 (0)