ページネーションクエリに対応

This commit is contained in:
kakkokari-gtyih 2023-11-11 16:42:12 +09:00
parent 0a29c8de90
commit 9bc6d8024f
1 changed files with 13 additions and 1 deletions

View File

@ -9,6 +9,7 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import type { ScheduledNotesRepository } from '@/models/_.js'; import type { ScheduledNotesRepository } from '@/models/_.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js'; import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { QueryService } from '@/core/QueryService.js';
export const meta = { export const meta = {
tags: ['notes'], tags: ['notes'],
@ -57,6 +58,12 @@ export const meta = {
} as const; } as const;
export const paramDef = { export const paramDef = {
type: 'object',
properties: {
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
},
} as const; } as const;
@Injectable() @Injectable()
@ -64,10 +71,15 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
constructor( constructor(
@Inject(DI.scheduledNotesRepository) @Inject(DI.scheduledNotesRepository)
private scheduledNotesRepository: ScheduledNotesRepository, private scheduledNotesRepository: ScheduledNotesRepository,
private userEntityService: UserEntityService, private userEntityService: UserEntityService,
private queryService: QueryService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(meta, paramDef, async (ps, me) => {
const scheduleNotes = await this.scheduledNotesRepository.findBy({ userId: me.id }); const query = this.queryService.makePaginationQuery(this.scheduledNotesRepository.createQueryBuilder('note'), ps.sinceId, ps.untilId)
.andWhere('note.userId = :userId', { userId: me.id });
const scheduleNotes = await query.limit(ps.limit).getMany();
const user = await this.userEntityService.pack(me, me); const user = await this.userEntityService.pack(me, me);
const scheduleNotesPack: { const scheduleNotesPack: {
id: string; id: string;