Add favorites API
parent
ba2c3ecdd0
commit
1d16da7235
|
@ -59,8 +59,22 @@ class ApiController extends Controller {
|
|||
$this->config = $config;
|
||||
$this->userSession = $userSession;
|
||||
$this->connection = $connection;
|
||||
$this->timelineQuery = new TimelineQuery($this->connection);
|
||||
$this->rootFolder = $rootFolder;
|
||||
$this->timelineQuery = new TimelineQuery($this->connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get transformations depending on the request
|
||||
*/
|
||||
private function getTransformations() {
|
||||
$transforms = array();
|
||||
|
||||
// Filter only favorites
|
||||
if ($this->request->getParam('fav')) {
|
||||
$transforms[] = array($this->timelineQuery, 'transformFavoriteFilter');
|
||||
}
|
||||
|
||||
return $transforms;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,7 +88,11 @@ class ApiController extends Controller {
|
|||
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
|
||||
}
|
||||
|
||||
$list = $this->timelineQuery->getDays($this->config, $user->getUID());
|
||||
$list = $this->timelineQuery->getDays(
|
||||
$this->config,
|
||||
$user->getUID(),
|
||||
$this->getTransformations(),
|
||||
);
|
||||
return new JSONResponse($list, Http::STATUS_OK);
|
||||
}
|
||||
|
||||
|
@ -89,7 +107,12 @@ class ApiController extends Controller {
|
|||
return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED);
|
||||
}
|
||||
|
||||
$list = $this->timelineQuery->getDay($this->config, $user->getUID(), intval($id));
|
||||
$list = $this->timelineQuery->getDay(
|
||||
$this->config,
|
||||
$user->getUID(),
|
||||
intval($id),
|
||||
$this->getTransformations(),
|
||||
);
|
||||
return new JSONResponse($list, Http::STATUS_OK);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ use OCP\IDBConnection;
|
|||
class TimelineQuery {
|
||||
use TimelineQueryDays;
|
||||
use TimelineQueryDay;
|
||||
use TimelineQueryFavorites;
|
||||
|
||||
protected IDBConnection $connection;
|
||||
|
||||
|
|
|
@ -56,7 +56,8 @@ trait TimelineQueryDay {
|
|||
public function getDay(
|
||||
IConfig &$config,
|
||||
string $user,
|
||||
int $dayId
|
||||
int $dayId,
|
||||
array $queryTransforms = []
|
||||
): array {
|
||||
// Filter by path starting with timeline path
|
||||
$path = "files" . Exif::getPhotosPath($config, $user) . "%";
|
||||
|
@ -68,6 +69,11 @@ trait TimelineQueryDay {
|
|||
// Filter by UID
|
||||
$query->andWhere($query->expr()->eq('uid', $query->createNamedParameter($user)));
|
||||
|
||||
// Apply all transformations
|
||||
foreach ($queryTransforms as &$transform) {
|
||||
$transform($query);
|
||||
}
|
||||
|
||||
$rows = $query->executeQuery()->fetchAll();
|
||||
return $this->processDay($rows);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,8 @@ trait TimelineQueryDays {
|
|||
*/
|
||||
public function getDays(
|
||||
IConfig &$config,
|
||||
string $user
|
||||
string $user,
|
||||
array $queryTransforms = []
|
||||
): array {
|
||||
|
||||
// Filter by path starting with timeline path
|
||||
|
@ -63,6 +64,11 @@ trait TimelineQueryDays {
|
|||
// Filter by user
|
||||
$query->andWhere($query->expr()->eq('uid', $query->createNamedParameter($user)));
|
||||
|
||||
// Apply all transformations
|
||||
foreach ($queryTransforms as &$transform) {
|
||||
$transform($query);
|
||||
}
|
||||
|
||||
$rows = $query->executeQuery()->fetchAll();
|
||||
return $this->processDays($rows);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\Memories\Db;
|
||||
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
|
||||
trait TimelineQueryFavorites {
|
||||
public function transformFavoriteFilter(IQueryBuilder $query) {
|
||||
$query->innerJoin('m', 'vcategory_to_object', 'c',
|
||||
$query->expr()->andX(
|
||||
$query->expr()->eq('c.objid', 'm.fileid'),
|
||||
$query->expr()->eq('c.categoryid', $query->createNamedParameter(2, IQueryBuilder::PARAM_INT)),
|
||||
$query->expr()->eq('c.type', $query->createNamedParameter('files')),
|
||||
));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue