Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
$builder->scope('/api', function (RouteBuilder $builder): void {
$builder->get('/leaderboard', ['prefix' => 'Api', 'controller' => 'LeaderBoard', 'action' => 'get']);

$builder->get('/potatoes', ['prefix' => 'Api', 'controller' => 'Potatoes', 'action' => 'list']);

$builder->get('/users', ['prefix' => 'Api', 'controller' => 'Users', 'action' => 'list']);
$builder->get('/user', ['prefix' => 'Api', 'controller' => 'Users', 'action' => 'get']);
$builder->patch('/user', ['prefix' => 'Api', 'controller' => 'Users', 'action' => 'edit']);
Expand Down
50 changes: 50 additions & 0 deletions src/Controller/Api/PotatoesController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);

namespace App\Controller\Api;

use Cake\Http\Response;

/**
* @property \Authentication\Controller\Component\AuthenticationComponent $Authentication
*/
class PotatoesController extends ApiController
{
/**
* @return \Cake\Http\Response
*/
public function list(): Response
{
$messagesTable = $this->fetchTable('Messages');

$sent = $messagesTable->find()
->select([
'amount' => 'Messages.amount',
'recipient' => 'Messages.receiver_user_id',
'created' => 'Messages.created',
])
->where(['Messages.sender_user_id' => $this->Authentication->getIdentity()->getIdentifier()])
->orderBy(['Messages.created' => 'DESC'])
->disableHydration()
->all();

$received = $messagesTable->find()
->select([
'amount' => 'Messages.amount',
'sender' => 'Messages.sender_user_id',
'created' => 'Messages.created',
])
->where(['Messages.receiver_user_id' => $this->Authentication->getIdentity()->getIdentifier()])
->orderBy(['Messages.created' => 'DESC'])
->disableHydration()
->all();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing promised history pagination

Medium Severity

The PR describes /api/potatoes as paginated potato history, but list loads every matching sent and received row with no limit, page parameter, or paging metadata. For long-lived accounts that can mean two full unbounded result sets in one response, which undercuts the export/dashboard use case and risks slow or heavy replies as history grows.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 6191785. Configure here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

broken promises


return $this->response
->withStatus(200)
->withType('json')
->withStringBody(json_encode([
'sent' => $sent,
'received' => $received,
]));
}
}
Loading