Skip to content

Commit 804ade0

Browse files
committed
fix: add shuffle query endpoint for retrieving channel items by season
1 parent e543336 commit 804ade0

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/controllers/item.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ const getManyByChannelBySeasonQuerySchema = Joi.object({
8383
page: Joi.number().integer().min(1).required()
8484
});
8585

86+
const getManyByChannelBySeasonShuffleQuerySchema = Joi.object({
87+
page: Joi.number().integer().min(1).required(),
88+
shuffleHash: Joi.string().required()
89+
});
90+
8691
const getManyByChannelTopQuerySchema = Joi.object({
8792
range: Joi.string().valid(...QUERY_PARAMS_STATS_RANGE_VALUES).required(),
8893
page: Joi.number().integer().min(1).required()
@@ -566,6 +571,38 @@ export class ItemController {
566571
});
567572
}
568573

574+
static async getManyByChannelBySeasonShuffle(req: Request, res: Response): Promise<void> {
575+
validateParamsObject(getManyByChannelParmsSchema, req, res, async () => {
576+
validateQueryObject(getManyByChannelBySeasonShuffleQuerySchema, req, res, async () => {
577+
try {
578+
const { page, limit, offset } = getPaginationParams(req);
579+
const { channelIdOrIdText } = req.params;
580+
const { shuffleHash } = req.query as { shuffleHash: string };
581+
582+
const channel = await ItemController.channelService.getByIdOrIdText(
583+
channelIdOrIdText,
584+
{ channel_about: true }
585+
);
586+
587+
if (!channel) {
588+
res.status(404).json({ message: 'Channel not found' });
589+
return;
590+
}
591+
592+
const config: FindManyOptions<Item> = {
593+
skip: offset,
594+
take: limit
595+
};
596+
const items = await ItemController.itemService.getManyByChannelBySeason(channel, "shuffle", config, shuffleHash);
597+
598+
res.json({ data: items, meta: { page, count: channel.channel_about.episode_count, limit } });
599+
} catch (error) {
600+
handleGenericErrorResponse(res, error);
601+
}
602+
});
603+
});
604+
}
605+
569606
static async getManyForQueueByPubDate(req: Request, res: Response): Promise<void> {
570607
validateParamsObject(getManyForQueueByPubDateParamsSchema, req, res, async () => {
571608
validateQueryObject(getManyForQueueByPubDateQuerySchema, req, res, async () => {

src/routes/item.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ router.get('/chapters/:item_id_text', asyncHandler(ItemController.parseAndGetCha
1111

1212
router.get('/channel/season/forward/:channelIdOrIdText', asyncHandler(ItemController.getManyByChannelBySeasonForward));
1313
router.get('/channel/season/backward/:channelIdOrIdText', asyncHandler(ItemController.getManyByChannelBySeasonBackward));
14+
router.get('/channel/season/shuffle/:channelIdOrIdText', asyncHandler(ItemController.getManyByChannelBySeasonShuffle));
1415

1516
router.get('/channel/recent/:channelIdOrIdText', asyncHandler(ItemController.getManyByChannelRecent));
1617
router.get('/channel/oldest/:channelIdOrIdText', asyncHandler(ItemController.getManyByChannelOldest));

0 commit comments

Comments
 (0)