// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "NotesRepository.hpp" #include #include #include #include #include namespace app::notes { NotesDBRepository::NotesDBRepository(ApplicationCommon *application) : app::AsyncCallbackReceiver{application}, application{application} {} void NotesDBRepository::get(std::uint32_t offset, std::uint32_t limit, const OnGetCallback &callback) { auto query = std::make_unique(offset, limit); auto task = app::AsyncQuery::createFromQuery(std::move(query), db::Interface::Name::Notes); task->setCallback([callback](auto response) { auto result = dynamic_cast(response); if (result == nullptr) { return false; } if (callback) { callback(result->getRecords(), result->getCount()); } return true; }); task->execute(application, this); } void NotesDBRepository::getByText(const std::string &text, std::uint32_t offset, std::uint32_t limit, const OnGetCallback &callback) { auto query = std::make_unique(text, offset, limit); auto task = app::AsyncQuery::createFromQuery(std::move(query), db::Interface::Name::Notes); task->setCallback([callback](auto response) { auto result = dynamic_cast(response); if (result == nullptr) { return false; } if (callback) { callback(result->getRecords(), result->getCount()); } return true; }); task->execute(application, this); } void NotesDBRepository::save(const NotesRecord ¬e, const OnSaveCallback &callback) { auto query = std::make_unique(note); auto task = app::AsyncQuery::createFromQuery(std::move(query), db::Interface::Name::Notes); task->setCallback([callback](auto response) { auto result = dynamic_cast(response); if (result == nullptr) { return false; } if (callback) { callback(result->succeed(), result->getNoteId()); } return true; }); task->execute(application, this); } void NotesDBRepository::remove(const NotesRecord ¬e, const OnRemoveCallback &callback) { auto query = std::make_unique(note.ID); auto task = app::AsyncQuery::createFromQuery(std::move(query), db::Interface::Name::Notes); task->setCallback([callback](auto response) { auto result = dynamic_cast(response); if (result == nullptr) { return false; } if (callback) { callback(result->succeed()); } return true; }); task->execute(application, this); } } // namespace app::notes