From 17d62b689df22af66486cb50e9de82d745b129ce Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 29 Nov 2020 12:34:39 +0900 Subject: [PATCH] wip --- src/client/pages/user/clips.vue | 57 +++++++++++++++++++++++++ src/client/pages/user/index.vue | 20 +++++++-- src/client/pages/user/pages.vue | 56 ++++++++++++++++++++++++ src/models/repositories/clip.ts | 6 +++ src/server/api/endpoints/users/clips.ts | 40 +++++++++++++++++ src/server/api/endpoints/users/pages.ts | 40 +++++++++++++++++ 6 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 src/client/pages/user/clips.vue create mode 100644 src/client/pages/user/pages.vue create mode 100644 src/server/api/endpoints/users/clips.ts create mode 100644 src/server/api/endpoints/users/pages.ts diff --git a/src/client/pages/user/clips.vue b/src/client/pages/user/clips.vue new file mode 100644 index 0000000000..2a66b6752d --- /dev/null +++ b/src/client/pages/user/clips.vue @@ -0,0 +1,57 @@ + + + + + diff --git a/src/client/pages/user/index.vue b/src/client/pages/user/index.vue index 0c816a2d22..70f6662604 100644 --- a/src/client/pages/user/index.vue +++ b/src/client/pages/user/index.vue @@ -60,12 +60,15 @@
@@ -193,8 +198,8 @@ + + diff --git a/src/models/repositories/clip.ts b/src/models/repositories/clip.ts index 2830546528..11f743349f 100644 --- a/src/models/repositories/clip.ts +++ b/src/models/repositories/clip.ts @@ -24,6 +24,12 @@ export class ClipRepository extends Repository { isPublic: clip.isPublic, }); } + + public packMany( + clips: Clip[], + ) { + return Promise.all(clips.map(x => this.pack(x))); + } } export const packedClipSchema = { diff --git a/src/server/api/endpoints/users/clips.ts b/src/server/api/endpoints/users/clips.ts new file mode 100644 index 0000000000..72aae7252c --- /dev/null +++ b/src/server/api/endpoints/users/clips.ts @@ -0,0 +1,40 @@ +import $ from 'cafy'; +import { ID } from '../../../../misc/cafy-id'; +import define from '../../define'; +import { Clips } from '../../../../models'; +import { makePaginationQuery } from '../../common/make-pagination-query'; + +export const meta = { + tags: ['users', 'clips'], + + params: { + userId: { + validator: $.type(ID), + }, + + limit: { + validator: $.optional.num.range(1, 100), + default: 10 + }, + + sinceId: { + validator: $.optional.type(ID), + }, + + untilId: { + validator: $.optional.type(ID), + }, + } +}; + +export default define(meta, async (ps, user) => { + const query = makePaginationQuery(Clips.createQueryBuilder('clip'), ps.sinceId, ps.untilId) + .andWhere(`clip.userId = :userId`, { userId: ps.userId }) + .andWhere('clip.isPublic = true'); + + const clips = await query + .take(ps.limit!) + .getMany(); + + return await Clips.packMany(clips); +}); diff --git a/src/server/api/endpoints/users/pages.ts b/src/server/api/endpoints/users/pages.ts new file mode 100644 index 0000000000..706a2e115b --- /dev/null +++ b/src/server/api/endpoints/users/pages.ts @@ -0,0 +1,40 @@ +import $ from 'cafy'; +import { ID } from '../../../../misc/cafy-id'; +import define from '../../define'; +import { Pages } from '../../../../models'; +import { makePaginationQuery } from '../../common/make-pagination-query'; + +export const meta = { + tags: ['users', 'pages'], + + params: { + userId: { + validator: $.type(ID), + }, + + limit: { + validator: $.optional.num.range(1, 100), + default: 10 + }, + + sinceId: { + validator: $.optional.type(ID), + }, + + untilId: { + validator: $.optional.type(ID), + }, + } +}; + +export default define(meta, async (ps, user) => { + const query = makePaginationQuery(Pages.createQueryBuilder('page'), ps.sinceId, ps.untilId) + .andWhere(`page.userId = :userId`, { userId: ps.userId }) + .andWhere('page.visibility = \'public\''); + + const pages = await query + .take(ps.limit!) + .getMany(); + + return await Pages.packMany(pages); +});