1
0
Fork 0
mirror of https://codeberg.org/demostf/api.git synced 2026-06-03 18:04:08 +02:00

ordering for profile and uploads

This commit is contained in:
Robin Appelman 2020-12-09 23:39:17 +01:00
commit 750de60257
2 changed files with 8 additions and 6 deletions

View file

@ -120,12 +120,14 @@ class DemoController extends BaseController {
$page = (int) $this->query('page', '1');
$where = $this->getFilter();
$where['players'][] = $steamId;
$this->json($this->demoListProvider->listProfile((int) $page, $where));
$order = 'ASC' === $this->query('order', 'DESC') ? 'ASC' : 'DESC';
$this->json($this->demoListProvider->listProfile((int) $page, $where, $order));
}
public function listUploads(string $steamId): void {
$page = (int) $this->query('page', '1');
$this->json($this->demoListProvider->listUploads($steamId, (int) $page, $this->getFilter()));
$order = 'ASC' === $this->query('order', 'DESC') ? 'ASC' : 'DESC';
$this->json($this->demoListProvider->listUploads($steamId, (int) $page, $this->getFilter(), $order));
}
public function chat(string $demoId): void {

View file

@ -17,7 +17,7 @@ class DemoListProvider extends BaseProvider {
*
* @return Demo[]
*/
public function listUploads(string $steamId, int $page, array $where = []) {
public function listUploads(string $steamId, int $page, array $where = [], string $order = 'DESC') {
$query = $this->getQueryBuilder();
$query->select('id')
->from('users')
@ -29,7 +29,7 @@ class DemoListProvider extends BaseProvider {
$where['uploader'] = $userId;
return $this->listDemos($page, $where);
return $this->listDemos($page, $where, $order);
}
/**
@ -39,7 +39,7 @@ class DemoListProvider extends BaseProvider {
*
* @return Demo[]
*/
public function listProfile(int $page, array $where = []): array {
public function listProfile(int $page, array $where = [], string $order = 'DESC'): array {
$query = $this->getQueryBuilder();
$query->select('id')
->from('users')
@ -66,7 +66,7 @@ class DemoListProvider extends BaseProvider {
$query->where($query->expr()->eq('user_id',
$query->createNamedParameter($userIds[0], PDO::PARAM_INT)));
}
$query->orderBy('demo_id', 'desc')
$query->orderBy('demo_id', $order)
->setMaxResults(50)
->setFirstResult(((int) $page - 1) * 50);