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 // Load all cards with search
const { data: cardsData, isLoading } = useQuery({ const { data: cardsData, isLoading } = useQuery({
queryKey: ['cards', 1, 1000, search], // Large limit to get all cards queryKey: ['cards', 1, 100, search], // Limit to 100 (backend max)
queryFn: () => cardsApi.getCards({ page: 1, limit: 1000, search }), queryFn: () => cardsApi.getCards({ page: 1, limit: 100, search }),
enabled: !disabled, enabled: !disabled,
}) })

View file

@ -58,17 +58,8 @@ class AdminCardsApiV2 {
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
); );
} }
if (limit < 1 || limit > 100) { // Limit validation: if limit is invalid, set to default; if > 100, cap at 100
return Response.badRequest( final validatedLimit = limit < 1 ? 20 : (limit > 100 ? 100 : limit);
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'},
);
}
// Get all cards // Get all cards
final allCards = await _db.packDao.getAllCards(); final allCards = await _db.packDao.getAllCards();
@ -87,9 +78,9 @@ class AdminCardsApiV2 {
// Calculate pagination // Calculate pagination
final total = filteredCards.length; final total = filteredCards.length;
final totalPages = (total / limit).ceil(); final totalPages = (total / validatedLimit).ceil();
final offset = (page - 1) * limit; final offset = (page - 1) * validatedLimit;
final paginatedCards = filteredCards.skip(offset).take(limit).toList(); final paginatedCards = filteredCards.skip(offset).take(validatedLimit).toList();
// Получить паки для всех карточек (для packId) // Получить паки для всех карточек (для packId)
final cardsWithPacks = <Map<String, dynamic>>[]; final cardsWithPacks = <Map<String, dynamic>>[];
@ -116,7 +107,7 @@ class AdminCardsApiV2 {
'items': cardsWithPacks, 'items': cardsWithPacks,
'total': total, 'total': total,
'page': page, 'page': page,
'limit': limit, 'limit': validatedLimit,
'totalPages': totalPages, 'totalPages': totalPages,
}), }),
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},

View file

@ -76,17 +76,8 @@ class AdminPacksApiV2 {
statusCode: 400, statusCode: 400,
); );
} }
if (limit < 1 || limit > 100) { // Limit validation: if limit is invalid, set to default; if > 100, cap at 100
return _json( final validatedLimit = limit < 1 ? 20 : (limit > 100 ? 100 : limit);
{
'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,
);
}
// Get all packs // Get all packs
final allPacks = await _db.packDao.getAllPacks( final allPacks = await _db.packDao.getAllPacks(
@ -124,15 +115,15 @@ class AdminPacksApiV2 {
// Calculate pagination // Calculate pagination
final total = previewDtos.length; final total = previewDtos.length;
final totalPages = (total / limit).ceil(); final totalPages = (total / validatedLimit).ceil();
final offset = (page - 1) * limit; final offset = (page - 1) * validatedLimit;
final paginatedPacks = previewDtos.skip(offset).take(limit).toList(); final paginatedPacks = previewDtos.skip(offset).take(validatedLimit).toList();
return _json({ return _json({
'items': paginatedPacks, 'items': paginatedPacks,
'total': total, 'total': total,
'page': page, 'page': page,
'limit': limit, 'limit': validatedLimit,
'totalPages': totalPages, 'totalPages': totalPages,
}); });
} catch (e, s) { } catch (e, s) {

View file

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