Skip to content
Snippets Groups Projects
Commit fc6efddb authored by Angela Livia Arumsari's avatar Angela Livia Arumsari
Browse files

feat: add initial sync in search and filter

parent 0ad5349f
1 merge request!2endpoint for polling and get image file, fix search issue, modify db
......@@ -98,6 +98,7 @@ abstract class BaseRepository
$pageNo = null,
$pageSize = null,
$sort = "asc",
$isInitialSync = "no"
) {
$sql = "SELECT * FROM $this->tableName";
......@@ -124,6 +125,21 @@ abstract class BaseRepository
$sql .= " WHERE " . implode(" AND ", $conditions);
}
if ($isInitialSync == "no") {
$pollingDurationMinutes = intval(getenv('POLLING_DURATION_MINUTES'));
$pollingSql = "";
if (count($where) == 0) {
$pollingSql .= " WHERE ";
}
if ($pollingDurationMinutes !== false && is_numeric($pollingDurationMinutes) && $pollingDurationMinutes) {
$pollingSql .= "last_updated >= DATE_SUB(NOW(), INTERVAL $pollingDurationMinutes MINUTE)";
} else {
$pollingSql .= "last_updated >= DATE_SUB(NOW(), INTERVAL 30 MINUTE)";
}
$sql .= $pollingSql;
}
if ($order) {
$sql .= " ORDER BY $order";
}
......
......@@ -36,7 +36,8 @@ class FilmRepository extends BaseRepository
$genre = 'all',
$released_year = 'all',
$pageNo = 1,
$limit = 10
$limit = 10,
$isInitialSync = "no"
) {
$where = [];
......@@ -47,10 +48,13 @@ class FilmRepository extends BaseRepository
$where['released_year'] = [$released_year, PDO::PARAM_INT];
}
if (isset($word) and !empty($word)) {
$where['title'] = [$genre, PDO::PARAM_STR, 'LIKE', ['director']];
$where['title'] = [$word, PDO::PARAM_STR, 'LIKE', ['director']];
}
return $this->findAll($where, $order, $pageNo, $limit, $isDesc);
$data = $this->findAll($where, $order, $pageNo, $limit, $isDesc, $isInitialSync);
error_log(count($data));
return $this->findAll($where, $order, $pageNo, $limit, $isDesc, $isInitialSync);
}
public function countRowBySearchAndFilter($word, $genre = 'all', $released_year = 'all')
......@@ -64,7 +68,7 @@ class FilmRepository extends BaseRepository
$where['released_year'] = [$released_year, PDO::PARAM_INT];
}
if (isset($word) and !empty($word)) {
$where['title'] = [$genre, PDO::PARAM_STR, 'LIKE', ['director']];
$where['title'] = [$word, PDO::PARAM_STR, 'LIKE', ['director']];
}
return $this->countRow($where);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment