~aleteoryx/muditaos

ref: sign_test muditaos/module-db/Interface/NotesRecord.hpp -rw-r--r-- 2.2 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "Record.hpp"

#include <cstdint>
#include <filesystem>

#include <utf8/UTF8.hpp>

#include "module-db/databases/NotesDB.hpp"
#include "../Common/Common.hpp"

struct NotesRecord : public Record
{
    std::uint32_t date;
    UTF8 snippet;
};

enum class NotesRecordField
{
    Date,
    Snippet,
};

class NotesRecordInterface : public RecordInterface<NotesRecord, NotesRecordField>
{
  public:
    explicit NotesRecordInterface(NotesDB *notesDb);

    bool Add(const NotesRecord &rec) override;
    bool RemoveAll() override;
    bool RemoveByID(std::uint32_t id) override;
    bool RemoveByField(NotesRecordField field, const char *str) override;
    bool Update(const NotesRecord &rec) override;
    NotesRecord GetByID(std::uint32_t id) override;
    std::uint32_t GetCount() override;
    std::unique_ptr<std::vector<NotesRecord>> GetLimitOffset(std::uint32_t offset, std::uint32_t limit) override;
    std::unique_ptr<std::vector<NotesRecord>> GetLimitOffsetByField(std::uint32_t offset,
                                                                    std::uint32_t limit,
                                                                    NotesRecordField field,
                                                                    const char *str) override;

    std::unique_ptr<db::QueryResult> runQuery(std::shared_ptr<db::Query> query) override;

  private:
    std::vector<NotesRecord> getNotes(std::uint32_t offset, std::uint32_t limit) const;
    std::pair<std::vector<NotesRecord>, unsigned int> getNotesByText(const std::string &text,
                                                                     unsigned int offset,
                                                                     unsigned int limit) const;

    std::unique_ptr<db::QueryResult> getQuery(const std::shared_ptr<db::Query> &query);
    std::unique_ptr<db::QueryResult> getByTextQuery(const std::shared_ptr<db::Query> &query);
    std::unique_ptr<db::QueryResult> storeQuery(const std::shared_ptr<db::Query> &query);
    std::unique_ptr<db::QueryResult> removeQuery(const std::shared_ptr<db::Query> &query);

    NotesDB *notesDB;
};