admin limit
Some checks are pending
Backend CI / test (push) Waiting to run
Backend CI / build (push) Blocked by required conditions
Deploy Admin Panel / Deploy Admin Panel (push) Waiting to run
Deploy Admin Panel / Admin Panel Verification (push) Blocked by required conditions
Deploy Mnemo Cards / Deploy Backend (push) Waiting to run
Deploy Mnemo Cards / Deploy Web App (push) Blocked by required conditions
Deploy Mnemo Cards / Final Verification (push) Blocked by required conditions

This commit is contained in:
Dmitry 2025-12-15 01:24:24 +03:00
parent 48cd5ca836
commit aec56c2fd8
4 changed files with 21 additions and 40 deletions

View file

@ -31,8 +31,8 @@ export function PackCardsManager({
// Load all cards with search
const { data: cardsData, isLoading } = useQuery({
queryKey: ['cards', 1, 1000, search], // Large limit to get all cards
queryFn: () => cardsApi.getCards({ page: 1, limit: 1000, search }),
queryKey: ['cards', 1, 100, search], // Limit to 100 (backend max)
queryFn: () => cardsApi.getCards({ page: 1, limit: 100, search }),
enabled: !disabled,
})

View file

@ -58,17 +58,8 @@ class AdminCardsApiV2 {
headers: {'Content-Type': 'application/json'},
);
}
if (limit < 1 || limit > 100) {
return Response.badRequest(
body: json.encode({
'error': 'Invalid limit parameter',
'message': 'Limit must be between 1 and 100. Received: $limit',
'field': 'limit',
'details': 'The maximum number of items per page is 100. Please use a value between 1 and 100.',
}),
headers: {'Content-Type': 'application/json'},
);
}
// Limit validation: if limit is invalid, set to default; if > 100, cap at 100
final validatedLimit = limit < 1 ? 20 : (limit > 100 ? 100 : limit);
// Get all cards
final allCards = await _db.packDao.getAllCards();
@ -87,9 +78,9 @@ class AdminCardsApiV2 {
// Calculate pagination
final total = filteredCards.length;
final totalPages = (total / limit).ceil();
final offset = (page - 1) * limit;
final paginatedCards = filteredCards.skip(offset).take(limit).toList();
final totalPages = (total / validatedLimit).ceil();
final offset = (page - 1) * validatedLimit;
final paginatedCards = filteredCards.skip(offset).take(validatedLimit).toList();
// Получить паки для всех карточек (для packId)
final cardsWithPacks = <Map<String, dynamic>>[];
@ -116,7 +107,7 @@ class AdminCardsApiV2 {
'items': cardsWithPacks,
'total': total,
'page': page,
'limit': limit,
'limit': validatedLimit,
'totalPages': totalPages,
}),
headers: {'Content-Type': 'application/json'},

View file

@ -76,17 +76,8 @@ class AdminPacksApiV2 {
statusCode: 400,
);
}
if (limit < 1 || limit > 100) {
return _json(
{
'error': 'Invalid limit parameter',
'message': 'Limit must be between 1 and 100. Received: $limit',
'field': 'limit',
'details': 'The maximum number of items per page is 100. Please use a value between 1 and 100.',
},
statusCode: 400,
);
}
// Limit validation: if limit is invalid, set to default; if > 100, cap at 100
final validatedLimit = limit < 1 ? 20 : (limit > 100 ? 100 : limit);
// Get all packs
final allPacks = await _db.packDao.getAllPacks(
@ -124,15 +115,15 @@ class AdminPacksApiV2 {
// Calculate pagination
final total = previewDtos.length;
final totalPages = (total / limit).ceil();
final offset = (page - 1) * limit;
final paginatedPacks = previewDtos.skip(offset).take(limit).toList();
final totalPages = (total / validatedLimit).ceil();
final offset = (page - 1) * validatedLimit;
final paginatedPacks = previewDtos.skip(offset).take(validatedLimit).toList();
return _json({
'items': paginatedPacks,
'total': total,
'page': page,
'limit': limit,
'limit': validatedLimit,
'totalPages': totalPages,
});
} catch (e, s) {

View file

@ -170,9 +170,8 @@ class TestsApiV2 {
if (page < 1) {
return _badRequest('Page must be greater than 0');
}
if (limit < 1 || limit > 100) {
return _badRequest('Limit must be between 1 and 100');
}
// Limit validation: if limit is invalid, set to default; if > 100, cap at 100
final validatedLimit = limit < 1 ? 20 : (limit > 100 ? 100 : limit);
if (user.id == null) {
return _unauthorized('User ID is required');
@ -186,7 +185,7 @@ class TestsApiV2 {
'items': [],
'total': 0,
'page': page,
'limit': limit,
'limit': validatedLimit,
'totalPages': 0,
});
}
@ -213,15 +212,15 @@ class TestsApiV2 {
// Apply pagination
final total = attempts.length;
final totalPages = (total / limit).ceil();
final offset = (page - 1) * limit;
final paginatedAttempts = attempts.skip(offset).take(limit).toList();
final totalPages = (total / validatedLimit).ceil();
final offset = (page - 1) * validatedLimit;
final paginatedAttempts = attempts.skip(offset).take(validatedLimit).toList();
return _ok({
'items': paginatedAttempts,
'total': total,
'page': page,
'limit': limit,
'limit': validatedLimit,
'totalPages': totalPages,
});
} catch (e, s) {