M changelog.md => changelog.md +6 -0
@@ 1,5 1,11 @@
# MuditaOS changelog
+## Current release
+
+### Changed
+
+* `[calendar]` Rework to use database model instead of internal model in day events list.
+
## [0.44.1 2020-10-30]
### Added
M module-apps/application-calendar/ApplicationCalendar.cpp => module-apps/application-calendar/ApplicationCalendar.cpp +3 -2
@@ 159,9 159,10 @@ namespace app
{
if (equivalentWindow == EquivalentWindow::DayEventsWindow) {
popToWindow(gui::name::window::main_window);
- return;
}
-
+ if (equivalentWindow == EquivalentWindow::AllEventsWindow) {
+ popToWindow(gui::name::window::main_window);
+ }
gui::DialogMetadata meta;
meta.text = utils::localize.get("app_calendar_no_events_information");
meta.title = title;
M module-apps/application-calendar/CMakeLists.txt => module-apps/application-calendar/CMakeLists.txt +1 -1
@@ 17,7 17,7 @@ target_sources( ${PROJECT_NAME}
"${CMAKE_CURRENT_LIST_DIR}/windows/EventReminderWindow.cpp"
"${CMAKE_CURRENT_LIST_DIR}/models/CustomRepeatModel.cpp"
"${CMAKE_CURRENT_LIST_DIR}/models/NewEditEventModel.cpp"
- "${CMAKE_CURRENT_LIST_DIR}/models/DayEventsInternalModel.cpp"
+ "${CMAKE_CURRENT_LIST_DIR}/models/DayEventsModel.cpp"
"${CMAKE_CURRENT_LIST_DIR}/widgets/DayEventsItem.cpp"
"${CMAKE_CURRENT_LIST_DIR}/widgets/AllEventsItem.cpp"
"${CMAKE_CURRENT_LIST_DIR}/widgets/CalendarListView.cpp"
D module-apps/application-calendar/models/DayEventsInternalModel.cpp => module-apps/application-calendar/models/DayEventsInternalModel.cpp +0 -72
@@ 1,72 0,0 @@
-// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
-// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
-
-#include "DayEventsInternalModel.hpp"
-#include "application-calendar/widgets/DayEventsItem.hpp"
-#include "application-calendar/data/CalendarData.hpp"
-#include "module-apps/application-calendar/ApplicationCalendar.hpp"
-#include <ListView.hpp>
-#include <algorithm>
-
-DayEventsInternalModel::DayEventsInternalModel(app::Application *app) : application(app)
-{}
-
-unsigned int DayEventsInternalModel::requestRecordsCount()
-{
- return internalData.size();
-}
-
-unsigned int DayEventsInternalModel::getMinimalItemHeight() const
-{
- return style::window::calendar::item::dayEvents::height;
-}
-
-void DayEventsInternalModel::requestRecords(const uint32_t offset, const uint32_t limit)
-{
- setupModel(offset, limit);
- list->onProviderDataUpdate();
-}
-
-gui::ListItem *DayEventsInternalModel::getItem(gui::Order order)
-{
- return getRecord(order);
-}
-
-void DayEventsInternalModel::loadData(std::unique_ptr<std::vector<EventsRecord>> records)
-{
- auto app = dynamic_cast<app::ApplicationCalendar *>(application);
- assert(app != nullptr);
-
- list->clear();
- eraseInternalData();
-
- std::sort(records->begin(), records->end(), [](const EventsRecord &first, const EventsRecord &second) {
- return first.date_from < second.date_from;
- });
-
- auto eventShift = app->getEventShift();
- if (eventShift) {
- for (auto &record : *records) {
- record.date_from += hours(eventShift);
- record.date_till += hours(eventShift);
- }
- }
-
- for (auto &record : *records) {
- auto item = new gui::DayEventsItem();
- item->setEvent(std::make_shared<EventsRecord>(record));
- item->activatedCallback = [=](gui::Item &item) {
- auto rec = std::make_unique<EventsRecord>(record);
- auto data = std::make_unique<EventRecordData>(std::move(rec));
- app->switchWindow(style::window::calendar::name::details_window, std::move(data));
- return true;
- };
- internalData.push_back(item);
- }
-
- for (auto &item : internalData) {
- item->deleteByList = false;
- }
-
- list->rebuildList();
-}
A module-apps/application-calendar/models/DayEventsModel.cpp => module-apps/application-calendar/models/DayEventsModel.cpp +102 -0
@@ 0,0 1,102 @@
+// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
+// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+
+#include "DayEventsModel.hpp"
+#include "application-calendar/widgets/DayEventsItem.hpp"
+#include "application-calendar/data/CalendarData.hpp"
+#include "application-calendar/ApplicationCalendar.hpp"
+#include <ListView.hpp>
+#include <queries/calendar/QueryEventsGetFiltered.hpp>
+#include <module-services/service-db/api/DBServiceAPI.hpp>
+#include <module-services/service-db/messages/QueryMessage.hpp>
+#include <module-db/queries/RecordQuery.hpp>
+
+DayEventsModel::DayEventsModel(app::Application *app) : DatabaseModel(app), application(app)
+{}
+
+unsigned int DayEventsModel::requestRecordsCount()
+{
+ return recordsCount;
+}
+
+unsigned int DayEventsModel::getMinimalItemHeight() const
+{
+ return style::window::calendar::item::dayEvents::height;
+}
+
+void DayEventsModel::requestRecords(const uint32_t offset, const uint32_t limit)
+{
+ auto query = std::make_unique<db::query::events::GetFiltered>(filterFrom, filterTill, offset, limit);
+ query->setQueryListener(
+ db::QueryCallback::fromFunction([this](auto response) { return handleQueryResponse(response); }));
+ DBServiceAPI::GetQuery(application, db::Interface::Name::Events, std::move(query));
+}
+
+gui::ListItem *DayEventsModel::getItem(gui::Order order)
+{
+ auto record = getRecord(order);
+ if (record == nullptr) {
+ LOG_DEBUG("Empty record in DayEventsModel::GetItem");
+ return nullptr;
+ }
+
+ auto *item = new gui::DayEventsItem();
+ item->setEvent(record);
+ item->activatedCallback = [=](gui::Item &item) {
+ LOG_INFO("Switch to event details window");
+ auto rec = std::make_unique<EventsRecord>(*record);
+ auto data = std::make_unique<EventRecordData>(std::move(rec));
+ application->switchWindow(style::window::calendar::name::details_window, std::move(data));
+ return true;
+ };
+
+ return item;
+}
+
+bool DayEventsModel::updateRecords(std::vector<EventsRecord> records)
+{
+ DatabaseModel::updateRecords(std::move(records));
+ list->onProviderDataUpdate();
+ return true;
+}
+
+auto DayEventsModel::handleQueryResponse(db::QueryResult *queryResult) -> bool
+{
+ if (auto response = dynamic_cast<db::query::events::GetFilteredResult *>(queryResult); response != nullptr) {
+ if (recordsCount != (response->getCountResult())) {
+ recordsCount = response->getCountResult();
+ list->rebuildList(style::listview::RebuildType::Full, 0, true);
+ return false;
+ }
+
+ auto records = *response->getResult();
+ if (auto app = dynamic_cast<app::ApplicationCalendar *>(application); app != nullptr) {
+ if (response->getCountResult() == 0) {
+ LOG_DEBUG("Empty records");
+ if (app->getEquivalentToEmptyWindow() == EquivalentWindow::DayEventsWindow) {
+ app->switchToNoEventsWindow(dayMonthTitle, filterFrom);
+ return true;
+ }
+ }
+ auto eventShift = app->getEventShift();
+ if (eventShift) {
+ for (auto &record : records) {
+ record.date_from += hours(eventShift);
+ record.date_till += hours(eventShift);
+ }
+ }
+ return updateRecords(std::move(records));
+ }
+ LOG_ERROR("App is not a calendar");
+ return false;
+ }
+ LOG_ERROR("GetFilteredResult response is nullptr");
+ return false;
+}
+
+void DayEventsModel::setFilters(TimePoint from, TimePoint till, const std::string &dayMonth)
+{
+ this->filterFrom = from;
+ this->filterTill = till;
+ this->dayMonthTitle = dayMonth;
+}
R module-apps/application-calendar/models/DayEventsInternalModel.hpp => module-apps/application-calendar/models/DayEventsModel.hpp +10 -4
@@ 4,19 4,25 @@
#pragma once
#include "Application.hpp"
#include "application-calendar/widgets/CalendarStyle.hpp"
-#include "InternalModel.hpp"
+#include "DatabaseModel.hpp"
#include <ListItem.hpp>
#include <ListItemProvider.hpp>
#include <module-db/Interface/EventsRecord.hpp>
-class DayEventsInternalModel : public app::InternalModel<gui::ListItem *>, public gui::ListItemProvider
+class DayEventsModel : public app::DatabaseModel<EventsRecord>, public gui::ListItemProvider
{
app::Application *application = nullptr;
+ std::string dayMonthTitle;
+ TimePoint filterFrom = TIME_POINT_INVALID;
+ TimePoint filterTill = TIME_POINT_INVALID;
public:
- DayEventsInternalModel(app::Application *app);
+ DayEventsModel(app::Application *app);
- void loadData(std::unique_ptr<std::vector<EventsRecord>> records);
+ void setFilters(TimePoint from, TimePoint till, const std::string &dayMonth);
+
+ bool updateRecords(std::vector<EventsRecord> records) override;
+ auto handleQueryResponse(db::QueryResult *) -> bool;
[[nodiscard]] unsigned int getMinimalItemHeight() const override;
[[nodiscard]] unsigned int requestRecordsCount() override;
M module-apps/application-calendar/models/NewEditEventModel.cpp => module-apps/application-calendar/models/NewEditEventModel.cpp +2 -2
@@ 203,11 203,11 @@ void NewEditEventModel::saveData(std::shared_ptr<EventsRecord> event, bool edit)
assert(app != nullptr);
if (app->getEquivalentToEmptyWindow() == EquivalentWindow::DayEventsWindow) {
app->popToWindow(gui::name::window::main_window);
- app->switchWindow(style::window::calendar::name::day_events_window);
+ app->switchWindow(style::window::calendar::name::day_events_window, std::move(data));
}
else if (app->getEquivalentToEmptyWindow() == EquivalentWindow::AllEventsWindow) {
app->popToWindow(gui::name::window::main_window);
- app->switchWindow(style::window::calendar::name::all_events_window);
+ app->switchWindow(style::window::calendar::name::all_events_window, std::move(data));
}
}
else {
M module-apps/application-calendar/widgets/DayLabel.cpp => module-apps/application-calendar/widgets/DayLabel.cpp +4 -28
@@ 7,8 7,6 @@
#include "application-calendar/widgets/MonthBox.hpp"
#include "application-calendar/data/CalendarData.hpp"
#include <time/time_conversion.hpp>
-#include <module-db/queries/calendar/QueryEventsGetFiltered.hpp>
-#include <module-services/service-db/api/DBServiceAPI.hpp>
namespace gui
{
@@ 78,32 76,10 @@ namespace gui
auto filter = TimePointFromYearMonthDay(dateFilter);
data->setData(number + " " + month, filter);
LOG_DEBUG("Switch to DayEventsWindow");
-
- /////
- auto filterTill = filter + std::chrono::hours(style::window::calendar::time::max_hour_24H_mode + 1);
- auto query = std::make_unique<db::query::events::GetFiltered>(filter, filterTill);
- query->setQueryListener(
- db::QueryCallback::fromFunction([app, filter, number, month](db::QueryResult *result) {
- if (const auto response = dynamic_cast<db::query::events::GetFilteredResult *>(result)) {
- std::unique_ptr<std::vector<EventsRecord>> records = response->getResult();
- auto application = dynamic_cast<app::ApplicationCalendar *>(app);
- assert(application != nullptr);
- if (records->empty()) {
- auto name = number + " " + month;
- application->switchToNoEventsWindow(name, filter);
- return true;
- }
- /// aaaand here switch to DauEventsWindow!
- auto message = std::make_unique<DayEventsWindowMessage>();
- message->records = std::move(records);
- app->switchWindow(style::window::calendar::name::day_events_window, std::move(message));
- return true;
- }
- return false;
- }));
- DBServiceAPI::GetQuery(app, db::Interface::Name::Events, std::move(query));
- /////
-
+ if (auto calendarApp = dynamic_cast<app::ApplicationCalendar *>(app); calendarApp != nullptr) {
+ calendarApp->setEquivalentToEmptyWindow(EquivalentWindow::DayEventsWindow);
+ }
+ app->switchWindow(style::window::calendar::name::day_events_window, std::move(data));
return true;
};
this->setPenWidth(style::window::default_border_no_focus_w);
M module-apps/application-calendar/windows/DayEventsWindow.cpp => module-apps/application-calendar/windows/DayEventsWindow.cpp +8 -16
@@ 3,8 3,7 @@
#include "DayEventsWindow.hpp"
#include "application-calendar/data/CalendarData.hpp"
-#include "log/log.hpp"
-#include "module-apps/application-calendar/ApplicationCalendar.hpp"
+#include "application-calendar/ApplicationCalendar.hpp"
#include <gui/widgets/Window.hpp>
#include <gui/widgets/Label.hpp>
#include <gui/widgets/Item.hpp>
@@ 14,7 13,6 @@
#include <time/time_conversion.hpp>
#include <module-services/service-db/messages/QueryMessage.hpp>
#include <module-db/queries/calendar/QueryEventsGetFiltered.hpp>
-#include <module-services/service-db/api/DBServiceAPI.hpp>
#include <module-services/service-db/messages/DBNotificationMessage.hpp>
namespace gui
@@ 22,7 20,7 @@ namespace gui
DayEventsWindow::DayEventsWindow(app::Application *app)
: AppWindow(app, style::window::calendar::name::day_events_window),
- dayEventsModel{std::make_shared<DayEventsInternalModel>(this->application)}
+ dayEventsModel{std::make_shared<DayEventsModel>(this->application)}
{
buildInterface();
}
@@ 33,7 31,9 @@ namespace gui
}
void DayEventsWindow::onBeforeShow(ShowMode mode, SwitchData *data)
{
- setTitle(dayMonthTitle);
+ if (mode == gui::ShowMode::GUI_SHOW_INIT) {
+ dayEventsList->rebuildList();
+ }
}
auto DayEventsWindow::handleSwitchData(SwitchData *data) -> bool
@@ 42,18 42,15 @@ namespace gui
return false;
}
- auto message = dynamic_cast<DayEventsWindowMessage *>(data);
- if (message != nullptr) {
- dayEventsModel->loadData(std::move(message->records));
- }
-
auto *item = dynamic_cast<DayMonthData *>(data);
if (item == nullptr) {
return false;
}
dayMonthTitle = item->getDayMonthText();
- filterFrom = item->getDateFilter();
+ filterFrom = item->getDateFilter();
+ auto filterTill = filterFrom + date::days{1};
+ dayEventsModel->setFilters(filterFrom, filterTill, dayMonthTitle);
LOG_DEBUG("FILTER 1: %s", TimePointToString(filterFrom).c_str());
setTitle(dayMonthTitle);
if (dayMonthTitle == "") {
@@ 113,11 110,6 @@ namespace gui
return false;
}
- auto DayEventsWindow::handleQueryResponse(db::QueryResult *queryResult) -> bool
- {
- LOG_DEBUG("Response False");
- return false;
- }
bool DayEventsWindow::onDatabaseMessage(sys::Message *msgl)
{
auto *msgNotification = dynamic_cast<db::NotificationMessage *>(msgl);
M module-apps/application-calendar/windows/DayEventsWindow.hpp => module-apps/application-calendar/windows/DayEventsWindow.hpp +3 -4
@@ 3,7 3,7 @@
#pragma once
-#include "application-calendar/models/DayEventsInternalModel.hpp"
+#include "application-calendar/models/DayEventsModel.hpp"
#include "application-calendar/widgets/CalendarStyle.hpp"
#include "windows/AppWindow.hpp"
#include "Application.hpp"
@@ 12,7 12,7 @@
#include <ListView.hpp>
#include <gui/widgets/Item.hpp>
#include <gui/widgets/Label.hpp>
-#include <module-apps/application-calendar/data/dateCommon.hpp>
+#include <application-calendar/data/dateCommon.hpp>
namespace gui
{
@@ 23,7 23,7 @@ namespace gui
gui::Image *leftArrowImage = nullptr;
gui::Image *newDayEventImage = nullptr;
gui::ListView *dayEventsList = nullptr;
- std::shared_ptr<DayEventsInternalModel> dayEventsModel = nullptr;
+ std::shared_ptr<DayEventsModel> dayEventsModel = nullptr;
public:
DayEventsWindow(app::Application *app);
@@ 33,7 33,6 @@ namespace gui
void rebuild() override;
void buildInterface() override;
void onBeforeShow(ShowMode mode, SwitchData *data) override;
- auto handleQueryResponse(db::QueryResult *queryResult) -> bool;
};
} /* namespace app */
M module-db/Interface/EventsRecord.cpp => module-db/Interface/EventsRecord.cpp +16 -4
@@ 59,9 59,12 @@ bool EventsRecordInterface::Add(const EventsRecord &rec)
}
}
-std::unique_ptr<std::vector<EventsRecord>> EventsRecordInterface::Select(TimePoint filter_from, TimePoint filter_till)
+std::unique_ptr<std::vector<EventsRecord>> EventsRecordInterface::Select(TimePoint filter_from,
+ TimePoint filter_till,
+ uint32_t offset,
+ uint32_t limit)
{
- auto rows = eventsDb->events.selectByDatePeriod(filter_from, filter_till);
+ auto rows = eventsDb->events.selectByDatePeriod(filter_from, filter_till, offset, limit);
auto records = std::make_unique<std::vector<EventsRecord>>();
@@ 182,6 185,11 @@ uint32_t EventsRecordInterface::GetCount()
return eventsDb->events.count();
}
+uint32_t EventsRecordInterface::GetCountFiltered(TimePoint from, TimePoint till)
+{
+ return eventsDb->events.countFromFilter(from, till);
+}
+
std::unique_ptr<std::vector<EventsRecord>> EventsRecordInterface::SelectFirstUpcoming(TimePoint filter_from,
TimePoint filter_till)
{
@@ 264,8 272,12 @@ std::unique_ptr<db::query::events::GetFilteredResult> EventsRecordInterface::run
{
auto getFilteredQuery = dynamic_cast<db::query::events::GetFiltered *>(query.get());
assert(getFilteredQuery != nullptr);
- auto records = Select(getFilteredQuery->filter_from, getFilteredQuery->filter_till);
- auto response = std::make_unique<db::query::events::GetFilteredResult>(std::move(records));
+ auto records = Select(getFilteredQuery->filter_from,
+ getFilteredQuery->filter_till,
+ getFilteredQuery->offset,
+ getFilteredQuery->limit);
+ auto numberOfEvents = GetCountFiltered(getFilteredQuery->filter_from, getFilteredQuery->filter_till);
+ auto response = std::make_unique<db::query::events::GetFilteredResult>(std::move(records), numberOfEvents);
response->setRequestQuery(query);
return response;
}
M module-db/Interface/EventsRecord.hpp => module-db/Interface/EventsRecord.hpp +5 -1
@@ 75,7 75,11 @@ class EventsRecordInterface : public RecordInterface<EventsRecord, EventsRecordF
bool Update(const EventsRecord &rec) override final;
EventsRecord GetByID(uint32_t id) override final;
uint32_t GetCount() override final;
- std::unique_ptr<std::vector<EventsRecord>> Select(TimePoint filter_from, TimePoint filter_till);
+ uint32_t GetCountFiltered(TimePoint from, TimePoint till);
+ std::unique_ptr<std::vector<EventsRecord>> Select(TimePoint filter_from,
+ TimePoint filter_till,
+ uint32_t offset,
+ uint32_t limit);
std::unique_ptr<std::vector<EventsRecord>> GetLimitOffset(uint32_t offset, uint32_t limit) override final;
std::unique_ptr<std::vector<EventsRecord>> GetLimitOffsetByField(uint32_t offset,
uint32_t limit,
M module-db/Tables/EventsTable.cpp => module-db/Tables/EventsTable.cpp +24 -5
@@ 425,12 425,17 @@ EventsTableRow EventsTable::getById(uint32_t id)
};
}
-std::vector<EventsTableRow> EventsTable::selectByDatePeriod(TimePoint date_filter, TimePoint filter_till)
+std::vector<EventsTableRow> EventsTable::selectByDatePeriod(TimePoint date_filter,
+ TimePoint filter_till,
+ uint32_t offset,
+ uint32_t limit)
{
- auto retQuery =
- db->query("SELECT * FROM events WHERE date_from >= date('%q') AND date_from < date('%q', 'start of day');",
- TimePointToString(date_filter).c_str(),
- TimePointToString(filter_till).c_str());
+ auto retQuery = db->query("SELECT * FROM events WHERE date_from >= date('%q') AND date_from < date('%q', 'start of "
+ "day') ORDER BY datetime(date_from) LIMIT %u OFFSET %u;",
+ TimePointToString(date_filter).c_str(),
+ TimePointToString(filter_till).c_str(),
+ limit,
+ offset);
if ((retQuery == nullptr) || (retQuery->getRowCount() == 0)) {
return std::vector<EventsTableRow>();
@@ 529,6 534,20 @@ uint32_t EventsTable::count()
return (*queryRet)[0].getUInt32();
}
+uint32_t EventsTable::countFromFilter(TimePoint from, TimePoint till)
+{
+ auto queryRet = db->query(
+ "SELECT COUNT(*) FROM events WHERE date_from >= date('%q') AND date_from < date('%q', 'start of day');",
+ TimePointToString(from).c_str(),
+ TimePointToString(till).c_str());
+
+ if (queryRet == nullptr || queryRet->getRowCount() == 0) {
+ return 0;
+ }
+
+ return (*queryRet)[0].getUInt32();
+}
+
uint32_t EventsTable::countByFieldId(const char *field, uint32_t id)
{
assert(0 && "Not implemented");
M module-db/Tables/EventsTable.hpp => module-db/Tables/EventsTable.hpp +5 -1
@@ 44,8 44,12 @@ class EventsTable : public Table<EventsTableRow, EventsTableFields>
bool removeByField(EventsTableFields field, const char *str) override final;
bool update(EventsTableRow entry) override final;
EventsTableRow getById(uint32_t id) override final;
- std::vector<EventsTableRow> selectByDatePeriod(TimePoint filter_from, TimePoint filter_till);
+ std::vector<EventsTableRow> selectByDatePeriod(TimePoint filter_from,
+ TimePoint filter_till,
+ uint32_t offset,
+ uint32_t limit);
uint32_t count() override final;
+ uint32_t countFromFilter(TimePoint from, TimePoint till);
uint32_t countByFieldId(const char *field, uint32_t id) override final;
std::vector<EventsTableRow> getLimitOffset(uint32_t offset, uint32_t limit) override final;
std::vector<EventsTableRow> getLimitOffsetByField(uint32_t offset,
M module-db/queries/calendar/QueryEventsGetFiltered.cpp => module-db/queries/calendar/QueryEventsGetFiltered.cpp +9 -4
@@ 5,8 5,8 @@
namespace db::query::events
{
- GetFiltered::GetFiltered(TimePoint filter_from, TimePoint filter_till)
- : Query(Query::Type::Read), filter_from(filter_from), filter_till(filter_till)
+ GetFiltered::GetFiltered(TimePoint filter_from, TimePoint filter_till, uint32_t offset, uint32_t limit)
+ : Query(Query::Type::Read), filter_from(filter_from), filter_till(filter_till), offset(offset), limit(limit)
{}
auto GetFiltered::debugInfo() const -> std::string
@@ 14,8 14,8 @@ namespace db::query::events
return "GetFiltered";
}
- GetFilteredResult::GetFilteredResult(std::unique_ptr<std::vector<EventsRecord>> records)
- : records(std::move(records))
+ GetFilteredResult::GetFilteredResult(std::unique_ptr<std::vector<EventsRecord>> records, uint32_t count)
+ : records(std::move(records)), recordsCount(count)
{}
auto GetFilteredResult::getResult() -> std::unique_ptr<std::vector<EventsRecord>>
@@ 23,6 23,11 @@ namespace db::query::events
return std::move(records);
}
+ auto GetFilteredResult::getCountResult() -> uint32_t
+ {
+ return recordsCount;
+ }
+
auto GetFilteredResult::debugInfo() const -> std::string
{
return "GetFilteredResult";
M module-db/queries/calendar/QueryEventsGetFiltered.hpp => module-db/queries/calendar/QueryEventsGetFiltered.hpp +6 -2
@@ 13,19 13,23 @@ namespace db::query::events
class GetFiltered : public Query
{
public:
- GetFiltered(TimePoint filter_from, TimePoint filter_till);
+ GetFiltered(TimePoint filter_from, TimePoint filter_till, uint32_t offset = 0, uint32_t limit = UINT32_MAX);
[[nodiscard]] auto debugInfo() const -> std::string override;
TimePoint filter_from;
TimePoint filter_till;
+ uint32_t offset;
+ uint32_t limit;
};
class GetFilteredResult : public QueryResult
{
std::unique_ptr<std::vector<EventsRecord>> records;
+ uint32_t recordsCount;
public:
- GetFilteredResult(std::unique_ptr<std::vector<EventsRecord>> records);
+ GetFilteredResult(std::unique_ptr<std::vector<EventsRecord>> records, uint32_t count);
+ auto getCountResult() -> uint32_t;
[[nodiscard]] auto getResult() -> std::unique_ptr<std::vector<EventsRecord>>;
[[nodiscard]] auto debugInfo() const -> std::string override;
M module-db/tests/EventsRecord_tests.cpp => module-db/tests/EventsRecord_tests.cpp +2 -2
@@ 155,8 155,8 @@ TEST_CASE("Events Record tests")
SECTION("Get table rows by SELECT invalid")
{
- auto retOffsetLimit = eventsRecordInterface.Select(TimePointFromString("2010-10-20 14:24:00"),
- TimePointFromString("2010-10-20 15:36:00"));
+ auto retOffsetLimit = eventsRecordInterface.Select(
+ TimePointFromString("2010-10-20 14:24:00"), TimePointFromString("2010-10-20 15:36:00"), 0, UINT32_MAX);
REQUIRE(retOffsetLimit->size() == 0);
}
}
M module-db/tests/EventsTable_tests.cpp => module-db/tests/EventsTable_tests.cpp +2 -2
@@ 140,8 140,8 @@ TEST_CASE("Events Table tests")
.reminder = 0,
.repeat = 3}));
- auto entries = eventsTbl.selectByDatePeriod(TimePointFromString("2000-01-01 00:00:00"),
- TimePointFromString("2012-12-31 23:59:00"));
+ auto entries = eventsTbl.selectByDatePeriod(
+ TimePointFromString("2000-01-01 00:00:00"), TimePointFromString("2012-12-31 23:59:00"), 0, UINT32_MAX);
REQUIRE(entries.size() == 0);
}