mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-06-12 18:45:43 -04:00
[EGD-4487] Application notes implemented. (#1094)
* [EGD-4487] Implementation of notes application.
This commit is contained in:
64
module-apps/application-notes/model/NotesRepository.cpp
Normal file
64
module-apps/application-notes/model/NotesRepository.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
|
||||
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
||||
|
||||
#include "NotesRepository.hpp"
|
||||
|
||||
#include <module-db/queries/notes/QueryNotesGet.hpp>
|
||||
#include <module-db/queries/notes/QueryNoteStore.hpp>
|
||||
#include <module-db/queries/notes/QueryNoteRemove.hpp>
|
||||
|
||||
#include <service-db/DBServiceAPI.hpp>
|
||||
|
||||
namespace app::notes
|
||||
{
|
||||
NotesDBRepository::NotesDBRepository(Application *application) : application{application}
|
||||
{}
|
||||
|
||||
void NotesDBRepository::get(std::uint32_t offset, std::uint32_t limit, const OnGetCallback &callback)
|
||||
{
|
||||
auto query = std::make_unique<db::query::QueryNotesGet>(offset, limit);
|
||||
query->setQueryListener(db::QueryCallback::fromFunction([callback](auto response) {
|
||||
auto result = dynamic_cast<db::query::NotesGetResult *>(response);
|
||||
if (result == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (callback) {
|
||||
callback(result->getRecords(), result->getCount());
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
DBServiceAPI::GetQuery(application, db::Interface::Name::Notes, std::move(query));
|
||||
}
|
||||
|
||||
void NotesDBRepository::save(const NotesRecord ¬e, const OnResultCallback &callback)
|
||||
{
|
||||
auto query = std::make_unique<db::query::QueryNoteStore>(note);
|
||||
query->setQueryListener(db::QueryCallback::fromFunction([callback](auto response) {
|
||||
auto result = dynamic_cast<db::query::NoteStoreResult *>(response);
|
||||
if (result == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (callback) {
|
||||
callback(result->succeed());
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
DBServiceAPI::GetQuery(application, db::Interface::Name::Notes, std::move(query));
|
||||
}
|
||||
|
||||
void NotesDBRepository::remove(const NotesRecord ¬e, const OnResultCallback &callback)
|
||||
{
|
||||
auto query = std::make_unique<db::query::QueryNoteRemove>(note.ID);
|
||||
query->setQueryListener(db::QueryCallback::fromFunction([callback](auto response) {
|
||||
auto result = dynamic_cast<db::query::NoteRemoveResult *>(response);
|
||||
if (result == nullptr) {
|
||||
return false;
|
||||
}
|
||||
if (callback) {
|
||||
callback(result->succeed());
|
||||
}
|
||||
return true;
|
||||
}));
|
||||
DBServiceAPI::GetQuery(application, db::Interface::Name::Notes, std::move(query));
|
||||
}
|
||||
} // namespace app::notes
|
||||
Reference in New Issue
Block a user