mirror of
https://github.com/samanhappy/mcphub.git
synced 2026-01-04 21:58:42 -05:00
feat: implement pagination for server list with customizable items pe… (#534)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ServerDao, ServerConfigWithName } from './index.js';
|
||||
import { ServerDao, ServerConfigWithName, PaginatedResult } from './index.js';
|
||||
import { ServerRepository } from '../db/repositories/ServerRepository.js';
|
||||
|
||||
/**
|
||||
@@ -16,6 +16,32 @@ export class ServerDaoDbImpl implements ServerDao {
|
||||
return servers.map((s) => this.mapToServerConfig(s));
|
||||
}
|
||||
|
||||
async findAllPaginated(page: number, limit: number): Promise<PaginatedResult<ServerConfigWithName>> {
|
||||
const { data, total } = await this.repository.findAllPaginated(page, limit);
|
||||
const totalPages = Math.ceil(total / limit);
|
||||
|
||||
return {
|
||||
data: data.map((s) => this.mapToServerConfig(s)),
|
||||
total,
|
||||
page,
|
||||
limit,
|
||||
totalPages,
|
||||
};
|
||||
}
|
||||
|
||||
async findByOwnerPaginated(owner: string, page: number, limit: number): Promise<PaginatedResult<ServerConfigWithName>> {
|
||||
const { data, total } = await this.repository.findByOwnerPaginated(owner, page, limit);
|
||||
const totalPages = Math.ceil(total / limit);
|
||||
|
||||
return {
|
||||
data: data.map((s) => this.mapToServerConfig(s)),
|
||||
total,
|
||||
page,
|
||||
limit,
|
||||
totalPages,
|
||||
};
|
||||
}
|
||||
|
||||
async findById(name: string): Promise<ServerConfigWithName | null> {
|
||||
const server = await this.repository.findByName(name);
|
||||
return server ? this.mapToServerConfig(server) : null;
|
||||
|
||||
Reference in New Issue
Block a user