Skip to content
关注公众号,获取新课通知

我的收藏列表


控制器:app/controller/fava.js

js
	// 我的收藏列表
    async list() {
        const { ctx, app } = this;
        let currentUser = ctx.authUser;

        ctx.validate({
            page: {
                required: true,
                desc: "页码",
                type: "int"
            },
            user_id: {
                required: true,
                desc: "用户id",
                type: "int"
            }
        });

        let user_id = ctx.query.user_id;

        let rows = await ctx.page(app.model.Fava, {
            user_id
        }, {
            include: [{
                model: app.model.Video,
            }]
        });

        rows = rows.map(item => {
            return {
                created_time: item.video.created_time,
                id: item.video.id,
                title: item.video.title,
                cover: item.video.cover,
                category_id: item.video.category_id,
                user_id: item.video.user_id,
                duration: item.video.duration,
                desc: item.video.desc,
                play_count: item.video.play_count,
                danmu_count: item.video.danmu_count,
                updated_time: item.video.updated_time,
            }
        });

        ctx.apiSuccess(rows);
    }

路由:app/router.js

js
// 收藏列表
router.get("/fava_list/:page", controller.fava.list);